VTX Posted February 27, 2014 Share Posted February 27, 2014 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
PaiN^ Posted February 27, 2014 Share Posted February 27, 2014 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
VTX Posted February 27, 2014 Author Share Posted February 27, 2014 It doesn't do anything. Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 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
VTX Posted February 27, 2014 Author Share Posted February 27, 2014 Still counts it more times. Link to comment
WhoAmI Posted February 27, 2014 Share Posted February 27, 2014 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
VTX Posted February 27, 2014 Author Share Posted February 27, 2014 This works perfectly, thanks. Link to comment
WhoAmI Posted February 27, 2014 Share Posted February 27, 2014 Just Citizen forgot about setting data, when someone reached hunter, thanks to him! Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 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
VTX Posted February 27, 2014 Author Share Posted February 27, 2014 Yea, I saw that is pretty similar, and I realized that just one line was added. Thanks to both of you then. Link to comment
Moderators Citizen Posted February 27, 2014 Moderators Share Posted February 27, 2014 You're welcome 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