Hello, my first question here.
How can I set and get random per-player (cPlayer) data. I want to use it eg to store current effects of a player (when overriding them) or a position or something. A bit like just a random space to save data tied to a player
Maybe there is an obvious solution, but thanks, anyway
Perhaps you can open a player's json file to add/change stuff. Every player has one in the players folder. Since we just got a JSON serializer and deserializer it shouldn't be too hard.
(02-18-2016, 07:56 AM)NiLSPACE Wrote: [ -> ]Perhaps you can open a player's json file to add/change stuff. Every player has one in the players folder. Since we just got a JSON serializer and deserializer it shouldn't be too hard.
Rather than editing server files, wouldn't it be cleaner if the plugin has its own json file? Each object in that file would have a player name for identification, and that player's plugin data. This is better because if I ever delete the plugin's folder, it won't leave junk behind. Also, all you have to do for resetting the plugin is deleting the plugin's data files, instead of editing the server's player files.
I would prefer writing a separate file for each player, but how to store any data just in memory? (and accessing it, with the corresponding cPlayer object)
(02-18-2016, 05:14 PM)Schwertspize Wrote: [ -> ]I would prefer writing a separate file for each player, but how to store any data just in memory? (and accessing it, with the corresponding cPlayer object)
-- Global storage table
PlayerStorage = {}
PlayerUUID = my_cPlayer_object:GetUUID()
-- Create new player storage, if not created already
if PlayerStorage[PlayerUUID] == nil then
PlayerStorage[PlayerUUID] = {}
end
-- Save player data
PlayerStorage[PlayerUUID].effect = "whatever";
PlayerStorage[PlayerUUID].etc = 42814
-- Check and read player data
if PlayerStorage[PlayerUUID].effect ~= nil then
-- Data exists
else
-- Data does not exist
end
-- Delete specific player data
PlayerStorage[PlayerUUID].effect = nil
-- Delete all player data
PlayerStorage[PlayerUUID] = nil
Rather than addressing by playername, you should address by UUID, other than that, this is most likely the best approach so far. Also, it allows you to serialize the data to a DB when you decide to make it permanent at a later point in the development.
I updated this accordingly.
Zzzzzz playsrName = GetUUID .... But thanks, I will use it
And that's how bugs are born

Thanks. Updated.