找回密码
 点一下
查看: 1140|回复: 9

如何将魔兽中字符串变量的值导出到txt文件--已解决

[复制链接]
发表于 2012-8-14 21:59:40 | 显示全部楼层 |阅读模式
如题,

下面真三AR模式锁定种子的测试代码:

//TESH.scrollpos=36
//TESH.alwaysfold=0
function Trig_Allrandom_Func008002 takes nothing returns nothing
call RemoveUnit(GetEnumUnit())
endfunction
function Trig_Allrandom_Func009Func003001 takes nothing returns boolean
return (udg_RandomHero_TypeList[udg_x]!=0)
endfunction
function Trig_Allrandom_Func009Func008002 takes nothing returns nothing
call SetPlayerTechMaxAllowedSwap(udg_RandomHero_TypeList[udg_x],0,GetEnumPlayer())
endfunction
function Trig_Allrandom_Func010Func003001 takes nothing returns boolean
return (udg_RandomHero_TypeList[udg_x]!=0)
endfunction
function Trig_Allrandom_Func010Func008002 takes nothing returns nothing
call SetPlayerTechMaxAllowedSwap(udg_RandomHero_TypeList[udg_x],0,GetEnumPlayer())
endfunction
function Trig_Allrandom_Actions takes nothing returns nothing
  local integer loopi
  local string displaytext
  local integer abc
call DisableTrigger(GetTriggeringTrigger())
call RemoveUnit(gg_unit_n00Z_0200)
call RemoveUnit(gg_unit_n001_0198)
call RemoveUnit(gg_unit_n01B_0203)
call RemoveUnit(gg_unit_n00B_0201)
call RemoveUnit(gg_unit_n00Y_0205)
call RemoveUnit(gg_unit_n000_0199)
call ForGroupBJ(GetUnitsOfTypeIdAll('h000'),function Trig_Allrandom_Func008002)
   
    set loopi=1
    //set udg_TextResult=""
  loop
    exitwhen loopi>50
    set udg_RandomHero_TypeList[1]='E000'
    set udg_RandomHero_TypeList[2]='E003'
    set udg_RandomHero_TypeList[3]='O003'
    set udg_RandomHero_TypeList[4]='O002'
    set udg_RandomHero_TypeList[5]='O00K'
    set udg_RandomHero_TypeList[6]='O000'
    set udg_RandomHero_TypeList[7]='U002'
    set udg_RandomHero_TypeList[8]='Hvwd'
    set udg_RandomHero_TypeList[9]='U006'
    set udg_RandomHero_TypeList[10]='E004'
    set udg_RandomHero_TypeList[11]='H01P'
    set udg_RandomHero_TypeList[12]='Hamg'
    set udg_RandomHero_TypeList[13]='U00J'
    set udg_RandomHero_TypeList[14]='H004'
    set udg_RandomHero_TypeList[15]='H003'
    set udg_RandomHero_TypeList[16]='H01G'
    set udg_RandomHero_TypeList[17]='N00P'
    set udg_RandomHero_TypeList[18]='U00D'
    set udg_RandomHero_TypeList[19]='H008'
    set udg_RandomHero_TypeList[20]='N00W'
    set udg_RandomHero_TypeList[21]='N004'
    set udg_RandomHero_TypeList[22]='U00A'
    set udg_RandomHero_TypeList[23]='U00I'
    set udg_RandomHero_TypeList[24]='U000'
    set udg_RandomHero_TypeList[25]='H006'
    set udg_RandomHero_TypeList[26]='H005'
    set udg_RandomHero_TypeList[27]='H010'
    set udg_RandomHero_TypeList[28]='N005'
    set udg_RandomHero_TypeList[29]='H00I'
    set udg_RandomHero_TypeList[30]='H012'
    set udg_RandomHero_TypeList[31]='O00P'
    set udg_RandomHero_TypeList[32]='U007'
    set udg_RandomHero_TypeList[33]='Ucrl'
    set udg_RandomHero_TypeList[34]='E00C'
    set udg_RandomHero_TypeList[35]='E005'
    set udg_RandomHero_TypeList[36]='E006'
    set udg_RandomHero_TypeList[37]='E00J'
    set udg_RandomHero_TypeList[38]='U00O'
    set udg_RandomHero_TypeList[39]='N010'
    set udg_RandomHero_TypeList[40]='U00N'
set bj_forLoopAIndex=2
set bj_forLoopAIndexEnd=6
    call SetRandomSeed(loopi)
    set abc=GetRandomInt(1,40)
    set abc=GetRandomInt(1,40)
    set abc=GetRandomInt(1,40)
    set displaytext="seed"+I2S(loopi)+":"
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
loop
set udg_x=GetRandomInt(1,40)
if (Trig_Allrandom_Func009Func003001()) then
exitwhen true
endif
endloop
set udg_Temp_Point=GetRectCenter(gg_rct_SHU_TavernsRect)
call CreateNUnitsAtLoc(1,udg_RandomHero_TypeList[udg_x],Player(-1+(bj_forLoopAIndex)),udg_Temp_Point,bj_UNIT_FACING)
call RemoveLocation(udg_Temp_Point)
call ForForce(bj_FORCE_ALL_PLAYERS,function Trig_Allrandom_Func009Func008002)
      set displaytext=displaytext+" "+I2S(udg_x)
set udg_RandomHero_TypeList[udg_x]=0
set bj_forLoopAIndex=bj_forLoopAIndex+1
      call RemoveUnit(GetLastCreatedUnit())
endloop
    set displaytext=displaytext+"  "
set bj_forLoopAIndex=8
set bj_forLoopAIndexEnd=12
loop
exitwhen bj_forLoopAIndex>bj_forLoopAIndexEnd
loop
set udg_x=GetRandomInt(1,40)
if (Trig_Allrandom_Func010Func003001()) then
exitwhen true
endif
endloop
set udg_Temp_Point=GetRectCenter(gg_rct_WEI_TavernsRect)
call CreateNUnitsAtLoc(1,udg_RandomHero_TypeList[udg_x],Player(-1+(bj_forLoopAIndex)),udg_Temp_Point,bj_UNIT_FACING)
call RemoveLocation(udg_Temp_Point)
call ForForce(bj_FORCE_ALL_PLAYERS,function Trig_Allrandom_Func010Func008002)
      set displaytext=displaytext+" "+I2S(udg_x)
set udg_RandomHero_TypeList[udg_x]=0
set bj_forLoopAIndex=bj_forLoopAIndex+1
      call RemoveUnit(GetLastCreatedUnit())
endloop
    set displaytext=displaytext+"\n"
    call DisplayTimedTextToForce( GetPlayersAll(), 180, displaytext)
    set udg_TextResult=udg_TextResult+displaytext
    set loopi=loopi+1
  endloop
endfunction
//===========================================================================
function InitTrig_Allrandom takes nothing returns nothing
set gg_trg_Allrandom=CreateTrigger()
call TriggerRegisterPlayerChatEvent(gg_trg_Allrandom,Player(1),"-ar",true)
call TriggerAddAction(gg_trg_Allrandom,function Trig_Allrandom_Actions)
endfunction

在游戏开始后输入-ar,50组AR英雄种子数据信息完全存储在字符串变量udg_TextResult(全局变量)中。
这个字符串变量udg_TextResult可以在游戏中用War3JassDebug软件监视得到字符串变量值,但是不能导出到文件,貌似JASS中也没有直接导出变量值到文件的函数。求高手解决。。。

此问题解决后 以后AR锁定种子我可以公开让大家利用了。

注:能在JASS代码中解决是最好了,不过如果你能用其它语言编程 利用Windows API调用war3的进程,然后搜索内存地址,得出变量值也可,但是我不会。
发表于 2012-8-14 22:04:54 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2012-8-14 22:32:38 | 显示全部楼层
你提供只是预读地图的BUG,而我现在的情况是游戏运行后的变量值。。。。
回复

使用道具 举报

发表于 2012-8-14 23:07:34 | 显示全部楼层

回 andy4001 的帖子

andy4001:你提供只是预读地图的BUG,而我现在的情况是游戏运行后的变量值。。。。 (2012-08-14 22:32) 
嗯。。不太清楚你的情况呢。。这个bug是可以在游戏进行中使用的,只是不能直接输出变量,但如果你要输出的变量只是在少数几种可能性中变化的话,那还是可以用这种方法的。
虽然不能输出变量的值到文本,但是可以把变量输出到文件名和文件路径上哦
然后dir X : / X / X  >> X.txt一下就搞定了嘛。。

[jass]function Trig____________________001Actions takes nothing returns nothing
    local string a = GetEventPlayerChatString()
    call PreloadGenClear()
    call PreloadGenStart()
    call PreloadGenEnd("D:\\\\"+a)
endfunction

//===========================================================================
function InitTrig____________________001 takes nothing returns nothing
    set gg_trg____________________001 = CreateTrigger()
#ifdef DEBUG
    call YDWESaveTriggerName(gg_trg____________________001, "未命名触发器 001")
#endif
    call TriggerRegisterPlayerChatEvent( gg_trg____________________001, Player(0), "a", false )
    call TriggerAddAction(gg_trg____________________001, function Trig____________________001Actions)
endfunction[/jass]
回复

使用道具 举报

发表于 2012-8-15 00:36:53 | 显示全部楼层
[trigger]Write
    事件
        玩家 - 玩家1(红色) 输入的聊天信息包含 <空字符串> ,匹配方式: 包含字符串
    条件
    动作
        自定义代码: call PreloadGenClear()
        自定义代码: call PreloadGenStart()
             ★     以下为输出变量String的代码,可以循环多次输出     ★     
        设置 String = (输入的聊天信息)
        自定义代码: call Preload("\\necho " + udg_String + " >> Message.txt\\n")
             ★     以上为输出变量String的代码,可以循环多次输出     ★     
        自定义代码: call PreloadGenEnd("D:\\\\M.bat")
             ★     数据会被保存到D:\\M.bat里面,运行一次后可以得到数据文件Message.txt     ★     
[/trigger]
回复

使用道具 举报

发表于 2012-8-15 00:50:46 | 显示全部楼层

回 美味豆沙包 的帖子

美味豆沙包:[trigger]Write
&#160;&#160;&#160;&#160;事件
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;玩家 - 玩家1(红色) 输入的聊天信息包含 <空字符串> ,匹配方式: 包含字符串
&#160;&#160;&#160;&#160;条件
&#160;&#160;&#160;&#160;动作
.......&#160;(2012-08-15 00:36)&#160;
原来变量名会被直接代替掉。。。。我一开始还以为不会输出变量的值。。
回复

使用道具 举报

发表于 2012-8-15 00:57:32 | 显示全部楼层

回 yelite 的帖子

yelite:原来变量名会被直接代替掉。。。。我一开始还以为不会输出变量的值。。(2012-08-15 00:50)嬀/color]
不是变量名会被直接代替...
只是利用BUG可以直接输出变量的值而已
回复

使用道具 举报

发表于 2012-8-15 01:29:00 | 显示全部楼层

回 美味豆沙包 的帖子

美味豆沙包:不是变量名会被直接代替...
只是利用BUG可以直接输出变量的值而已&#160;(2012-08-15 00:57)&#160;
这个bug不是用来以文本的形式输出脚本文件的吗。。。
在函数的参数里面如果有变量就直接用它的值来做输出(一开始我以为会输出call Preload("\\necho " + udg_String + " >> Message.txt\\n")这样的),感觉就像define那样的。。所以就用了代替这个词。。
回复

使用道具 举报

发表于 2012-8-15 01:31:08 | 显示全部楼层
s.w3x (12 KB, 下载次数: 7)
这里随便写了一个例子,可参考写法......
回复

使用道具 举报

 楼主| 发表于 2012-8-16 14:48:42 | 显示全部楼层
根据你们提供的方法,此问题已解决。

但是发现PreLoad函数输出字符串变量的值最多也只能2百多字符,使得我不得不换成字符串数组来解决几个千个字符的字符串问题。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-10-1 08:10 , Processed in 0.121601 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表