• 🏆 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] Get Local Player for UI Modification

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,720
I think so, yes. One has to do use GetLocalPlayer for that. In that context some people on hive discord said that using BlzGetOriginFrame inside a local block can disconnect. They recommended to use BlzGetOriginFrame synced and do only the action (show, hide, enable, repos ...) inside the GetLocalPlayer block.

Edit: BlzGetOriginFrame and/or BlzGetFrameByName will dc the game, if used localy only.

Edit Edit Added 16 July 2019 : This is only partly correct. BlzGetFrameByName/BlzGetOriginFrames can be used in GetLocalPlayer blocks without desync when the function using the same arguments was called at an earlier time for all players. My explanition for that is, this functions are creating a new handle when that frame did not have a handle yet. I was wondering before why the handleIds of basic frames where so instable different in my tests. When the first call is in a GetLocalPlayer block the handle stack gets desync and the game breaks. Custom Created Frames get handles at creation and won't desync, when they were created for all players.
Alright guys after reading that I'm super confused about using LocalPlayer for UI Modifications.

Basically my goal is to make a UI Inventory and that involves showing/hiding/moving a lot of "framehandles"

If I'm correct frames should never be created with local player right?
JASS:
local framehandle invall = BlzCreateFrameByType("BACKDROP" , "InventoryUI" , BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)

Instead all frames should be created for all players and then you can locally show/hide/move them
JASS:
if GetLocalPlayer() == GetTriggerPlayer() then
call BlzFrameSetVisible(BlzGetFrameByName("InventoryUI",0) , true)
endif

Code in the Test Map I Provided:
JASS:
function Inventory_Actions takes nothing returns nothing
    local framehandle invall = BlzCreateFrameByType("BACKDROP" , "InventoryUI" , BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    call BlzFrameSetSize(invall, 0.3, 0.3)
    call BlzFrameSetAbsPoint(invall, FRAMEPOINT_CENTER, 0.63, 0.35)
    call BlzFrameSetTexture(invall, "Inventory.tga",0, true)
endfunction
//===========================================================================
function InitTrig_Inventory_UI takes nothing returns nothing
    set gg_trg_Inventory_UI = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Inventory_UI, 0.40 )
    call TriggerAddAction( gg_trg_Inventory_UI, function Inventory_Actions )
endfunction
  • Hide Show Inventory
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Backpack
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Inventory_Hide[(Player number of (Owner of (Triggering unit)))] Equal to False
        • Then - Actions
          • Set Inventory_Hide[(Player number of (Owner of (Triggering unit)))] = True
          • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
          • Custom script: call BlzFrameSetVisible(BlzGetFrameByName("InventoryUI",0) , true)
          • Custom script: endif
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Inventory_Hide[(Player number of (Owner of (Triggering unit)))] Equal to True
            • Then - Actions
              • Set Inventory_Hide[(Player number of (Owner of (Triggering unit)))] = False
              • Custom script: if GetLocalPlayer() == GetTriggerPlayer() then
              • Custom script: call BlzFrameSetVisible(BlzGetFrameByName("InventoryUI",0) , false)
              • Custom script: endif
            • Else - Actions
I tested this in single player with different players and it works for each player, I'm just not sure if it will cause desync when used in multiplayer, so I'm seeking the help of an expert.
 

Attachments

  • Inventory UI LocalPlayer.w3x
    36.8 KB · Views: 44
If I'm correct frames should never be created with local player right?

Correct.

Instead all frames should be created for all players and then you can locally show/hide/move them

Yes.

I tested this in single player with different players and it works for each player, I'm just not sure if it will cause desync when used in multiplayer, so I'm seeking the help of an expert.

You can run multiple instances of the game and test for desyncs in LAN.
 
Status
Not open for further replies.
Top