Axel Posted August 21, 2011 Share Posted August 21, 2011 Im trying to create a pickup near the player when he types /givemoney {ammount} , i made the script but it does not work, i can t find bugs .. function givemoney(thePlayer, command, amount) local givingplayer = getPlayerFromName ( thePlayer ) local x,y,z = getElementPosition(thePlayer) local x = x + 5 local gpickup = createPickup(x,y,z,1212) takePlayerMoney (thePlayer, math.abs(tonumber(amount))) end addCommandHandler ("givemoney", givemoney) function takemoney ( thePlayer ) givePlayerMoney(thePlayer, math.abs(tonumber(amount))) destroyElement(gpickup) end addEventHandler ( "onPickupUse", gpickup, takemoney ) Link to comment
BinSlayer1 Posted August 21, 2011 Share Posted August 21, 2011 you almost got it right good job for trying, however you do have some bugs here and there, look at my code and if there's something you don't understand just ask. You should test it too first, because I didn't. gpickup = {} function takemoney ( thePlayer ) givePlayerMoney(thePlayer, getElementData(source, "moneyDropped")) destroyElement(source) end function givemoney(thePlayer, command, amount) if isElement(gpickup[thePlayer]) then return end local givingplayer = getPlayerFromName ( thePlayer ) local x,y,z = getElementPosition(thePlayer) local x = x + 5 local gpickup[thePlayer] = createPickup(x,y,z,3,1212) setElementData(gpickup[thePlayer], "moneyDropped", math.ceil(tonumber(amount))) takePlayerMoney (thePlayer, math.abs(math.ceil(tonumber(amount)))) addEventHandler('onPickupHit', gpickup[thePlayer], takemoney) end addCommandHandler ("givemoney", givemoney) Link to comment
Axel Posted August 31, 2011 Author Share Posted August 31, 2011 I tested and there is a error line 13 unexpected symbol near '[' Link to comment
Castillo Posted August 31, 2011 Share Posted August 31, 2011 That's caused by the 'local' infront of it. function takemoney ( thePlayer ) givePlayerMoney(thePlayer, getElementData(source, "moneyDropped")) destroyElement(source) end function givemoney(thePlayer, command, amount) if isElement(gpickup[thePlayer]) then return end local givingplayer = getPlayerFromName ( thePlayer ) local x,y,z = getElementPosition(thePlayer) local x = x + 5 gpickup[thePlayer] = createPickup(x,y,z,3,1212) setElementData(gpickup[thePlayer], "moneyDropped", math.ceil(tonumber(amount))) takePlayerMoney (thePlayer, math.abs(math.ceil(tonumber(amount)))) addEventHandler('onPickupHit', gpickup[thePlayer], takemoney) end addCommandHandler ("givemoney", givemoney) Link to comment
Axel Posted August 31, 2011 Author Share Posted August 31, 2011 Still does not work.. Link to comment
Castillo Posted August 31, 2011 Share Posted August 31, 2011 local gpickup = {} function takemoney ( thePlayer ) givePlayerMoney(thePlayer, getElementData(source, "moneyDropped")) destroyElement(source) end function givemoney(thePlayer, command, amount) if isElement(gpickup[thePlayer]) then return end local x,y,z = getElementPosition(thePlayer) local x = x + 5 gpickup[thePlayer] = createPickup(x,y,z,3,1212) setElementData(gpickup[thePlayer], "moneyDropped", math.ceil(tonumber(amount))) takePlayerMoney (thePlayer, math.abs(math.ceil(tonumber(amount)))) addEventHandler('onPickupHit', gpickup[thePlayer], takemoney) end addCommandHandler ("givemoney", givemoney) Works fine here. Link to comment
Static-X Posted August 31, 2011 Share Posted August 31, 2011 use this? I fixed some of the errors ( that could occur ) gpickup = {} function takemoney ( thePlayer ) givePlayerMoney(thePlayer, getElementData(source, "moneyDropped")) destroyElement(source) end function err(str,rec) -- lazy to type outputChatBox each time if not (rec) then rec = getRootElement() end outputChatBox(str,rec,255,0,0) end function givemoney(thePlayer, command, amount) if not (amount) then -- if the player didnot type the amount then err("Incorrect syntax",thePlayer) return end if not tonumber(amount) then -- if the amount is not a number then err("Invalid amount",thePlayer) return end if (tonumber(amount)>=getPlayerMoney(thePlayer)) then -- if the player's money is less than the amount then err("Invalid amount",thePlayer) return end if (tonumber(amount)==0) or (tonumber(amount)<=0) then -- if the amount is 0 or negative then err("Invalid amount",thePlayer) return end if isElement(gpickup[thePlayer]) then -- if the element gpickup[thePlayer] exists then return end local x,y,z = getElementPosition(thePlayer) local x = x + 5 gpickup[thePlayer] = createPickup(x,y,z,3,1212) setElementData(gpickup[thePlayer], "moneyDropped", math.ceil(tonumber(amount))) takePlayerMoney (thePlayer, math.abs(math.ceil(tonumber(amount)))) addEventHandler('onPickupHit', gpickup[thePlayer], takemoney) end addCommandHandler ("givemoney", givemoney) Link to comment
Axel Posted September 1, 2011 Author Share Posted September 1, 2011 Thank you very much, i apreciate your help. 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