找回密码
 点一下
查看: 2618|回复: 11

关于GetLocalPlayer()……

[复制链接]
发表于 2006-5-29 06:12:54 | 显示全部楼层 |阅读模式
function PanCameraToTimedLocForPlayer takes player whichPlayer, location loc, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
    endif
endfunction

类似这样的函数在BLIZZARD.J里面随处可见……
 楼主| 发表于 2006-5-29 06:27:43 | 显示全部楼层
if GetLocalPlayer() == Player(5) then
//some code
endif


somecode是什么时会导致掉线?
回复

使用道具 举报

发表于 2006-5-29 09:37:27 | 显示全部楼层
只要不包括全局数据就没问题~~

GetLocalPlayer()  后面一般只能用本地数据计算~~

比如一个只有某个玩家独有的变量~~
比如镜头参数~~
比如 MB~~
和单位无关的特效~~
等~~
回复

使用道具 举报

发表于 2006-5-29 15:27:05 | 显示全部楼层
原来如此~~受教啊啊啊啊啊啊
回复

使用道具 举报

 楼主| 发表于 2006-5-29 17:22:10 | 显示全部楼层
原帖由 Danexx 于 2006-5-29 09:37 发表
只要不包括全局数据就没问题~~

GetLocalPlayer()  后面一般只能用本地数据计算~~

比如一个只有某个玩家独有的变量~~
比如镜头参数~~
比如 MB~~
和单位无关的特效~~
等~~


那么播放音乐、淡出/入图片、漂浮文字、特效、播放单位动画呢?
有没有不用测试就知道结果的好办法。
回复

使用道具 举报

 楼主| 发表于 2006-5-29 18:33:07 | 显示全部楼层
[jass]function PanCameraToTimedLocForPlayer takes player whichPlayer, location loc, real duration returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
    endif
endfunction[/jass]


我现在甚至不明白这两种写法哪种好了::L
两个函数作用一样,
第一种,
[jass]function PanCameraToTimedLocForAllPlayer takes location loc, real duration returns nothing
        call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
endfunction[/jass]

第二种,
[jass]function PanCameraToTimedLocForAllPlayer takes location loc, real duration returns nothing
        local integer a = 1
        loop
               exitwhen a > 12
              call PanCameraToTimedLocForPlayer(player(a-1),loc,duration)
               set a = a + 1
        endloop
endfunction[/jass]
回复

使用道具 举报

 楼主| 发表于 2006-5-29 18:34:10 | 显示全部楼层
看起来是第一种好,但是实际用在游戏里,第一种导致玩家掉线的几率比第二种还高。
回复

使用道具 举报

 楼主| 发表于 2006-5-29 18:37:08 | 显示全部楼层
呃```再测试一下。
回复

使用道具 举报

 楼主| 发表于 2006-5-29 18:57:34 | 显示全部楼层
转自:http://infor.org/~n1048/WESelfStudy/GoodArticles/JASSManual/attach10.htm
?部分玩家播放音效(本?玩者)

--------------------------------------------------------------------------------

?指定玩家播放音效
 function PlaySoundForPlayer takes player whichPlayer, sound whichSound returns nothing
    if ( whichPlayer == GetLocalPlayer() ) then
        call StartSound( whichSound )
    endif
endfunction
 
??介?一下GetLocalPlayer()??函?。它的意思是「本?玩者」,也就是?行??Trigger的??上的玩者。
在b.net???,各???只??一些指令,大部分的?算都是由每一台??自行?算,所以:\\r
     if GetLocalPlayer() == Player(0) then
        call StartSound( whichSound )
    endif

假?此??有十?人在玩,玩者一的??中,「本?玩家」是玩者一,符合?件,因此玩者一的???播放音效;玩者二的??中,「本?玩家」是玩者二,不符合?件,因此就不播放;其它玩者同理。 (特?注意??中的玩者一在JASS?是Player(0);玩者二是Player(1),依此?推)

使用本?玩家要注意哪些必?同步?行,哪些不能同步?行。假?你只?玩者一和玩者二的??建立一?部?,而其它玩者??有。那???生伺服器分?,?成玩者一和玩者二一?,其它玩者一?。

此方法不能只?部分??:
建立新物件
取???
?定重要必?同步的?料,例如部?生命、魔力、?行高度
???作通常可以用在?部分玩者:
播放音效
建立特效
?定部??色(Change Unit Vertex Coloring)
?定部?外型大小
???影??(Advanced Filter。不可用Fade Filter)
?者?不??得整句用JASS??在太麻?了?所以??介?一???的方法:

首先建立一?玩者??LocalPlayer,然後?它初始化(日後不要?便改?此??的值):Init
 Events
  Map initialization
  Game - A saved game is loaded
 Conditions
 Actions
  Custom script: set udg_LocalPlayer = GetLocalPlayer()

?在LocalPlayer就代表本?玩家了,假?你要?玩者一播放某音效,就???:
If (LocalPlayer Equal to Player 1 (Red)) then do (Sound - Play BlizzardTarget1 <gen>) else do (Do nothing)

要?玩者二的盟友播放就???:
If ((LocalPlayer is an ally of Player 2 (Blue)) Equal to True) then do (Sound - Play BlizzardTarget1 <gen>) else do (Do nothing)

要?玩者二的盟友建立特效就???:
If ((LocalPlayer is an ally of Player 2 (Blue)) Equal to True) then do (Set TempString = Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl) else do (Set TempString = <Empty String>)
Special Effect - Create a special effect at (Center of (Playable map area)) using TempString
Special Effect - Destroy (Last created special effect)

{??不可以???:
If ((LocalPlayer is an ally of Player 2 (Blue)) Equal to True) then do (Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl) else do (Do Nothing)

因???就只?部分玩家?造物件(特效),?造成??



???了吧?
回复

使用道具 举报

发表于 2006-5-30 02:47:07 | 显示全部楼层
好晕@_@^!!!!!!!!!
回复

使用道具 举报

发表于 2006-5-30 13:35:49 | 显示全部楼层
需要我的建议么?!
把播放音乐删了。
能正常游戏才是王道。
关于音乐的问题。另外测试。
嗯。因为我看到的没有写着测试版字样。所以。掉线。我会很气愤。
请不要给我无用的东西。我不听音乐。
回复

使用道具 举报

发表于 2006-5-30 14:23:49 | 显示全部楼层
从我自己得到的一些错误得出的结论:
GetLocalPlayer()后不要涉及实际handle或与此相关的操作或赋值(指这些操作可能影响到handle本身是否存在/清除),不同的玩家可能因此造成内存中数据的脱节而引起断线;
比较隐蔽的如TriggerCondition,Filter,Boolexpr等(基类型同为handle),
还有,bj中LocalPlayer()的用法未必都是正确的,最近的一个例子:
[jass]
function SelectGroupBJEnum takes nothing returns nothing
    call SelectUnit( GetEnumUnit(), true )
endfunction



function SelectGroupForPlayerBJ takes group g, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
        call ForGroup( g, function SelectGroupBJEnum )
    endif
endfunction[/jass]
比较特殊的,调用code(ForGroup)的异步导致DisSyn,我以为如果是LocalPlayer判断放到SelectGroupBJEnum就应该好了:
[jass]
function SelectGroupBJEnum takes nothing returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
    call SelectUnit( GetEnumUnit(), true )
  endif
endfunction



function SelectGroupForPlayerBJ takes group g, player whichPlayer returns nothing
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.
        call ClearSelection()
    endif

        call ForGroup( g, function SelectGroupBJEnum )
endfunction[/jass]

对于那个特效的本地显示还是有点匪夷所思,
[jass]native AddSpecialEffect takes string modelName, real x, real y returns effect[/jass]
如果是modelName为空而还能正常返回effect(非null值),那么象CreateUnit如果用的不同的Id是不是也一样可行呢.
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-4 22:10 , Processed in 0.050396 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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