Jump to content

money drop


Recommended Posts

I have this money drop script I found somewhere. It works fine except it stops my pickups from respawning.

My pickups are all in a map file and the script is in my gamemode.

Here is the script. I have it between my teams list and spawns.

Any help would be greatly appreciated.

function createMoney(mx,my,mz,level)

local x1=(mx-2)+(math.random()*4)

local y1=(my-2)+(math.random()*4)

local x2=(mx-2)+(math.random()*4)

local y2=(my-2)+(math.random()*4)

local moneyamount=math.floor(200*level^0.2)

setElementData(createPickup(x1,y1,mz,3,1212),"amount",moneyamount)

setElementData(createPickup(x2,y2,mz,3,1212),"amount",moneyamount)

end

function pickup(player)

local money=getElementData(source,"amount")

if ( money ) then

givePlayerMoney(player,money)

--destroyElement(source)

end

end

addEventHandler("onPickupUse",root,pickup)

function playerWasted ( ammo, attacker, weapon, bodypart )

local px,py,pz = getElementPosition(source)

createMoney(px,py,pz,100) --The last argument should be changed. Unless you have levels on your server (that are stored this way).

end

addEventHandler ( "onPlayerWasted", root, playerWasted )

end

Link to comment

Hint: You can make your code easier to read with the "code" button in the "Create reply" window. You can then also change the "code" in [] to "code=lua" or "code=xml" instead of "code". ;)

 

Then only thing I can see as a problem is that "pickup" function is triggered for every pickup used.

You can fix this by changing the following:

function createMoney(mx,my,mz,level) 
local x1=(mx-2)+(math.random()*4) 
local y1=(my-2)+(math.random()*4) 
local x2=(mx-2)+(math.random()*4) 
local y2=(my-2)+(math.random()*4) 
local moneyamount=math.floor(200*level^0.2) 
local pickup1=createPickup(x1,y1,mz,3,1212) 
local pickup2=createPickup(x2,y2,mz,3,1212) 
setElementData(pickup1,"amount",moneyamount) 
setElementData(pickup2,"amount",moneyamount) 
addEventHandler("onPickupUse",pickup1,pickup) 
addEventHandler("onPickupUse",pickup2,pickup) 
end 

Of course remove the addEventHandler you already had.

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