proracer Posted January 25, 2011 Share Posted January 25, 2011 I found how to use it on Wiki but not really clearly (not with SQL functions).I was trying to do it completely from scratch and changing played time from seconds to hours. I'm not really sure If it that is all correct but my main point is that I want to refresh join time every 5 seconds. Can I use a timer for it, because I'm not totally sure about messing with SQL functions. This will be created in the GUI. function createSQLTables() -- 1st table (Player Stats) executeSQLCreateTable( "PlayerStats", "HoursPlayed INT, PtsEarned INT, Rank INT, KmTraveledByFoot INT, KmTraveledByCar INT, KmTraveledByBike INT, KmTraveledByAircrafts INT, KmTraveledByBoat INT, serial STRING") -- 2nd table (Player Achievements) executeSQLCreateTable ( "PlayerAchievements", "EarnedAch INT, LeftAch INT, AchPts INT, serial STRING") -- 3rd table (Player Cash / Money) executeSQLCreateTable ( "PlayerCash", "EarnedCash INT, serial STRING") -- end of creating the tables end addEventHandler("onResourceStart", getResourceRootElement(), createSQLTables) function playerisReady(g_player) local serial = getPlayerSerial(g_player) local playername = getPlayerName(g_player) CheckPlayer = executeSQLSelect ("PlayerStats", "serial", "serial = '" ..serial.. "'") CheckPlayer2 = executeSQLSelect("PlayerAchievements", "serial", "serial = '" ..serial.. "'") CheckPlayer3 = executeSQLSelect("PlayerCash", "serial", "serial = '" ..serial.. "'") --- check the player now if (type(CheckPlayer) == "table" and #CheckPlayer == 0) or not CheckPlayer then executeSQLInsert ("PlayerStats", "'" ..serial.. "', '0', '0', '0', '0', '0', '0', '0', '0'") end if (type(CheckPlayer2) == "table" and #CheckPlayer2 == 0) or not CheckPlayer2 then executeSQLInsert ("PlayerAchievements", "'" ..serial.. "', '0', '0', '0'") end if (type(CheckPlayer3) == "table" and #CheckPlayer3 == 0) or not CheckPlayer3 then executeSQLInsert ("PlayerCash", "'" ..serial.. "', '0'") end end addEventHandler("onPlayerSpawn", getRootElement(), playerIsReady) --- #Hours Played -- saving element data function hoursPlayed() setElementData(source, "hoursPlayed", getTickCount()) end addEventHandler ("onPlayerSpawn", getRootElement(), hoursPlayed) -- main script function showHoursPlayed(source) local showHoursPlayed1 = executeSQLInsert ("PlayerStats", "HoursPlayed", "serial = '" ..serial.. "'") local timeOnline = (getTickCount() - getElementData(source, "hoursPlayed")) / 3600000 executeSQLUpdate("PlayerStats", "HoursPlayed = '" ..showHoursPlayed1.. "'", "serial = '" ..serial.. "'") end Link to comment
Castillo Posted January 26, 2011 Share Posted January 26, 2011 I think this is part from some community script. Link to comment
proracer Posted January 26, 2011 Author Share Posted January 26, 2011 No, everything is made from scratch.Used MTA Wiki for little help of course Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now