Ulysses
General => Developers Corner => Topic started by: LuaTenshi on December 25, 2012, 05:04:25 PM
-
How would I store data on players such as Score amounts (I need to have them store in a database so people don't lose their score when they leave.) and stuff like that?
I was thinking of using Networked-Vars but after Megiddo said they where broken I am not so sure about using them, so any ideas?
-
I never said they were broken, I said that they have historically been terrible. As in, slow to update, sometimes not synching properly.
-
I never said they were broken, I said that they have historically been terrible. As in, slow to update, sometimes not synching properly.
For me that translates into broken. lol.
-
You could just make a hook for when they leave (I believe it's best to use "OnEntityRemoved" and check if it's a player), get their score (GetFrags()?) and save it.
-
You could just make a hook for when they leave (I believe it's best to use "OnEntityRemoved" and check if it's a player), get their score (GetFrags()?) and save it.
Yes but I would like to score to update live so where would I hold it then?
-
Yes but I would like to score to update live so where would I hold it then?
I'm confused. If you need to be able to get any player's score (frags/kills) at any time, just use ply:GetFrags().
-
Ryno (glad to see you back btw), I think he's trying to figure out best way/place to store them non-live..that is, through SQLite, SQL, or flat text table.
Though the GetFrags and other functions could be used live...I think he wants to have the score/frags tables get stored somewhere offline whenever they get updated.
Then when a player leaves/rejoins...stuff is still there and loads into live data.
(I could be wrong)
-
You could use a hook for "PlayerInitialSpawn" and create a timer for that player that updates every second.
function updatePlayer( ply )
// Your code to save the frags/data/etc.
end
function timerStart( ply )
timer.Create( "save_stats_"..tostring(ply:SteamID()), 1, 0, function() if not (ply and IsValid(ply)) then return end updatePlayer( ply ) end ) // Runs every second forever.
end
hook.Add( "PlayerInitialSpawn", "timerstarting", timerStart )
function destroyTimers(ply) // Destroy the timers when they disconnect and save their stats one more time.
if (ply and IsValid(ply)) then updatePlayer( ply ) end
if timer.Exists("save_stats_" ..tostring(ply:SteamID())) then
timer.Stop("save_stats_" ..tostring(ply:SteamID()))
timer.Destroy("save_stats_" ..tostring(ply:SteamID()))
end
end
hook.Add( "PlayerDisconnected", "PromotionCleanUP", destroyTimers )