|
function ChooseTheShops_Conditions takes nothing returns boolean
local unit u = GetTriggerUnit()
local player p = GetTriggerPlayer()
if u == gg_unit_n020_0158 then
call SelectUnitForPlayerSingle( gg_unit_n00Q_0111, p )
elseif u == gg_unit_n020_0121 then
call SelectUnitForPlayerSingle( gg_unit_n00Q_0060, p )
endif
set u = null
set p = null
return false
endfunction
call TriggerRegisterPlayerUnitEvent(trg, p, EVENT_PLAYER_UNIT_SELECTED, null)
call TriggerAddCondition( trg, Condition( function ChooseTheShops_Conditions ) )
简单写了。。。为什么这段代码不会掉线?而下面那段代码会!
function SelectTheInvisible takes nothing returns nothing
local player p
local integer i
local unit u = gg_unit_n00Q_0060
local boolean b
set i = 1
loop
if i == 6 then
set u = gg_unit_n00Q_0111
set i = 7
endif
exitwhen i > 11
set p = Player(i)
if IsPlayerAvailable(p)then
call SelectUnitAddForPlayer(u,p)
endif
set i = i + 1
endloop
set p = null
set u = null
call DestroyTimer(GetExpiredTimer())
endfunction
call TimerStart(t,1,false,function SelectTheInvisible)
之前是写成GetLocalPlayer()==p 然后 SelectUnit(u)的形式,结果相同。
求解~理论上应该第一段代码也是会掉线才对额???
是否有什么办法能解决不同步问题??
顺便问下native SyncSelections takes nothing returns nothing
作用与用法?相关链接http://bbs.islga.org/read-htm-tid-27131.html
补充函数
function SelectUnitForPlayerSingle takes unit whichUnit, player whichPlayer returns nothing
if (GetLocalPlayer() == whichPlayer) then
// Use only local code (no net traffic) within this block to avoid desyncs.
call ClearSelection()
call SelectUnit(whichUnit, true)
endif
endfunction
function SelectUnitAddForPlayer takes unit whichUnit, player whichPlayer returns nothing
if (GetLocalPlayer() == whichPlayer) then
// Use only local code (no net traffic) within this block to avoid desyncs.
call SelectUnit(whichUnit, true)
endif
endfunction
function IsPlayerAvailable takes player p returns boolean
return GetPlayerSlotState(p)==PLAYER_SLOT_STATE_PLAYING and GetPlayerController(p)==MAP_CONTROL_USER
endfunction |
|