Wei Posted April 8, 2012 Posted April 8, 2012 i'm asking again for resource that detects how much time did you play on server. I was looking at he search line but i only find season time online. Please help Diet with russian vodka, lose 3 days in one week !
Guest Guest4401 Posted April 8, 2012 Posted April 8, 2012 https://wiki.multitheftauto.com/wiki/onPlayerJoin -- start tick count when a player joins https://wiki.multitheftauto.com/wiki/onPlayerQuit -- end tick count when he quits getTickCount -- use this to calculate how much time he spent.(it's in milliseconds) Don't forget to save data in mySQL, accountData, XML or wherever you wish to save.
drk Posted April 8, 2012 Posted April 8, 2012 Don't forget that you need to convert getTickCount time to HOUR:MINUTE:SECONDS. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Wei Posted April 9, 2012 Author Posted April 9, 2012 Ok here is my script but it is ticking on season but when player login doesn't get the time back My Script: (PS. It's my first time working with saving) function onResourceStart() call(getResourceFromName("scoreboard"), "addScoreboardColumn", "Online Time") end addEventHandler("onResourceStart",resourceRoot,onResourceStart) function joinTime() setElementData (source, "joinTime", getTickCount() ) setElementData (source, "Online Time", "0 :, 0 :, 0 " ) end addEventHandler ( "onPlayerJoin", root, joinTime ) function all() for index , player in ipairs ( getElementsByType ( "player" ) ) do local s = getElementData(player,"joinTime") or getTickCount() s = (getTickCount() - s) / 1000 local string = string.format("%02d : %02d : %02d ", s/3600, s%3600/60, s%60) setElementData(player,"Online Time",string) end end setTimer(all,1000,0) function fSaveManager ( ) getElementData(player,"Online Time",string) end addEventHandler ( 'onPlayerLogin', root, fSaveManager ) Diet with russian vodka, lose 3 days in one week !
Smart. Posted April 9, 2012 Posted April 9, 2012 (edited) @blazy, glad I could help. @DrakeN, it works perfectly, maybe YOU should learn lua? Edited April 9, 2012 by Guest lol
drk Posted April 9, 2012 Posted April 9, 2012 What is that? LOL if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end You should learn Lua. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Wei Posted April 9, 2012 Author Posted April 9, 2012 I don't care what's that. It works perfectly for me !!!! Thanks Seb! Diet with russian vodka, lose 3 days in one week !
drk Posted April 9, 2012 Posted April 9, 2012 @blazy, glad I could help. @DrakeN, it works perfectly, maybe YOU should learn lua? Hum, then why you removed the code? To no one see your shitty code? Your code is completely wrong. local time = setTimer ( updatePlayerOnlineTime, 60000, 1 ) setAccountData ( pAccount, 'onlineTime.minutes', time ) LOOOOOL You make me laugh dude. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Wei Posted April 9, 2012 Author Posted April 9, 2012 Can Mod / Admin please lock this topic ? It makes me crazy when this Darken is typing funny things. Can't you read ? THIS SCRIPT IS WORKING PERFECTLY!! AND THANKS TO SEB !! And I wanna see your server if it's better than sebs one wich is still in development!! Diet with russian vodka, lose 3 days in one week !
drk Posted April 9, 2012 Posted April 9, 2012 Haha don't make me laugh dude, you don't know a fuck about Lua. Can Mod / Admin please lock this topic ? It makes me crazy when this Darken is typing funny things. Can't you read ? THIS SCRIPT IS WORKING PERFECTLY!! AND THANKS TO SEB !! And I wanna see your server if it's better than sebs one wich is still in development!! His server will be a shit like his script. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Wei Posted April 9, 2012 Author Posted April 9, 2012 Haha don't make me laugh dude, you don't know a about Lua. I don't know a shit of Lua and you don't know a shit of helping people ( I would be ashamed if I had 1400 post and all post without help.)I'm sure that in 1400 posts you didn't help eaven 2 people! If I would have that much post I would be a better Than you in helping and stuff like that! Diet with russian vodka, lose 3 days in one week !
drk Posted April 9, 2012 Posted April 9, 2012 Go go go ! Dude, don't try to be good. You know, this code sucks, will never work. And you're a dumbass that trys to be better than others. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Mefisto_PL Posted April 9, 2012 Posted April 9, 2012 Server: addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Online" ) addEventHandler ( "onResourceStart" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( player , "Online" , "00 H 00 M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end else setElementData ( player , "Online" , "N/A" ) end end end ) addEventHandler ( "onResourceStop" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( player , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end end ) addEventHandler ( "onPlayerLogin" , root , function ( _ , pAccount ) local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( source , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( source , "Online" , "00 H 00 M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) end end ) addEventHandler ( "onPlayerLogout" , root , function ( pAccount ) local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end ) addEventHandler ( "onPlayerJoin" , root , function ( ) setElementData ( source , "Online" , "N/A" ) end ) addEventHandler ( "onPlayerQuit" , root , function ( ) local pAccount = getPlayerAccount ( source ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end ) function updatePlayerOnline ( player ) local pAccount = getPlayerAccount ( player ) local minutes = getAccountData ( pAccount , "Online.minutes" ) local hours = getAccountData ( pAccount , "Online.hours" ) minutes = tostring ( tonumber ( minutes ) + 1 ) if minutes == "60" then hours = tostring ( tonumber ( hours ) + 1 ) minutes = "00" end setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end It's Working in 100%. I was having this same problem
drk Posted April 9, 2012 Posted April 9, 2012 Server: addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), call ( getResourceFromName ( "scoreboard" ), "scoreboardAddColumn", "Online" ) addEventHandler ( "onResourceStart" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( player , "Online" , "00 H 00 M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end else setElementData ( player , "Online" , "N/A" ) end end end ) addEventHandler ( "onResourceStop" , resourceRoot , function ( ) for index , player in ipairs ( getElementsByType ( "player" ) ) do local pAccount = getPlayerAccount ( player ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( player , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end end ) addEventHandler ( "onPlayerLogin" , root , function ( _ , pAccount ) local minutes = getAccountData ( pAccount , "Online.minutes" ) if minutes then local hours = getAccountData ( pAccount , "Online.hours" ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( source , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) else setAccountData ( pAccount , "Online.minutes" , 0 ) setAccountData ( pAccount , "Online.hours" , 0 ) setElementData ( source , "Online" , "00 H 00 M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , source ) setElementData ( source , "Online.timer" , timer ) end end ) addEventHandler ( "onPlayerLogout" , root , function ( pAccount ) local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end ) addEventHandler ( "onPlayerJoin" , root , function ( ) setElementData ( source , "Online" , "N/A" ) end ) addEventHandler ( "onPlayerQuit" , root , function ( ) local pAccount = getPlayerAccount ( source ) if not isGuestAccount ( pAccount ) then local timer = getElementData ( source , "Online.timer" ) if isTimer ( timer ) then killTimer ( timer ) end end end ) function updatePlayerOnline ( player ) local pAccount = getPlayerAccount ( player ) local minutes = getAccountData ( pAccount , "Online.minutes" ) local hours = getAccountData ( pAccount , "Online.hours" ) minutes = tostring ( tonumber ( minutes ) + 1 ) if minutes == "60" then hours = tostring ( tonumber ( hours ) + 1 ) minutes = "00" end setAccountData ( pAccount , "Online.minutes" , tonumber ( minutes ) ) setAccountData ( pAccount , "Online.hours" , tonumber ( hours ) ) if # tostring ( minutes ) == 1 then minutes = "0" .. minutes end if # tostring ( hours ) == 1 then hours = "0" .. hours end setElementData ( player , "Online" , hours .. " H " .. minutes .. " M" ) local timer = setTimer ( updatePlayerOnline , 60000 , 1 , player ) setElementData ( player , "Online.timer" , timer ) end It's Working in 100%. I was having this same problem * BABY FACEPALM * This is wrong. Also why 2 onResourceStart handlers? EPT Team Server Development: 0% Learning C++ | C++ is amazing
Wei Posted April 9, 2012 Author Posted April 9, 2012 Go go go !Dude, don't try to be good. You know, this code sucks, will never work. And you're a dumbass that trys to be better than others. Test the script then comment ! You didn't eaven test it ! Cuz it works perfectly! @Mefisto_PL I have it allready. Thanks anyway! Diet with russian vodka, lose 3 days in one week !
drk Posted April 9, 2012 Posted April 9, 2012 Go go go !Dude, don't try to be good. You know, this code sucks, will never work. And you're a dumbass that trys to be better than others. Test the script then comment ! You didn't eaven test it ! Cuz it works perfectly! @Mefisto_PL I have it allready. Thanks anyway! I'll test only if you want my pc to blow with these amount of errors. EPT Team Server Development: 0% Learning C++ | C++ is amazing
Cadu12 Posted April 9, 2012 Posted April 9, 2012 setAccountData with setTimer? Not good idea. Ingame nick: Cadu12
Castillo Posted April 9, 2012 Posted April 9, 2012 @DrakeN: Stop acting like a kid, we're here to help, not to insult someone because he doesn't know how to script. Topic locked. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Recommended Posts