Jump to content

Updates everytime


Newbie

Recommended Posts

function someoneReachedHunter(number, sort, model) 
    for index, account in ipairs ( getAccounts (        ) ) do 
        if getAccountPlayer ( account ) then 
            if sort == "vehiclechange" and model == 425 then 
            outputChatBox (" hunter! Run!", getRootElement(), 255, 255, 255, true ) 
            setAccountData( account,"Hunters",tostring( getAccountData( account,"Hunters" ) or 0 )+1 ) 
            end 
        end 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 

When i take hunter in race maps it spams and set account data many times bcs of pickups refresh.

How to make that every player can take hunter only once in map and if takes more times it wont counts.

Link to comment

Why are you looping through a table everytime a player reaches a pickup? That's highly inefficient.

I would do it like this.

  
local hunter_reach = function() 
    if getElementData(source,"hunter.reach") then 
        return 
    else 
        outputChatBox("Someone reached hunter!",root,255,255,255,true) 
        setElementData(source,"hunter.reach",true) 
        if getAccountPlayer(source) then 
            setAccountData(source,"Hunters",getAccountData(source,"Hunters",getAccountData(source,"Hunters")+1) 
        end 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",--[[your pickup element here (there is no need to attach it to the root element as it will decrease performance)]],hunter_reach) 
  

This also fixes the problem you mentioned above.

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