Jump to content

Money for reached hunter (without repetition!)


VTX

Recommended Posts

Hey guys!

I thought it's a common problem, so I searched for it, but didn't find the answer.

So here's the script:

function someoneReachedHunter(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        outputChatBox ( getPlayerName(source).." #3366FFhas taken the hunter and gets #B30000$500!", getRootElement(), 255, 255, 255, true ) 
        givePlayerMoney ( source , 500 ) 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 
  
  
function checkHunter(number,sort,model) 
    if sort == "vehiclechange" then 
        if model == 425 then        
            removeEventHandler("onPlayerPickUpRacePickup", getRootElement(), someoneReachedHunter) 
        end 
    end 
end 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),checkHunter) 

The problem is, when there are more hunter pickups than one in the end of a map, it gives the $500 (and writes the message) as many as I hit an other pickup. So how can I set it to give the money for the first time when the hunter was reached, and disable it when the player hit the pickup again?

As you see I tried it with removeEventHandler, but that's worked for only one time, then it disabled the someoneReachedHunter function. Yes, that's obvious...but I don't know how to enable again when a next map starts. But there's probably an easier way.

Link to comment

Try this :

function someoneReachedHunter(number, sort, model) 
    if sort == "vehiclechange" and model == 425 then 
        if getElementModel( getPedOccupiedVehicle( source ) ) ~= 425 then  
            outputChatBox ( getPlayerName(source).." #3366FFhas taken the hunter and gets #B30000$500!", getRootElement(), 255, 255, 255, true ) 
            givePlayerMoney ( source , 500 ) 
        end 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),someoneReachedHunter) 

Link to comment
  • Moderators

Maybe this ?

function someoneReachedHunter(number, sort, model) 
    -- get the element data gotHunter to check if he already got it once 
    local alreadyGotHunter = getElementData(source, "gotHunter") 
    if sort == "vehiclechange" and model == 425 and not alreadyGotHunter then 
        outputChatBox ( getPlayerName(source).." #3366FFhas taken the hunter and gets #B30000$500!", getRootElement(), 255, 255, 255, true ) 
        givePlayerMoney ( source, 500 ) 
        --set the element data gotHunter to true to know he got it for the 1st time on this map 
    end 
end 
addEvent("onPlayerPickUpRacePickup",true) 
addEventHandler("onPlayerPickUpRacePickup", root, someoneReachedHunter) 
  
-- reset gotHunter element data for everyone when the new map is starting 
addEvent("onMapStarting", true) 
function resetHunterStatus() 
    for k, player in ipairs(getElementsByType("player")) do 
        setElementData(player, "gotHunter", false) 
    end 
end 
addEventHandler("onMapStarting", root, resetHunterStatus) 

Link to comment
    function someoneReachedHunter(number, sort, model) 
        -- get the element data gotHunter to check if he already got it once 
        local alreadyGotHunter = getElementData(source, "gotHunter") 
        if sort == "vehiclechange" and model == 425 and not alreadyGotHunter then 
            outputChatBox ( getPlayerName(source).." #3366FFhas taken the hunter and gets #B30000$500!", getRootElement(), 255, 255, 255, true ) 
            givePlayerMoney ( source, 500 ) 
            setElementData(source, "gotHunter", true) 
            --set the element data gotHunter to true to know he got it for the 1st time on this map 
        end 
    end 
    addEvent("onPlayerPickUpRacePickup",true) 
    addEventHandler("onPlayerPickUpRacePickup", root, someoneReachedHunter) 
      
    -- reset gotHunter element data for everyone when the new map is starting 
    addEvent("onMapStarting", true) 
    function resetHunterStatus() 
        for k, player in ipairs(getElementsByType("player")) do 
            setElementData(player, "gotHunter", false) 
        end 
    end 
    addEventHandler("onMapStarting", root, resetHunterStatus) 

Try this out.

Link to comment
  • Moderators

Haha yeah I was like "WTF" when he said it didn't work, I immediatly checked what I posted and I don't know why the setElementData disapeared (because I added the comments after I did the code ...).

So yeah, just a fail in my copy paste from my ide.

Thanks WhoAmI :)

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