Author Topic: Storing data like score amounts and or money, for each player.  (Read 4118 times)

0 Members and 2 Guests are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Storing data like score amounts and or money, for each player.
« 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 cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Storing data like score amounts and or money, for each player.
« Reply #1 on: December 25, 2012, 11:07:55 PM »
I never said they were broken, I said that they have historically been terrible. As in, slow to update, sometimes not synching properly.
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Storing data like score amounts and or money, for each player.
« Reply #2 on: December 26, 2012, 12:38:43 AM »
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.
I cry every time I see that I am not a respected member of this community.

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: Storing data like score amounts and or money, for each player.
« Reply #3 on: December 26, 2012, 01:18:21 AM »
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.


YouTube music player by RynO-SauruS

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Storing data like score amounts and or money, for each player.
« Reply #4 on: December 26, 2012, 10:21:36 AM »
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?
I cry every time I see that I am not a respected member of this community.

Offline RynO-SauruS

  • Jr. Member
  • **
  • Posts: 77
  • Karma: 17
Re: Storing data like score amounts and or money, for each player.
« Reply #5 on: December 26, 2012, 02:58:25 PM »
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().


YouTube music player by RynO-SauruS

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Storing data like score amounts and or money, for each player.
« Reply #6 on: December 26, 2012, 03:06:13 PM »
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)

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline emilhem

  • Newbie
  • *
  • Posts: 21
  • Karma: 3
Re: Storing data like score amounts and or money, for each player.
« Reply #7 on: December 29, 2012, 01:10:49 PM »
You could use a hook for "PlayerInitialSpawn" and create a timer for that player that updates every second.

Code: [Select]
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 )