GanJaRuleZ Posted January 11, 2012 Share Posted January 11, 2012 (edited) Hi allz, In the last week , i worked just on the race stats , but i can't make it working -.-' Here is the script : function DestructionWin() local alivePlayers = getAlivePlayers() if #alivePlayers == 1 then local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end local playername = getPlayerName(alivePlayers[1]) setAccountData(account,"Race Wins",tostring(raceWins)+1) outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) end addEventHandler("onPlayerWasted", getRootElement(), function() local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end setAccountData(account,"Race Loses",tostring(raceLoses)+1) end) function updateTimePlayed() setTimer(updateTimePlayed,1000,1) if isGuestAccount(account) then return end local account = getPlayerAccount(source) local timePlayed = getAccountData(account, "Time played") if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) end end end setTimer(updateTimePlayed,1000,1) function ratioCalculator() local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount(source) local raceLoses = getAccountData(account,"Race Loses") if raceLoses == 0 then setAccountData(account, "Ratio", "-") else local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) setAccountData(account, "Ratio", tostring(kdr)) end end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio " and the total time he played is : " .. timePlayed .. ", getRootElement(), 255, 12, 15,true) else setAccountData(account, "RaceWins" , 0) setAccountData(account, "RaceLoses" , 0) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) function checkCommand(message, messageType) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler("onPlayerChat", getRootElement(), checkCommand) And the error is : SCRIPT ERROR: stats\stats.lua:83: unexpected symbol near ')' Btw : The time played belongs to Solidsnake Thank you. Edited January 11, 2012 by Guest Link to comment
FatalTerror Posted January 11, 2012 Share Posted January 11, 2012 You have forget "end"... addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end end) Link to comment
GTX Posted January 11, 2012 Share Posted January 11, 2012 You also forgot something here: outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio " and the total time he played is : " .. timePlayed .. ", getRootElement(), 255, 12, 15,true) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he losed " .. loses .. " times ,his ratio is " .. ratio " and the total time he played is : " .. timePlayed, getRootElement(), 255, 12, 15,true) else setAccountData(account, "RaceWins" , 0) setAccountData(account, "RaceLoses" , 0) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) Link to comment
GanJaRuleZ Posted January 11, 2012 Author Share Posted January 11, 2012 Same error .. @GTX : Ty , i didn't saw that . Link to comment
arezu Posted January 11, 2012 Share Posted January 11, 2012 you also forgot two dots after ratio on line 94 Link to comment
myonlake Posted January 11, 2012 Share Posted January 11, 2012 function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) else setAccountData(account, "RaceWins" , 0) setAccountData(account, "RaceLoses" , 0) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) Link to comment
GanJaRuleZ Posted January 12, 2012 Author Share Posted January 12, 2012 @myonlake : The single thing you edited its the " .. ratio .. " Btw : not there is the problem : the problem is at line 83. Link to comment
codeluaeveryday Posted January 12, 2012 Share Posted January 12, 2012 Use myonlake script plus use this: addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) end if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) end if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") end if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end end) You forgot to close of the if's! Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 Well , i had a bit of free time and i tested it , it gives the following error : WARNING: stats\stats.lua:43: Bad argument @ 'setTimer' [Expected function at argument 1 , got nil] New script function DestructionWin() local alivePlayers = getAlivePlayers() if #alivePlayers == 1 then local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end local playername = getPlayerName(alivePlayers[1]) setAccountData(account,"Race Wins",tostring(raceWins)+1) outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) end addEventHandler("onPlayerWasted", getRootElement(), function() local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end setAccountData(account,"Race Loses",tostring(raceLoses)+1) end) function updateTimePlayed() setTimer(updateTimePlayed,1000,1) if isGuestAccount(account) then return end local account = getPlayerAccount(source) local timePlayed = getAccountData(account, "Time played") if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) end end end setTimer(updateTimePlayed,1000,1) function ratioCalculator() local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount(source) local raceLoses = getAccountData(account,"Race Loses") if raceLoses == 0 then setAccountData(account, "Ratio", "-") else local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) setAccountData(account, "Ratio", tostring(kdr)) end end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) end if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) end if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") end if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end end) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) else outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) function checkCommand(message, messageType) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler("onPlayerChat", getRootElement(), checkCommand) Link to comment
myonlake Posted January 14, 2012 Share Posted January 14, 2012 GanJa, actually it was an error. function DestructionWin() local alivePlayers = getAlivePlayers() if #alivePlayers == 1 then local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end local playername = getPlayerName(alivePlayers[1]) setAccountData(account,"Race Wins",tostring(raceWins)+1) outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) end addEventHandler("onPlayerWasted", getRootElement(), function() local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end setAccountData(account,"Race Loses",tostring(raceLoses)+1) end) function updateTimePlayed() if isGuestAccount(account) then return end local account = getPlayerAccount(source) local timePlayed = getAccountData(account, "Time played") if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) end end end setTimer(updateTimePlayed,1000,1) function ratioCalculator() local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount(source) local raceLoses = getAccountData(account,"Race Loses") if raceLoses == 0 then setAccountData(account, "Ratio", "-") else local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) setAccountData(account, "Ratio", tostring(kdr)) end end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) end if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) end if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") end if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end end) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) else outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) function checkCommand(message, messageType) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler("onPlayerChat", getRootElement(), checkCommand) Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 Same error but this time at line 42. Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 Try: function DestructionWin() local alivePlayers = getAlivePlayers() if #alivePlayers == 1 then local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end local playername = getPlayerName(alivePlayers[1]) setAccountData(account,"Race Wins",tostring(raceWins)+1) outputChatBox ( "#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true ) end addEventHandler("onPlayerWasted", getRootElement(), function() local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end setAccountData(account,"Race Loses",tostring(raceLoses)+1) end) setTimer( function() if isGuestAccount(account) then return end local account = getPlayerAccount(source) local timePlayed = getAccountData(account, "Time played") if (not timePlayed) then setAccountData(account, "Time played","0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) end end end ,1000,1) function ratioCalculator() local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount(source) local raceLoses = getAccountData(account,"Race Loses") if raceLoses == 0 then setAccountData(account, "Ratio", "-") else local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) setAccountData(account, "Ratio", tostring(kdr)) end end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins",tostring(raceWins)) else setAccountData(account,"Race Wins",0) end if raceLoses then setAccountData(account,"Race Loses",tostring(raceLoses)) else setAccountData(account,"Race Loses",0) end if timePlayed then setAccountData ( account, "Time played", tostring(hours) ..":".. tostring(mins) ..":".. tostring(newsec)) else setAccountData(account, "Time played","0:0:0") end if ratio then setAccountData(account,"Ratio",tostring(ratio)) else setAccountData(account,"Ratio",0) end end) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) else outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) function checkCommand(message, messageType) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler("onPlayerChat", getRootElement(), checkCommand) Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 Well , it solved it , but now another problem.. WARNING : Loading script failed : stats\stats:18: '(' expected near 'updateTimePlayed' Link to comment
myonlake Posted January 14, 2012 Share Posted January 14, 2012 (edited) Few missing ends there. Edited. function DestructionWin() local alivePlayers = getAlivePlayers() if #alivePlayers == 1 then local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end local playername = getPlayerName(alivePlayers[1]) setAccountData(account,"Race Wins",tostring(raceWins)+1) outputChatBox("#FFA824The player " .. playername .. " won!", getRootElement(), 255, 255, 255, true) end end addEventHandler("onPlayerWasted", getRootElement(), function() local account = getPlayerAccount(alivePlayers[1]) if isGuestAccount(account) then return end setAccountData(account, "Race Loses", tostring(raceLoses) + 1) end) setTimer(function() if isGuestAccount(account) then return end local account = getPlayerAccount(source) local timePlayed = getAccountData(account, "Time played") if (not timePlayed) then setAccountData(account, "Time played", "0:0:0") end local hours, mins, secs = unpack(split(timePlayed, ":")) local hours = tonumber(hours) local mins = tonumber(mins) local secs = tonumber(secs) if (hours and mins and secs) then local newsec = secs + 1 if (newsec >= 60) then newsec = 0 mins = mins + 1 end if (mins >= 60) then mins = 0 hours = hours + 1 end setAccountData(account, "Time played", tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(newsec)) end end, 1000, 1) function ratioCalculator() local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount(source) local raceLoses = getAccountData(account, "Race Loses") if raceLoses == 0 then setAccountData(account, "Ratio", "-") else local kdr = round(getAccountData(account, "Race Wins") / raceLoses, KDR_DECIMAL_PLACES) setAccountData(account, "Ratio", tostring(kdr)) end end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local raceWins = getAccountData(account,"Race Wins") local raceLoses = getAccountData(account,"Race Loses") local timePlayed = getAccountData(account, "Time played") local ratio = getAccountData(account, "Ratio") if raceWins then setAccountData(account,"Race Wins", tostring(raceWins)) else setAccountData(account,"Race Wins", 0) end if raceLoses then setAccountData(account,"Race Loses", tostring(raceLoses)) else setAccountData(account,"Race Loses", 0) end if timePlayed then setAccountData(account, "Time played", tostring(hours) .. ":" .. tostring(mins) .. ":" .. tostring(newsec)) else setAccountData(account, "Time played", "0:0:0") end if ratio then setAccountData(account,"Ratio", tostring(ratio)) else setAccountData(account,"Ratio", 0) end end) function publicstatsinfo() local account = getPlayerAccount(source) if isGuestAccount(account) then return end local askdname = getPlayerName(source) local wins = getAccountData(account, "Race Wins") local loses = getAccountData(account, "Race Loses") local ratio = getAccountData(account, "Ratio") local timePlayed = getAccountData(account, "Time played") if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " .. timePlayed, getRootElement(), 255, 12, 15, true) else outputChatBox("*You don't losed or won" , getRootElement(), 255, 12, 15, true) end end addEvent("stats", true) addEventHandler("stats", getRootElement(), publicstatsinfo) function checkCommand(message, messageType) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler("onPlayerChat", getRootElement(), checkCommand) Edited January 14, 2012 by Guest Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 SCRIPT ERROR : stats\stats:41: ')' expected <to close '(' at line 19> near 'end' .. But it's aleardy closed.. Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 (edited) try addEventHandler( "onResourceStart",resourceRoot, function( ) exports.scoreboard:addScoreboardColumn( "Race Loses" ) exports.scoreboard:addScoreboardColumn( "Race Wins" ) exports.scoreboard:addScoreboardColumn( "Ratio" ) exports.scoreboard:addScoreboardColumn( "Time played" ) -- add to scoreboard end ) function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local playername local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( account,"Race Wins",tostring( raceWins ) ) setElementData( account,"Race Loses",tostring( raceLoses ) ) setElementData( account,"Ratio",tostring( ratio ) ) end setTimer( function( player ) local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local timePlayed = getAccountData( account, "Time played" ) if not timePlayed then setElementData( player, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) local hours = tonumber( hours ) local mins = tonumber( mins ) local secs = tonumber( secs ) if hours and mins and secs then local newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) end end end ,1000,1, source ) end ) function publicstatsinfo( ) local account = getPlayerAccount( source ) if isGuestAccount( account ) then return end local askdname = getPlayerName( source ) local wins = getAccountData( account, "Race Wins" ) local loses = getAccountData( account, "Race Loses" ) local ratio = getAccountData( account, "Ratio" ) local timePlayed = getAccountData( account, "Time played" ) if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " ..tostring( timePlayed ), root, 255, 12, 15, true) else outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if (messageType == 0) then if (message == "!stats") then cancelEvent() setTimer(triggerEvent, 100, 1, "stats", source) end end end addEventHandler( "onPlayerChat", root, checkCommand ) Edited January 14, 2012 by Guest Link to comment
myonlake Posted January 14, 2012 Share Posted January 14, 2012 Copy my code again, saw something. @All: Why do you all need to reply here with your codes. It's better if you let the first helper help to the end. Not that everybody just strikes in. Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 Copy my code again, saw something. You lol? Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 @myonlake : There are many errors @Kenix : Thanks , no errors , but when i write !stats , at the time played it outputs : nil:nil:nil. Can anyone help? Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 Are you sure data has been set to Time Played. Make sure your logged in. Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 (edited) function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerQuit",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local timePlayed = getElementData( source, "Time played" ) if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) end end ) addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end setTimer( function( player ) local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local timePlayed = getAccountData( account, "Time played" ) if not timePlayed then setElementData( player, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) local hours = tonumber( hours ) or 0 local mins = tonumber( mins ) or 0 local secs = tonumber( secs ) or 0 local newsec if hours and mins and secs then newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) end end end ,1000,1, source ) end ) function publicstatsinfo( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local askdname = getPlayerName( source ) local wins = getAccountData( account, "Race Wins" ) local loses = getAccountData( account, "Race Loses" ) local ratio = getAccountData( account, "Ratio" ) local timePlayed = getAccountData( account, "Time played" ) if loses and wins then outputChatBox("#FFA824*" .. askdname .. " won " .. wins .. " times and he/she lost " .. loses .. " times, his/her ratio is " .. ratio .. " and the total time played he/she is: " ..tostring( timePlayed ), root, 255, 12, 15, true) else outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) end end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then cancelEvent( ) setTimer( triggerEvent, 100, 1, "stats", source ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) Try it. P.S update code Edited January 14, 2012 by Guest Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 There are some errors : WARNING: stats\stats.lua:72: Bad argument @ 'setElementData' [Expected element at argument 1] WARNING: stats\stats.lua:73: Bad argument @ 'setElementData' [Expected element at argument 1] WARNING: stats\stats.lua:74: Bad argument @ 'setElementData' [Expected element at argument 1] Btw , i don't want to add them on scoreboard . Link to comment
GanJaRuleZ Posted January 14, 2012 Author Share Posted January 14, 2012 Ye , there are not any errors , but the time played is still nil:nil:nil Link to comment
Kenix Posted January 14, 2012 Share Posted January 14, 2012 Try function DestructionWin( ) local alivePlayers = getAlivePlayers( ) if #alivePlayers == 1 then local account = getPlayerAccount( alivePlayers[1] ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Wins",tostring( getAccountData( account,"Race Wins" ) or 0 ) +1 ) end local playername = getPlayerName( alivePlayers[1] ) outputChatBox ( "#FFA824The player " .. playername .. " won!", root, 255, 255, 255, true ) end end addEventHandler( "onPlayerWasted", root, function( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end setAccountData( account,"Race Loses",tostring( getAccountData( account,"Race Loses" ) or 0 )+1 ) end end ) function ratioCalculator( player ) local KDR_DECIMAL_PLACES = 2 local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local raceLoses = getAccountData( account,"Race Loses" ) if raceLoses == 0 then setAccountData( account, "Ratio", "-") else local kdr = round( getAccountData( account, "Race Wins" ) / raceLoses, KDR_DECIMAL_PLACES ) setAccountData( account, "Ratio", tostring(kdr)) end end end addEventHandler( "onPlayerQuit",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local timePlayed = getElementData( source, "Time played" ) if not timePlayed then setAccountData( account, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) setAccountData( account, "Time played", tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ) ) end end ) addEventHandler( "onPlayerLogin",root, function ( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local raceWins = getAccountData( account,"Race Wins" ) or 0 local raceLoses = getAccountData( account,"Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 setElementData( source,"Race Wins",tostring( raceWins ) ) setElementData( source,"Race Loses",tostring( raceLoses ) ) setElementData( source,"Ratio",tostring( ratio ) ) end setTimer( function( player ) local account = getPlayerAccount( player ) if account then if isGuestAccount( account ) then return end local timePlayed = getAccountData( account, "Time played" ) if not timePlayed then setElementData( player, "Time played","0:0:0" ) end local hours, mins, secs = unpack( split( timePlayed, ":" ) ) local hours = tonumber( hours ) or 0 local mins = tonumber( mins ) or 0 local secs = tonumber( secs ) or 0 local newsec if hours and mins and secs then newsec = secs + 1 if ( newsec >= 60 ) then newsec = 0 mins = mins + 1 end if ( mins >= 60 ) then mins = 0 hours = hours + 1 end setElementData ( player, "Time played", tostring( hours ) ..":".. tostring( mins ) ..":".. tostring( newsec ) ) end end end ,1000,1, source ) end ) function publicstatsinfo( ) local account = getPlayerAccount( source ) if account then if isGuestAccount( account ) then return end local askdname = getPlayerName( source ) local wins = getAccountData( account, "Race Wins" ) or 0 local loses = getAccountData( account, "Race Loses" ) or 0 local ratio = getAccountData( account, "Ratio" ) or 0 local timePlayed = getAccountData( account, "Time played" ) local hours, mins, secs = unpack( split( timePlayed, ":" ) ) if loses and wins then outputChatBox("#FFA824*" .. tostring( askdname ) .. " won " .. tostring( wins ) .. " times and he/she lost " ..tostring( loses ).. " times, his/her ratio is " .. tostring( ratio ) .. " and the total time played he/she is: " .. tostring( hours or 0 ) ..":".. tostring( mins or 0 ) ..":".. tostring( secs or 0 ), root, 255, 12, 15, true) else outputChatBox("*You don't losed or won" , root, 255, 12, 15, true) end end end addEvent( "stats", true ) addEventHandler( "stats", root, publicstatsinfo ) function checkCommand( message, messageType ) if messageType == 0 then if message == "!stats" then cancelEvent( ) triggerEvent( "stats", source ) end end end addEventHandler( "onPlayerChat", root, checkCommand ) 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