Jump to content

Timer


buba123

Recommended Posts

Hi i have code what show in scoreboard how many zombies you have killed and save it to account file

but in scoreboard zombie kills is only update when you relogin it doesnt in game when you kill,

i add timer but it still doesnt work what is wrong here?

exports.scoreboard:addScoreboardColumn('Zabite Zombie') 
  
addEvent("onZombieWasted",true) 
addEventHandler("onZombieWasted",root, 
function (killer) 
    givePlayerMoney(killer, 2) 
    addPlayerZombieKills(killer) 
  
end) 
  
  
function addPlayerZombieKills(killer) 
    local account = getPlayerAccount(killer) 
    if isGuestAccount(account) then return end 
    local zombieKills = getAccountData(account,"Zabite Zombie") 
    if not zombieKills then setAccountData(account,"Zabite Zombie",0) end 
    setAccountData(account,"Zabite Zombie",tonumber(zombieKills)+1) 
end 
  
  
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
    if isGuestAccount(account) then return end 
    local zombieKills = getAccountData(account,"Zabite Zombie") 
    if zombieKills then 
        setElementData(source,"Zabite Zombie",tostring(zombieKills)) 
    else 
        setElementData(source,"Zabite Zombie",0)     
  
end 
end) 
  
function timer() 
    setTimer( addPlayerZombieKills, 1000, 1, source ) 
end 

Link to comment

First thing you need to have dxscoreboard resource. Then you have to add somewhere in your script a function named "scoreboardAddColumn". Having passed required arguments through that function you can display your kills in scoreboard. But keep in mind that you have to set element data in order it to work.

Link to comment

i have colum in scoreboard what show how many zombie you kill but

if you join server first time you have 0 zombie kill then you kill some zombies

but in scoreboard it show 0. you are doing relogin and now it show how many zombie you kill

to that time when you relogin.

i want to update that zombie kills ingame without player must relogin to see it

Link to comment

i make somethnk like this

 function updatePlayersZKILLS ( )  
        for index, player in ipairs ( getElementsByType "player" ) do  
            setElementData ( player, "Zabite Zombie", tonumber(zombieKills)+1 )  
        end  
    end  
    setTimer ( updatePlayersZKILLS, 1000, 0 )  

but in console it write i cant arthmetic to nill... what is wrong?

Link to comment

You chose a bad way to update the scoreboard. Instead of checking every player on the server every second you should make it like this:

function ZombieDies(ammo,killer) 
local zombieKills = getElementData(killer,"Zabite Zombie") 
setElementData(killer,"Zabite Zombie",zombieKills+1) 
end 
addEventHandler("onPedWasted", getRootElement(), ZombieDies) -- I'm not sure how you made your zombies but I guess they're peds anyway... 

Link to comment

it work thank ; ) but for one kill zombie i get warrning and error

warning:bad argument @ 'getelementdata' [expected element at argument 1, got boolean]

this line

local zombieKills = getElementData(killer,"Zabite Zombie") 

and error:attempt to perform arithmetic on local 'zombieKills'

this line

setElementData(killer,"Zabite Zombie",(zombieKills)+1) 

Link to comment

It should help:

function ZombieDies(ammo,killer) 
if (killer) then 
local zombieKills = getElementData(killer,"Zabite Zombie") 
setElementData(killer,"Zabite Zombie",zombieKills+1) 
end 
end 
addEventHandler("onPedWasted", getRootElement(), ZombieDies) 

Link to comment

i find now weapons but it dont save couse have erros.

  function table.empty( t ) 
        if type( t ) ~= "table" then 
            return false 
        end 
        
        return not next( t ) 
    end 
      
    addEventHandler( "onPlayerLogin",root, 
        function( ) 
            local acc = getPlayerAccount( source ) 
            if acc then 
                local weap = getAccountData( acc,'weapons' ) 
                if weap then 
                    loadstring( 
                        "t = { "..weap.." } ".. 
                        "for _,v in pairs( t ) do ".. 
                            "giveWeapon( "..source..",v[1],v[2],false ) ".. 
                        "end" 
                    )( ) 
                end 
            end 
        end 
    ) 
      
    addEventHandler( "onPlayerQuit",root, 
        function( ) 
            local acc = getPlayerAccount( source ) 
            if acc and not isGuestAccount( acc ) then 
                if not table.empty( tWeap[ source ] ) then 
                    local eStr = "" 
                    for _,v in pairs( tWeap[ source ] ) do 
                        eStr = eStr.."{"..v[1]..","..v[2].."}," 
                    end 
                    setAccountData( acc,"weapons",eStr:sub( 0,#eStr-1 ) ) 
                end 
            end  
        end 
    )    

?

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