HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to detect if a player is an observer?

05-04-2009, 03:55 PM#1
Tyrande_ma3x
In my map I want to give special information to observer players that can be seen only by them (like, what abilities Player 4 leveled, what items Player 7 bought, etc.). Is there an easy way to do so? I noticed there was a constant PLAYER_STATE_OBSERVER but I have no idea with which function to use it. I tried using something like:
Collapse JASS:
if GetLocalPlayer() != Player(0) and GetLocalPlayer() != Player(1) and ... //etc.
but it becomes too long to type since I have 10 players in my map ... Suggestions?
05-04-2009, 04:16 PM#2
Captain Griffen
GetPlayerState, maybe...
05-04-2009, 04:48 PM#3
Tyrande_ma3x
But that returns an integer... With what am I supposed to compare it?
05-04-2009, 04:53 PM#4
Troll-Brain
Quote:
Originally Posted by Tyrande_ma3x
But that returns an integer... With what am I supposed to compare it?
Test and display it, maybe GetPlayerState(<player>,PLAYER_STATE_OBSERVER) > 0 , if the player is an observer.
05-04-2009, 05:50 PM#5
Ammorth
isn't it
Collapse JASS:
if GetPlayerState(Player(N)) == PLAYER_STATE_OBSERVER then
05-04-2009, 06:08 PM#6
Tyrande_ma3x
Quote:
Originally Posted by Ammorth
isn't it
Collapse JASS:
if GetPlayerState(Player(N)) == PLAYER_STATE_OBSERVER then
Collapse JASS:
constant native GetPlayerState takes player whichPlayer, playerstate whichPlayerState returns integer


Ok, I did this after 1 second of map startup. It displays 1 to the observer players and 0 to normal ones.
Collapse JASS:
call BJDebugMsg(I2S(GetPlayerState(GetLocalPlayer(), PLAYER_STATE_OBSERVER)))

My next question is if it will cause desyncs if I use directly
Collapse JASS:
if GetPlayerState(GetLocalPlayer(), PLAYER_STATE_OBSERVER) == 1 then
    call DisplayTextToPlayer(GetLocalPlayer(), ...)
endif
?
05-04-2009, 06:36 PM#7
Alevice
text messages are likely not source of desyncs.

although, you could just do a loop check, rather than a getlocalplayer block if you are worried, specially because displaytexttoplaer already filetrs by player
05-04-2009, 06:50 PM#8
Troll-Brain
GetLocalPlayer() fail in a replay.
It's hard for me to explain but basically with your example, only the first player (first slot) will see this message.

http://www.wc3c.net/showthread.php?t=101885

If you care about replays then you shouldn't use GetLocalPlayer() like that, especially because you can easily avoid using it here.
05-05-2009, 09:55 AM#9
Tyrande_ma3x
I saw the link but I couldn't find anything that could help me avoid usage of GetLocalPlayer().
Btw, in another thread a guy told me this native:
Collapse JASS:
constant native IsPlayerObserver takes player whichPlayer returns boolean
which is basically a lot better than using GetPlayerState comparision. So I guess I'll use that.

As for the replays... I still can't find a way to show messages, does anybody have a sollution for this?
05-05-2009, 10:23 AM#10
DioD
Collapse JASS:
function SFNLP takes nothing returns nothing
    call DisplayTimedTextToPlayer(GetEnumPlayer(), 0, 0, bj_cineFadeContinueTrans, bj_lastPlayedMusic)
endfunction

function DisplayTimedTextToForceSFNLP takes force toForce, real duration, string message returns nothing

    local real r = bj_cineFadeContinueTrans
    local string s = bj_lastPlayedMusic

    set bj_cineFadeContinueTrans = duration
    set bj_lastPlayedMusic = message
    
    call ForForce(toForce,function SFNLP)
    
    set bj_cineFadeContinueTrans = r
    set bj_lastPlayedMusic = s

endfunction

Have fun with this function
05-05-2009, 11:26 AM#11
Tyrande_ma3x
I see it displays a message but how am I supposed to use it? Do I have to create a force, set it to bj_FORCE_ALL_PLAYERS and then remove from it Players 0-9 and use it with that function?
05-05-2009, 12:57 PM#12
DioD
Post function you using currently to display text, i will fix it.

For this, just use GUI forces (enemy of player, ally of player and others) or create forces with players you need.
05-05-2009, 01:28 PM#13
Tyrande_ma3x
Currently:
Collapse JASS:
if IsPlayerObserver(GetLocalPlayer()) then
    call DisplayTextToPlayer(GetLocalPlayer(), 0., 0., GetPlayerNameColored(Player(2)) + "has leveled Earth Splitter.")
// Or something like that... 
endif

But as it was stated above, it won't work in a replay.
05-05-2009, 01:58 PM#14
Alevice
dont use getlocal player. just do a loop that checks for all players. that would be simpler, and displaytexttoplayer doesnt really need to use a local player argument.
05-05-2009, 04:35 PM#15
Troll-Brain
Quote:
Originally Posted by Alevice
dont use getlocal player. just do a loop that checks for all players. that would be simpler, and displaytexttoplayer doesnt really need to use a local player argument.
yes this function is already made for a specific player, no need of local player here.

Quote:
Originally Posted by Tyrande_ma3x
which is basically a lot better than using GetPlayerState comparision. So I guess I'll use that.
I THINK (need to test) IsPlayerObserver() will return true if the player is an OBSERVER_ON_DEATH or OBSERVER, and the function GetPlayerState(<player>,PLAYER_STATE_OBSERVER) should make the difference between these 2 status, and you should probably no need to make the difference anyway.