• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Register Trigger with GetLocalPlayer?

Status
Not open for further replies.
Level 13
Joined
Mar 16, 2008
Messages
941
I would be VERY carefull with this. I've never worked with local triggers, but anything that affects the game in here would desync, if not even the event itself desyncs. If the event works fine, you're restricted to anything that can be done in a "local block". The problem is, that for example, you need to create stuff and show/hide it localy, what's impossible with this. If this works, and you're sure to use a proper code in the action, this COULD work.
 
For such cases, you can add the player you want to a Player Group and register stuff, refering to him as EnumPlayer() and remove him when certain actions are done. So you will actually have a condition to check if that player you want (up to the event) is in that Player Group. Using locals in this case is extremely dangerous, you know it already.
 
I imagine it's impossible to cause any problems for just one player, right?

I want this to affect a single player so that he doesn't have to be red to have game controls.

Say you do something like this:
JASS:
function DesyncHehe takes nothing returns nothing
    call CreateUnit(GetTriggerPlayer(),'hfoo',0,0,0)
    //Will cause a disconnection =(
endfunction
function InitTrig_Local takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerEvent(t,GetLocalPlayer(),EVENT_PLAYER_END_CINEMATIC)
    call TriggerAddAction(t,function DesyncHehe)
    set t = null
endfunction

It will sadly cause a disconnection. =( I've tried doing this to make the RegisterAnyUnitEventBJ() a bit faster (so it doesn't have to have 1 register function per player) but I later figured out that the functions were done locally as well.

If you do this, the player will have game controls locally. It is better to do this globally since it wouldn't matter for it to be local anyway. I don't know if it'd cause a desync in your case (since I don't know what the game controls for your map are), but I'd refrain a bit from it just to be safe. ;)
JASS:
function NoDesyncHehe takes nothing returns nothing
    if GetTriggerPlayer() != Player(0) then
        call EnableGameControls(GetTriggerPlayer()) //random non-existent function, lol
    endif
endfunction
function InitTrig_Local takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer i = 0
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerEvent(t,Player(i),EVENT_PLAYER_END_CINEMATIC)
        set i = i + 1
    endloop
    call TriggerAddAction(t,function NoDesyncHehe)
    set t = null
endfunction

... Unless you're asking something else and I am completely off. D: If so then you can ignore this post. =P
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You can't create handles locally and expect the game not to desync. Local code means that it doesn't change the objects in place, though it may change data associated with those objects here and there. Obviously a specific player is not allowed to have units being created that aren't for the other players, that wouldn't make any sense.
 
Status
Not open for further replies.
Top