zombienation Posted January 8, 2012 Share Posted January 8, 2012 Hello, I would like to know how to add the zombiekills and hours played into the scoreboard and save system? Can anybody help me please? Thanks Link to comment
Castillo Posted January 8, 2012 Share Posted January 8, 2012 The "zombies" by Slothman already has a "Zombie kills" scoreboard column. Link to comment
Xeno Posted January 8, 2012 Share Posted January 8, 2012 If you cant find it, then here, I think this works, (And I think its Slothmans) exports.scoreboard:addScoreboardColumn('Zombie kills') addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) givePlayerMoney(killer,100) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if not zombieKills then setAccountData(account,"Zombie kills",0) end setAccountData(account,"Zombie kills",tonumber(zombieKills)+1) end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if zombieKills then setElementData(source,"Zombie kills",tostring(zombieKills)) else setElementData(source,"Zombie kills",0) end end) Link to comment
zombienation Posted January 8, 2012 Author Share Posted January 8, 2012 The "zombies" by Slothman already has a "Zombie kills" scoreboard column. you mean the zombies script or the gamemode? If you cant find it, then here, I think this works, (And I think its Slothmans) exports.scoreboard:addScoreboardColumn('Zombie kills') addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) givePlayerMoney(killer,100) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if not zombieKills then setAccountData(account,"Zombie kills",0) end setAccountData(account,"Zombie kills",tonumber(zombieKills)+1) end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if zombieKills then setElementData(source,"Zombie kills",tostring(zombieKills)) else setElementData(source,"Zombie kills",0) end end) hmm thanks , but where do i have to copy this ? Link to comment
Castillo Posted January 8, 2012 Share Posted January 8, 2012 If you cant find it, then here, I think this works, (And I think its Slothmans) exports.scoreboard:addScoreboardColumn('Zombie kills') addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) givePlayerMoney(killer,100) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if not zombieKills then setAccountData(account,"Zombie kills",0) end setAccountData(account,"Zombie kills",tonumber(zombieKills)+1) end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if zombieKills then setElementData(source,"Zombie kills",tostring(zombieKills)) else setElementData(source,"Zombie kills",0) end end) @Xeno: You got that from here: viewtopic.php?f=91&t=35621&p=368094 . @zombienation: That script will save the zombie kills each time you kill somene, and then load on login. Link to comment
zombienation Posted January 8, 2012 Author Share Posted January 8, 2012 If you cant find it, then here, I think this works, (And I think its Slothmans) exports.scoreboard:addScoreboardColumn('Zombie kills') addEvent("onZombieWasted",true) addEventHandler("onZombieWasted",root, function (killer) givePlayerMoney(killer,100) addPlayerZombieKills(killer) end) function addPlayerZombieKills(killer) local account = getPlayerAccount(killer) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if not zombieKills then setAccountData(account,"Zombie kills",0) end setAccountData(account,"Zombie kills",tonumber(zombieKills)+1) end addEventHandler("onPlayerLogin",root, function () local account = getPlayerAccount(source) if isGuestAccount(account) then return end local zombieKills = getAccountData(account,"Zombie kills") if zombieKills then setElementData(source,"Zombie kills",tostring(zombieKills)) else setElementData(source,"Zombie kills",0) end end) ah about my last question never mind i created a lua file forry for being so slow it works idd btw thx man ! do you also know how i can fix hours played? Link to comment
Xeno Posted January 8, 2012 Share Posted January 8, 2012 No, I do not know how to record time. But search around the forums (as I did with the zombie saving) and you may find it. Link to comment
zombienation Posted January 8, 2012 Author Share Posted January 8, 2012 No, I do not know how to record time. But search around the forums (as I did with the zombie saving) and you may find it. i also did for the zombiekills but i didn't opened the whole list i found, maybe 10 topics, but your reply here was the clearest actually but i'll search deeper for the time, thx Link to comment
Xeno Posted January 8, 2012 Share Posted January 8, 2012 It wasn't really my script, Castillo made it, I just copied it from another topic. Anyway - Ill search for a topic for you. Link to comment
Al3grab Posted January 9, 2012 Share Posted January 9, 2012 recording time is easy , like this : exports.scoreboard:addScoreboardColumn('Time') addEventHandler("onPlayerJoin",root,function() setElementData(source,"totalTime",0) setTimer ( function ( source ) local totalTime = getElementData(source,"totalTime") setElementData(source,"totalTime",totalTime+1) setElementData(source,"Time",math.floor(tonumber(totalTime)/60).." Mins") end , 1000 , 0 , source ) end ) don't forget to reconnect while testing the code =D Link to comment
zombienation Posted January 9, 2012 Author Share Posted January 9, 2012 recording time is easy , like this : exports.scoreboard:addScoreboardColumn('Time') addEventHandler("onPlayerJoin",root,function() setElementData(source,"totalTime",0) setTimer ( function ( source ) local totalTime = getElementData(source,"totalTime") setElementData(source,"totalTime",totalTime+1) setElementData(source,"Time",math.floor(tonumber(totalTime)/60).." Mins") end , 1000 , 0 , source ) end ) don't forget to reconnect while testing the code =D thanks for sharing man this works u just tried it Link to comment
zombienation Posted January 9, 2012 Author Share Posted January 9, 2012 recording time is easy , like this : exports.scoreboard:addScoreboardColumn('Time') addEventHandler("onPlayerJoin",root,function() setElementData(source,"totalTime",0) setTimer ( function ( source ) local totalTime = getElementData(source,"totalTime") setElementData(source,"totalTime",totalTime+1) setElementData(source,"Time",math.floor(tonumber(totalTime)/60).." Mins") end , 1000 , 0 , source ) end ) don't forget to reconnect while testing the code =D hey, when i log off the server or reconnect i get a warning and an error and they repeat themself without ending warning = bad argument @ getelementdata expected element at argument 1 error = attempt to perform arithemetic on local 'totaltime' ( a boolean value ) i added the script you gave me in a new lua file, i saved it in a meta file on server side ( same meta where other scoreboard scripts are in ) also that foldername is in the acl with admin group did i did something wrong or do you know what brings the warning and error? time saving works after reconnecting u can see it was saved, but the warning and errors keeps repeating lol Link to comment
Castillo Posted January 9, 2012 Share Posted January 9, 2012 exports.scoreboard:addScoreboardColumn('Time') function updateTimePlayed() setTimer(updateTimePlayed,1000,1) for index, player in ipairs(getElementsByType("player")) do setElementData(player,"totalTime",0) local totalTime = getElementData(player,"totalTime") setElementData(player,"totalTime",totalTime+1) setElementData(player,"Time",math.floor(tonumber(totalTime)/60).." Mins") end end setTimer(updateTimePlayed,1000,1) Link to comment
zombienation Posted January 9, 2012 Author Share Posted January 9, 2012 exports.scoreboard:addScoreboardColumn('Time') function updateTimePlayed() setTimer(updateTimePlayed,1000,1) for index, player in ipairs(getElementsByType("player")) do setElementData(player,"totalTime",0) local totalTime = getElementData(player,"totalTime") setElementData(player,"totalTime",totalTime+1) setElementData(player,"Time",math.floor(tonumber(totalTime)/60).." Mins") end end setTimer(updateTimePlayed,1000,1) thx solid this solves the error and warnings, but is it possible that it stays on 0 minutes in scoreboard? i added it and restarted the server, i connected, and i reconnected just to be sure, and after login i went outside to smoke, but when i came back inside it was still on 0 minutes.. Link to comment
Klesh Posted January 10, 2012 Share Posted January 10, 2012 You must to do a simple system script, maybe you can do one by: setElementData("time.data", timeHandler) ---Example code getElementData("time.data", timeHandler) ---You can use this too: setElementData("time.data", toJSON({.....}))--You must addEventHanderl("onPlayerLogin or playerQuit Link to comment
Al3grab Posted January 10, 2012 Share Posted January 10, 2012 exports.scoreboard:addScoreboardColumn('Time') addEventHandler("onPlayerJoin",root, function() setElementData(source,"totalTime",0) checkTimer = setTimer ( function ( source ) if isElement(source) then local totalTime = getElementData(source,"totalTime") setElementData(source,"totalTime",totalTime+1) setElementData(source,"Time",math.floor(tonumber(totalTime)/60).." Mins") end end , 1000 , 0 , source ) end ) addEventHandler("onPlayerQuit",root,function() if isTimer(checkTimer) then killTimer(checkTimer) end end ) this should solve the warnings Link to comment
Castillo Posted January 10, 2012 Share Posted January 10, 2012 @Al3grab: First, that timer is not required, the server will still run one timer for each player, it would be the same to be just one timer for every single player at once. Second, your script is creating one "checkTimer" each time someone joins, but not storing it on a table, so it'll never work, because it's replacing the variable every time. Link to comment
Al3grab Posted January 10, 2012 Share Posted January 10, 2012 ok thx , in your code you made it set the player total time to 0 every time , this will work : exports.scoreboard:addScoreboardColumn('Time') function updateTimePlayed() setTimer(updateTimePlayed,1000,1) for index, player in ipairs(getElementsByType("player")) do local totalTime = getElementData(player,"totalTime") if not totalTime then setElementData(player,"totalTime",0) end setElementData(player,"totalTime",totalTime+1) setElementData(player,"Time",math.floor(tonumber(totalTime)/60).." Mins") end end setTimer(updateTimePlayed,1000,1) Link to comment
Kenix Posted January 10, 2012 Share Posted January 10, 2012 exports.scoreboard:addScoreboardColumn( 'Time' ) setTimer( function( ) for _, v in pairs( getElementsByType( "player" ) ) do local totalTime = getElementData( v,"totalTime" ) or 0 setElementData( v,"totalTime",totalTime+1 ) setElementData( v,"Time",math.floor( tonumber( totalTime )/60 ).." Mins" ) end end, 1000, 0 ) Why you need variable index you can use _ ( freeze variable ) in loop. And second remember operator or is very useful. Link to comment
zombienation Posted January 10, 2012 Author Share Posted January 10, 2012 Thx guys for all the help with this. The last script thats posted here is without errors but it dont save the time when reconnect. With the script before the last one thats posted, i believe it saves the time but still one error. Same as before, different linenumber And also this error dont repeats but just shows in console when connecting or leqving. I have the resource in my acl in resources group Link to comment
Castillo Posted January 10, 2012 Share Posted January 10, 2012 Because that's saving in element data, when the player leaves, the time will be lost, you must use account data/sqlite/mysql/xml to save the data after quit. Link to comment
zombienation Posted January 10, 2012 Author Share Posted January 10, 2012 Ah so in my case thats normal. Then i need to download mysql first right? Link to comment
Castillo Posted January 10, 2012 Share Posted January 10, 2012 As you're newbie, I suggest you to use ACCOUNT DATA. https://wiki.multitheftauto.com/wiki/Ser ... _functions Link to comment
zombienation Posted January 10, 2012 Author Share Posted January 10, 2012 Alright thx solidsnake 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