Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*---------------------------------------------------------
- Leveling system
- ----------------------------------------------------------*/
- function saveStat ( ply )
- level = ply:GetNWInt("level")
- currentxp = ply:GetNWInt("currentxp")
- unique_id = ply:GetNWString ("steamID")
- levelxp = ply:GetNWInt ("levelxp")
- DB.Query("UPDATE darkrp_level SET level = "..level.." WHERE unique_id = '"..unique_id.."'")
- DB.Query("UPDATE darkrp_level SET currentxp = "..currentxp.." WHERE unique_id = '"..unique_id.."'")
- --ply:ChatPrint("Stats updated!\n")
- end
- function checkifLeveled( ply )
- ply:GetNWInt("currentxp", currentxp)
- ply:GetNWInt("levelxp", levelxp)
- ply:GetNWInt("level", level)
- if (currentxp >= levelxp) then
- ply:SetNWInt("level", level+1)
- ply:SetNWInt("currentxp", 0)
- DB.QueryValue("SELECT levelxp FROM darkrp_xpforlevel WHERE level = " .. sql.SQLStr(level+1) .. ";", function(lvlxp)
- if lvlxp then
- ply:SetNWInt("levelxp", lvlxp)
- end
- end)
- end
- end
- function load_stats ( ply )
- DB.QueryValue("SELECT level FROM darkrp_level WHERE unique_id = " .. sql.SQLStr(ply:SteamID()) .. ";", function(lvl)
- if lvl then
- Msg("Loading Stats!\n")
- ply:SetNWInt("level", lvl)
- DB.QueryValue("SELECT currentxp FROM darkrp_level WHERE unique_id = " .. sql.SQLStr(ply:SteamID()) .. ";", function(currxp)
- if currxp then
- ply:SetNWInt("currentxp", currxp)
- end
- end)
- DB.QueryValue("SELECT levelxp FROM darkrp_xpforlevel WHERE level = " .. sql.SQLStr(lvl) .. ";", function(lvlxp)
- if lvlxp then
- ply:SetNWInt("levelxp", lvlxp)
- end
- end)
- else
- Msg("Player Doesnt exist!\n")
- DB.Query( "INSERT INTO darkrp_level (`unique_id`, `level`)VALUES (" .. sql.SQLStr(ply:SteamID()) .. ", '1');", function(r) end)
- ply:SetNWInt("level", 1)
- ply:SetNWInt("currentxp", 1)
- ply:SetNWInt("levelxp", 2500)
- end
- end)
- end
- function PlayerInitialSpawn( ply )
- timer.Create("Steam_id_delay", 5, 1, function()
- steamID = ply:SteamID()
- ply:SetNWString("steamID", steamID)
- timer.Create("SaveStat", 10, 0, function() saveStat( ply ) end)
- timer.Create("checkifLeveled", 10, 0, function() checkifLeveled( ply ) end)
- load_stats( ply )
- end)
- end
- hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", PlayerInitialSpawn )
- hook.Add( "PlayerDisconnected", "playerdisconnected", saveStat )
Add Comment
Please, Sign In to add comment