|
发表于 2013-1-31 09:11:51
|
显示全部楼层
本帖最后由 lfglvstory 于 2013-1-31 09:16 编辑
刚好近期写了个字符串系统,LZ可以参考一下。截取实际捕获命令的这段贴出来:- function Trig_SinglePlayer_Actions takes nothing returns nothing
- local player p = GetTriggerPlayer()
- local integer id = GetPlayerId(p)
- local string msg = StringCase(GetEventPlayerChatString(),false) // 获取当前的聊天字符串,并且做小写转换操作
- local integer l = StringLength(msg)
- local integer data
- local integer parentKey = GetHandleId(p)
- local trigger orderTrig_ability
- local trigger orderTrig_ability
- //call Debug(SubString(msg,0,6))
- // 截取字符串与-lvlup匹配,也可以写成 SubString(msg,0,StringLength("-lvlup"))=="-lvlup",建议这么写,将命令封装一下就更好
- if SubString(msg,0,6) == "-lvlup" then
- set data = S2I(SubString(msg,6,l))
- call SaveInt(parentKey,StringHash("level"),data)
- call DestroyGroup(GetUnitsInRectMatching(GetPlayableMapRect(),Condition(function LvlupFilter)))
- call FlushChildHashtable(udg_HT,parentKey)
- elseif SubString(msg,0,5) == "-gold" then
- set data = S2I(SubString(msg,5,l))
- call SetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD,GetPlayerState(p,PLAYER_STATE_RESOURCE_GOLD)+data)
- elseif SubString(msg,0,7) == "-lumber" then
- set data = S2I(SubString(msg,7,l))
- call SetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER,GetPlayerState(p,PLAYER_STATE_RESOURCE_LUMBER)+data)
- elseif SubString(msg,0,5) == "-nocd" then
- set udg_orderTrig_ability = CreateTrigger()
- call TriggerRegisterAnyUnitEventBJ( orderTrig_ability, EVENT_PLAYER_UNIT_SPELL_EFFECT )
- call TriggerAddAction( orderTrig_ability, function NoCD_Actions )
- //call ConditionalTriggerExecute( order_nocd )
- elseif SubString(msg,0,7) == "-nomana" then
- set udg_orderTrig_ability = CreateTrigger()
- call TriggerRegisterAnyUnitEventBJ( orderTrig_ability, EVENT_PLAYER_UNIT_SPELL_EFFECT )
- call TriggerAddAction( orderTrig_ability, function NoMana_Actions )
- //call ConditionalTriggerExecute( order_nomana )
- endif
- set p = null
- endfunction
- //===========================================================================
- function InitTrig_SinglePlayer takes nothing returns nothing
- local integer index = 1
- set gg_trg_SinglePlayer = CreateTrigger( )
- loop
- call TriggerRegisterPlayerChatEvent( gg_trg_SinglePlayer, Player(index), "", false )
- set index = index + 1
- exitwhen index > 11
- endloop
- call TriggerAddAction( gg_trg_SinglePlayer, function Trig_SinglePlayer_Actions )
- endfunction
复制代码 |
|