-
Notifications
You must be signed in to change notification settings - Fork 3
Global ModData
- GlobalModData will be lost if the world is reset.
- Both client and server can have their own GlobalModData.
- Clients can request the server's GlobalModData latest data.
- Server can send the latest data to all clients.
In your config file
ClientModData = {
PriceList = true, -- true mean we request to the server when the client has connect
localPlayer = false -- false mean we will only store this mod data locally on the client
},
ServerModData = {
"PriceList", -- ServerModData are only local to the server
},To have a client and server GlobalModData table synchronized both must have the same name.
The Custom Event OnModDataInitialized is an internal event and do not need to be added to your config.
It is triggered after the GlobalModData is initialized, so the table are ready to be read and written to.
Client
local function onModDataInitialized()
Client.Log( Client.Data.LocalPlayer ) --- Table is ready with it's data
Client.Log( Client.Data.PriceList ) --- Is ready but data is not received yet
end
Client.AddEvent("OnModDataInitialized", onModDataInitialized);Client GlobalModData request data to the server during the initialization, so it will not have the data just yet.
Server
local function onModDataInitialized()
Server.Log( Server.Data.PriceList ) --- Table is ready with it's data
end
Server.AddEvent("OnModDataInitialized", onModDataInitialized);Never set the GlobalModData table directly, eg:
Client.Data.LocalPlayer = {}or it will not point not save it into GlobalModData anymore.
GlobalModData tables can be
array tableand/orkey pairs tableonly.
It is not recommended to save instance object into ModData, those object cannot load back into an instance.