JASS: GetLocalPlayer()

Discussion in 'Tutorial Repository' started by PurgeandFire, Apr 13, 2008.

  1. Andrewgosu

    Andrewgosu The Silent Pandaren Helper Staff Member

    Ratings:
    +711 / 0 / -0
    This tutorial has an excellent layout, it's nicely written and easily understandable.

    the misusage of "GetLocalPlayer()" function is one of the most common reasons of desyncs
    and I doubt anyone will argue me if I state this tutorials explains very well how
    to get around using the function properly.

    Approved.
     
  2. PurgeandFire

    PurgeandFire zxcvmkgdfg

    Ratings:
    +513 / 0 / -0
    Thanks for the approval! :)

    I hope this helps many people to solve their disconnection problems!
     
  3. Strilanc

    Strilanc Veteran Scripter

    Ratings:
    +42 / 0 / -0
    I got a bunch of rep for this post, so people seemed to like the description. Maybe you'll find it useful.

     
  4. pablo1517

    pablo1517 New Member

    Ratings:
    +1 / 0 / -0
    is GetLocalPlayer() a way to for eg. play a music theme just for 1 player?
    Like let's say: Player 3 got to the forest, i want to play forest theme just by player 3, is this possible?
     
  5. Romek

    Romek Super Moderator Staff Member

    Ratings:
    +961 / 0 / -0
    Yes. Although I don't think you can create sound variables for local players, you should be able to start/stop the sound without any risks :)
     
  6. pablo1517

    pablo1517 New Member

    Ratings:
    +1 / 0 / -0
    I would like to make something like - if player is in a tavern for example, then he hears tavern music, but only the player which is in tavern actually :D. I hope I'll get it. Thx.
     
  7. Light Alkmst

    Light Alkmst New Member

    Ratings:
    +20 / 0 / -0
    Maybe I missed something in the tutorial, but what are the usages of GetLocalPlayer(), and not just telling all of the computers about what you're doing to one computer? Is it a way to reduce potential code?

    Code:
    if (GetLocalPlayer() == GetTriggerPlayer()) then
         // Would this work for getting the triggering player only to run this code?
    endif
    
    also, (slightly off-topic) if you have a trigger that sends one player a message without using GetLocalPlayer(), would it send the message only once or once per player processing it?

    EDIT: another question: if there is a desync caused by GetLocalPlayer(), will it only boot the desynced player, or everyone in the game?

    scenario:
    Code:
    // Let's say this code runs on some normally undetectable unit being spotted
    function Some_Handwritten_Anti_MH_Code_Actions takes nothing returns nothing
         if (GetLocalPlayer() == TriggeringPlayer()) then
              call CreateUnitAtLoc(GetLocalPlayer(), 'A000', Location(0.0, 0.0))
         endif
    endfunction
    // Would it desync only the hacking player?
    
     
  8. AceHart

    AceHart Your Friendly Neighborhood Admin

    Ratings:
    +1,489 / 0 / -0
    > Would this work for getting the triggering player only to run this code?

    That is the entire point of that function...

    > would it send the message only once or once per player processing it?

    Game - Display to ... the text: "Now you're over-reacting"
    Using GetLocalPlayer() requires care. Nothing more. Paranoia is not required.

    > will it only boot the desynced player, or everyone in the game

    Nice try.
     
    • Like Like x 1
  9. Light Alkmst

    Light Alkmst New Member

    Ratings:
    +20 / 0 / -0
    Is that a yes?:confused:
     
  10. Nexor

    Nexor ...

    Ratings:
    +74 / 0 / -0
    I'm trying to make a local weather system, but I can't get it working. here's the code:

    JASS:
    function Actions takes nothing returns nothing
    
        local integer i
        local string s
        set s = SubString(GetEventPlayerChatString(), 10, StringLength(GetEventPlayerChatString()))
        call EnableWeatherEffect( GetLastCreatedWeatherEffect(), false )
        if GetLocalPlayer() == GetTriggerPlayer()  then
            if     s == "rain" then
                set i = 'RAlr'
            elseif s == "snow" then
                set i = 'SNbs'
            elseif s == "off" then
                set i = 0
                
            endif
        endif
        
        call AddWeatherEffectSaveLast( GetPlayableMapRect(), i )
        call EnableWeatherEffect( GetLastCreatedWeatherEffect(), true )
    endfunction
    
    //===========================================================================
    function InitTrig_Test takes nothing returns nothing
    
        local trigger t = CreateTrigger(  )
        call TriggerRegisterPlayerChatEvent( t, Player(0), "-weather", false )
        call TriggerAddAction( t, function Actions )
        set t = null
    
    endfunction


    What's wrong here? there's no dsyncing (i think) but the effect won't show :( pls help me
     
  11. Nexor

    Nexor ...

    Ratings:
    +74 / 0 / -0
    bump
     
  12. Furby

    Furby Current occupation: News poster

    Ratings:
    +140 / 0 / -0
  13. Vestras

    Vestras Retired

    Ratings:
    +249 / 0 / -0
    ^Yes.
     
  14. tooltiperror

    tooltiperror Super Moderator Staff Member

    Ratings:
    +233 / 0 / -0
    Thanks, I always wondered why you did x100000 or whatever.
     
  15. annihilator127

    annihilator127 Member

    Ratings:
    +7 / 0 / -0
    I have seen desyncs on my DS when my brother used Action Replay to cheat in multiplayer. It seems that the game (which in this case was New Super Mario Bros.) sends details about button presses to the other consoles, so if one player uses AR, and the others don't, it will desync.
    He used the 'always have item' cheat, so his console thought he had the item, and my console didn't.

    Eventually he killed 'me' on his game and his console thought he won, and my console thought the game was still going, so his game hanged on the score screen waiting for mine to finish.
    Then when we started the next round, we were looking at different courses!

    LMAO; obviously this game doesn't realise it had desynched and cut it off like Warcraft etc. do.

    If we hadn't turned off the game before then, eventually his console would show him winning 3 games to nil and disconnect, and my console would be showing something different and report a connection failure.

    P.S. Someone please tell me how I can change the text on my account where it says 'Junior User'.
     
  16. jackall

    jackall You can change this now in User CP.

    Ratings:
    +39 / 0 / -0
    Trigger:
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • (Entered chat string) Equal to !show kills
      • Then - Actions
        • Custom script: if GetTriggerPlayer()==GetLocalPlayer() then
        • Leaderboard - Show KillLDB
        • Custom script: endif
      • Else - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Entered chat string) Equal to !hide kills
          • Then - Actions
            • Custom script: if GetTriggerPlayer()==GetLocalPlayer() then
            • Leaderboard - Hide KillLDB
            • Custom script: endif
          • Else - Actions

    Does it cause a desync if i use it like that?
     
  17. luorax

    luorax Invasion in Duskwood

    Ratings:
    +67 / 0 / -0
    Showing/Hiding quests, multiboards, texttags locally won't cause desyncs, I don't think hiding a leaderboard would do it either.
     
    • Like Like x 1
  18. PurgeandFire

    PurgeandFire zxcvmkgdfg

    Ratings:
    +513 / 0 / -0
    Luorax is correct. It will not cause a desync--that code is safe. ;)
     

Share This Page