Blueman Posted March 1, 2015 Share Posted March 1, 2015 It seems the givePlayerMoney is not behaving as it should in this case. I get output into the chatbox but I receive no money. local hasBeenCollected local theDrug local locx,locy,locz={-2923.1591},{1165.1446},{13.5312} function pickedUpDrug(pickup,dimension) if(getElementData(theDrug, "rpg.drug") == "a") then local dbgmny = setPlayerMoney(source, 20000) if(dbgmny == false) then outputChatBox("Error money", getRootElement(), 0, 0, 255, true) end outputChatBox ( getPlayerName(source).." has collected the drug package", getRootElement(), 0, 0, 255, true ) end end function setupDrugRun() hasBeenCollected=false local location=math.random(1) theDrug = createPickup ( locx[location], locy[location], locz[location], 3, 1279) setElementData(theDrug, "rpg.drug", "a") outputChatBox ( "A new drug package is available for pick up", getRootElement(), 0, 0, 255, true ) end addEventHandler("onResourceStart", resourceRoot, setupDrugRun) addEventHandler("onPlayerPickupUse",root,pickedUpDrug) Please mind the messy code, also I should note that I used setElementData because when I called addEventHandler("onPickupUse", theDrug, pickedUpDrug) I would get no output at all. Link to comment
LaCosTa Posted March 1, 2015 Share Posted March 1, 2015 You just made setElementMoney(source , 20000) -- there is nothing called setElementMoney. So it should be like this local money = getPlayerMoney(source) setPlayerMoney(source , money + 20000) I'm on phone I'll see the rest of the code later . Link to comment
Noki Posted March 1, 2015 Share Posted March 1, 2015 Alternatively, you can use givePlayerMoney. Link to comment
Blueman Posted March 1, 2015 Author Share Posted March 1, 2015 My issue is using givePlayerMoney just does nothing with no errors and no feedback at all. LaCosta's suggestion worked fine though. Link to comment
LaCosTa Posted March 1, 2015 Share Posted March 1, 2015 Then what is the other problem cuz your code is messy and i didn't know what are you trying to do Link to comment
Walid Posted March 1, 2015 Share Posted March 1, 2015 Why there is nothing called setElementMoney() it can be like this. function setElementMoney(player, amount) if (not isElement(player)) then return end givePlayerMoney(player, amount) end Link to comment
Blueman Posted March 1, 2015 Author Share Posted March 1, 2015 I never called setElementMoney in my code.. I called setPlayerMoney because when I called givePlayerMoney(source, 1000) it would do nothing... Cleaned up the code and added some comments. This is a bit different than the original since i've been working on it but it does not seem to be destroy the map blip local hasBeenCollected=true local theDrug local locx,locy,locz,hint={-2923.1591, -1126.8721}, {1165.1446, 834.1354}, {13.5312, 3.0777}, {"The back yards of san fiero", "A oceanic rock next to a bridge support"} --An array with drug package locations and hints function pickedUpDrug(pickup,dimension) -- Called when something is picked up. if(getElementData(pickup, "rpg.drug") == "a") then local earnings=math.random(2000)--Generate random earnings from 1 to 2000 local money = getPlayerMoney(source) setPlayerMoney(source , money + earnings)--Give player money does nothing where as this seems to work fine. hasBeenCollected = true --Tell setupDrugRun we've collected it destroyElement(getElementAttachedTo(pickup))--Destroy the pickups blip(does not seem to work) destroyElement(pickup)--Make sure we destroy our pickup outputChatBox ( getPlayerName(source).." has collected the drug package for $"..earnings, getRootElement(), 0, 0, 255, true )--Tell everyone about it elseif(getElementData(pickup, "rpg.money") == "mons") then --This can be ignored it has nothing to do with the drug run local money = getPlayerMoney(source) setPlayerMoney(source , money + 100) destroyElement(pickup) end end function setupDrugRun() if(hasBeenCollected == true) then --Has our drug package been collected hasBeenCollected=false --If so reset it local location=math.random(2) --Choose a random location from the array theDrug = createPickup ( locx[location], locy[location], locz[location], 3, 1279) --Possibly not passing the element to theDrug createBlipAttachedTo ( theDrug, 36) setElementData(theDrug, "rpg.drug", "a")--We cannot pass theDrug to addEventHandler as element(Perhaps a bug or user error) outputChatBox ( "A new drug package is available for pick up", getRootElement(), 0, 0, 255, true )--Tell everyone about it. end end function startDrugRun() --Sets up the timer for the drug run this can be ignored setTimer(setupDrugRun, 1000, 0) end addEventHandler("onResourceStart", resourceRoot, startDrugRun)--Starts up the timer on resource start. addEventHandler("onPlayerPickupUse",root,pickedUpDrug) --Replacing root with theDrug results in nothing Link to comment
roaddog Posted March 1, 2015 Share Posted March 1, 2015 You can define the blip using variable and then check if it exists, destroyElement() local hasBeenCollected=true local theDrug local locx,locy,locz,hint={-2923.1591, -1126.8721}, {1165.1446, 834.1354}, {13.5312, 3.0777}, {"The back yards of san fiero", "A oceanic rock next to a bridge support"} --An array with drug package locations and hints function pickedUpDrug(pickup,dimension) -- Called when something is picked up. if(getElementData(pickup, "rpg.drug") == "a") then local earnings=math.random(2000)--Generate random earnings from 1 to 2000 local money = getPlayerMoney(source) setPlayerMoney(source , money + earnings)--Give player money does nothing where as this seems to work fine. hasBeenCollected = true --Tell setupDrugRun we've collected it destroyElement( pickup )--Make sure we destroy our pickup if isElement(drugBlip) then --Check if it exists destroyElement(drugBlip)-- we destroy our "drugBlip" end outputChatBox ( getPlayerName(source).." has collected the drug package for $"..earnings, getRootElement(), 0, 0, 255, true )--Tell everyone about it elseif(getElementData(pickup, "rpg.money") == "mons") then --This can be ignored it has nothing to do with the drug run local money = getPlayerMoney(source) setPlayerMoney(source , money + 100) destroyElement(pickup) end end function setupDrugRun() if(hasBeenCollected == true) then --Has our drug package been collected hasBeenCollected=false --If so reset it local location=math.random(2) --Choose a random location from the array theDrug = createPickup ( locx[location], locy[location], locz[location], 3, 1279) --Possibly not passing the element to theDrug drugBlip = createBlipAttachedTo ( theDrug, 36) -- Define the blip setElementData(theDrug, "rpg.drug", "a")--We cannot pass theDrug to addEventHandler as element(Perhaps a bug or user error) outputChatBox ( "A new drug package is available for pick up", getRootElement(), 0, 0, 255, true )--Tell everyone about it. end end function startDrugRun() --Sets up the timer for the drug run this can be ignored setTimer(setupDrugRun, 1000, 0) end 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