Jump to content

zombiekills and hours played in scoreboard


Recommended Posts

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
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 :D, but where do i have to copy this ?

Link to comment
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 :P.

@zombienation: That script will save the zombie kills each time you kill somene, and then load on login.

Link to comment
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 :P i created a lua file :P forry for being so slow :D it works idd btw thx man !

do you also know how i can fix hours played?

Link to comment
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

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
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
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 :D

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
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
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

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
  
  
  
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

@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

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
  
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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...