GlobalState.mode = 'open'
--[[ set state mode to 'open' so client-side can share to server]]
local player = Entity(GetPlayerPed(source))
-- get Entity object from Entity id
player.state.anyKeyHere = anyValueHere
-- set any key and value to Entity state
print(player.state.anyKeyHere)
-- return the 'anyKeyHere' set
Client-side
local player = Entity(PlayerPedId())
--[[ same as server get Entity object from Entity id ]]
print(player.state.anyKeyHere)
-- return the previus value set from server
player.state:set('anyKeyHere', anyValueHere, true --[[ bool | share with server? ]])
-- set any key and value to Entity state from client
Tested with other players. Yes, data is shared with all the players on the net
Important issue with this
This is something like Decorators but an advanced Decor.
So that means, when you set data to an Entity and then a new player connect to the server, that data isn’t shared. The data it’s only shared with the currently net players, not new players.
A lot of this information is inaccurate or not implemented correctly.
GlobalState.mode = ‘open’
–[[ set state mode to ‘open’ so client-side can share to server]]
This does nothing, its a global variable, doesn’t ‘allow’ or ‘disallow’ transferring of data.
local player = Entity(GetPlayerPed(source))
Why are you using the Entity when there is the player?
local player = Player(source)
This is something like Decorators but an advanced Decor.
So that means, when you set data to an Entity and then a new player connect to the server, that data isn’t shared. The data it’s only shared with the currently net players, not new players.
This is completely wrong, this isn’t just an ‘advanced’ decor, and all data is shared even after player join/leave.
Nothing ‘was explained’ there, it’s an example of using GlobalState which is a state bag not associated with any entity, you somehow made it up as ‘duh it’s a mode’.
I’ve never been told about any such bug, entity state and global state have always been working, no idea why this person treats it as intended or why he compared it to game decor stuff which is also retained on entity create.
When I made my own testings with this behavior, I just set a StateBag into a NPC created server-side. Players already connected could get key I’ve previously set, then when a new player joined the server, he couldn’t get the key.