General > Developers Corner
Storing data like score amounts and or money, for each player.
RynO-SauruS:
--- Quote from: HeLLFox_15 on December 26, 2012, 10:21:36 AM ---Yes but I would like to score to update live so where would I hold it then?
--- End quote ---
I'm confused. If you need to be able to get any player's score (frags/kills) at any time, just use ply:GetFrags().
JamminR:
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)
emilhem:
You could use a hook for "PlayerInitialSpawn" and create a timer for that player that updates every second.
--- Code: ---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 )
--- End code ---
Navigation
[0] Message Index
[*] Previous page
Go to full version