• Print

Author Topic: end map dilemma  (Read 4783 times)

0 Members and 1 Guest are viewing this topic.

Offline talmera

  • Newbie
  • *
  • Posts: 36
  • Karma: 4
    • Tectonic-Gaming
end map dilemma
« on: February 26, 2014, 08:58:11 pm »
Hi, I've been coding a cross server experience system for my community and I have it mostly ready for public testing but I'm having trouble figuring out how to get it to save the exp when the map is getting changed I have it saving fine on player disconnect.

I was wondering what would be the best approach to do this?
It's not a sin if it can't make me cry
He's not the devil unless there's fire in his eyes
It ain't the ghost if it don't speak in tongue
It's not a victory 'till the battles been won

Offline Eccid

  • Full Member
  • ***
  • Posts: 115
  • Karma: 11
  • Hey, come on... We just met...
    • Terror Abound! Steam Group
Re: end map dilemma
« Reply #1 on: February 26, 2014, 09:06:24 pm »
Try using the Shutdown Hook and making it save then.

Offline talmera

  • Newbie
  • *
  • Posts: 36
  • Karma: 4
    • Tectonic-Gaming
Re: end map dilemma
« Reply #2 on: February 26, 2014, 09:15:30 pm »
oh cool I completely missed that hook when looking for a solution XD thanks I'll give it a go.
It's not a sin if it can't make me cry
He's not the devil unless there's fire in his eyes
It ain't the ghost if it don't speak in tongue
It's not a victory 'till the battles been won

Offline talmera

  • Newbie
  • *
  • Posts: 36
  • Karma: 4
    • Tectonic-Gaming
Re: end map dilemma
« Reply #3 on: February 27, 2014, 03:30:11 am »
Hmmm so I set up this function for use on the Shutdown hook you suggested but it's not called on map change like I was hoping?

Code: Lua
  1. function saveAll()
  2.        
  3.         for k,v in pairs( player.GetAll() ) do
  4.        
  5.                 local PlyFormat = string.Replace(v:SteamID(), ":", "")
  6.                 local PlySteam = v:SteamID()
  7.                 local saver = Database:query("UPDATE exp_storage SET `exp_total`='" .. tec_PlyExp[PlySteam] .. "' WHERE `steam_id`='" .. PlyFormat .. "'" )
  8.                
  9.                 saver.onSuccess = function()
  10.                         print("[TGEXP] User saved to database")
  11.                 end
  12.                
  13.                 saver.onError = function()
  14.                         print("[TGEXP] save failed on leave")
  15.                 end
  16.                
  17.                 saver:start()
  18.        
  19.         end
  20. end
  21.  
  22. hook.Add( "ShutDown", "savingAll", saveAll )

*Notes*

I am using the MySQLoo "addon" to update a database with the new values a player has for exp and I'm attempting to save all players on map change/server shutdown.

*Update*

after some tinkering it appears to be working now.
« Last Edit: February 27, 2014, 07:50:45 am by talmera »
It's not a sin if it can't make me cry
He's not the devil unless there's fire in his eyes
It ain't the ghost if it don't speak in tongue
It's not a victory 'till the battles been won

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: end map dilemma
« Reply #4 on: March 01, 2014, 02:44:14 pm »
Gmod crashes a lot, I'd recommend saving in intervals you're comfortable losing. E.g., if you only want to lose up to 30 seconds of data, save every 30 seconds.
Experiencing God's grace one day at a time.

  • Print