OneSync / SERVER/CLIENT-SIDE Data Sharing

Early 'state bag' arraived

Features

  • Set data to any entity or object
  • Share the data with server / client

How to use it (Lua)

Server-side

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.

3 Likes

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.

1 Like

Because players state bags wasn’t introduced in the « early version » of statebag ?

So this bug is probably fixed ?

About the GlobalState.mode was explained at the github commit, I just added it when testing and it was working like that.

If you check the mentioned commit, I didn’t updated this post, so there wasn’t any Player statebag :confused:

When I tested all sort of things about the early StateBag, they were lost when a new player joined the server.

Before doing such comments, update the information if you know more about it.

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.

But it was introduced before this guide was even posted (reference).

As the rest of this was already commented on by bubble, I’ll respond to the last statement.

I already did

This post is deprecated / outdated, so I will delete to not create confusion between posts.

1 Like

OP request