找回密码
 点一下
查看: 1055|回复: 0

如何解决LocalPlayer和SelectUnit引起掉线问题?

[复制链接]
发表于 2011-8-23 00:49:35 | 显示全部楼层 |阅读模式
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
您需要登录后才可以回帖 登录 | 点一下

本版积分规则

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

GMT+8, 2024-12-27 11:56 , Processed in 0.037723 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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