- Joined
- Nov 4, 2019
- Messages
- 400
So... For the past 7 days I have tried to resolve the desyncs in my map and I think I have found the cause. When using the frame natives to create units there's a good chance that they are created with different handles.
For context:
I have a character select "screen" similar to that of WoW, and when the player selects a new class they want to create I remove and add the unit displayed in front of the player.
The difference in handles lead me to believe that the frame natives were async and I proceeded to create the units inside a synced event. And guess what? They are still created with different handles.
I then asked the Hive discord if I had to sync the button click and they told me the frames aren't async. So I changed it back and then created a timer and a boolean check for the button click so people can't spam the buttons, but still, the units are created with different handles.
Here's a demonstration (sry, I accidentally launched PlanetSide 2 a couple of times):
The heroes are loaded for each player (keep in mind I'm on the same PC so it loads the same hero for every client, if that confuses anyone), and the handles are the same on each client, so that's all good. But watch what happens when I swap between the different classes. At the end when I print the handles for every player you can see player 1 is out of sync with the others, and I'm just confused as hell.
Here's the code (Lua):
For context:
I have a character select "screen" similar to that of WoW, and when the player selects a new class they want to create I remove and add the unit displayed in front of the player.
The difference in handles lead me to believe that the frame natives were async and I proceeded to create the units inside a synced event. And guess what? They are still created with different handles.
I then asked the Hive discord if I had to sync the button click and they told me the frames aren't async. So I changed it back and then created a timer and a boolean check for the button click so people can't spam the buttons, but still, the units are created with different handles.
Here's a demonstration (sry, I accidentally launched PlanetSide 2 a couple of times):
The heroes are loaded for each player (keep in mind I'm on the same PC so it loads the same hero for every client, if that confuses anyone), and the handles are the same on each client, so that's all good. But watch what happens when I swap between the different classes. At the end when I print the handles for every player you can see player 1 is out of sync with the others, and I'm just confused as hell.
Here's the code (Lua):
JavaScript:
function SelectClassFuncAlliance()
local player = GetConvertedPlayerId(GetTriggerPlayer())
-- Expand this loop when new classes gets added
for i = 1, 3 do
if (BlzGetTriggerFrame() == classFrame[i] and selectClassClickCheck[player] == false) then
selectClassClickCheck[player] = true
selectedCharName[player] = heroname[i]
selectedCharClass[player] = class[i]
CharSelectClick()
if (GetLocalPlayer() == GetTriggerPlayer()) then
BlzFrameSetEnable(classFrame[1], false)
BlzFrameSetEnable(classFrame[2], false)
BlzFrameSetEnable(classFrame[3], false)
BlzFrameSetEnable(classFrame[11], false)
BlzFrameSetEnable(classFrame[12], false)
BlzFrameSetEnable(classFrame[13], false)
BlzFrameSetEnable(cancelCharacter, false)
BlzFrameSetEnable(acceptCharacter, false)
end
break
end
end
end
function SelectClassFuncHorde()
local player = GetConvertedPlayerId(GetTriggerPlayer())
-- Expand this loop when new classes gets added
for i = 11, 13 do
if (BlzGetTriggerFrame() == classFrame[i] and selectClassClickCheck[player] == false) then
selectClassClickCheck[player] = true
selectedCharName[player] = heroname[i]
selectedCharClass[player] = class[i]
CharSelectClick()
if (GetLocalPlayer() == GetTriggerPlayer()) then
BlzFrameSetEnable(classFrame[1], false)
BlzFrameSetEnable(classFrame[2], false)
BlzFrameSetEnable(classFrame[3], false)
BlzFrameSetEnable(classFrame[11], false)
BlzFrameSetEnable(classFrame[12], false)
BlzFrameSetEnable(classFrame[13], false)
BlzFrameSetEnable(cancelCharacter, false)
BlzFrameSetEnable(acceptCharacter, false)
end
break
end
end
end
function CharSelectClick()
local convertedPlayerID = GetConvertedPlayerId(GetTriggerPlayer())
local class = selectedCharClass[convertedPlayerID]
if (charSelectDisplayUnit[convertedPlayerID] ~= nil) then
RemoveUnit(charSelectDisplayUnit[convertedPlayerID])
end
local location =
PolarProjectionBJ(
GetRectCenter(udg_CharacterSelectRegion[convertedPlayerID]),
256,
252 + convertedPlayerID * 18
)
CreateUnitAtLocSaveLast(Player(27), class, location, 252 + convertedPlayerID * 18)
print(bj_lastCreatedUnit)
charSelectDisplayUnit[convertedPlayerID] = bj_lastCreatedUnit
StartTimerBJ(udg_SelectCharTimer[convertedPlayerID], false, 2)
end
function CharSelectTimerExpire()
local player = Player(27)
local convertedPlayerID
for i = 1, bj_MAX_PLAYER_SLOTS do
if(GetExpiredTimer() == udg_SelectCharTimer[i]) then
print(i)
player = Player(i-1)
convertedPlayerID = GetConvertedPlayerId(player)
selectClassClickCheck[convertedPlayerID] = false
if (GetLocalPlayer() == player) then
BlzFrameSetEnable(classFrame[1], true)
BlzFrameSetEnable(classFrame[2], true)
BlzFrameSetEnable(classFrame[3], true)
BlzFrameSetEnable(classFrame[11], true)
BlzFrameSetEnable(classFrame[12], true)
BlzFrameSetEnable(classFrame[13], true)
BlzFrameSetEnable(cancelCharacter, true)
BlzFrameSetEnable(acceptCharacter, true)
end
break
end
end
end