Jump to content

Money Drop


#Paper

Recommended Posts

function createMoney(player) 
   local x, y, z = getElementPosition(player); 
   local x1, y1, x2, y2; 
   x1 = (x-2)+(math.random()*4); 
   y1 = (y-2)+(math.random()*4); 
   x2 = (x-2)+(math.random()*4); 
   y2 = (y-2)+(math.random()*4); 
   local moneyAmmount = getPlayerMoney(player); 
   moneyAmmount = math.floor(moneyAmmount/2); 
   takePlayerMoney(player, moneyAmmount); 
   moneyAmmount = math.floor(moneyAmmount/2); 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
   setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
end 
  
function moneyPickupHit(player) 
   local money = getElementData(source, "ammount"); 
   if money then 
      givePlayerMoney(player, money); 
      destroyElement(source); 
   end 
end 
  
function playerJustGotDied(ammo, attacker, weapon, bodypart) 
if (isElement(attacker)) then 
    createMoney(source) 
    end 
end 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied); 

I didn't fully made this script, it was in the forums and I just searched for it for you and fixed some bugs.

Link to comment
function createMoney(player) 
   local x, y, z = getElementPosition(player); 
   local x1, y1, x2, y2; 
   x1 = (x-2)+(math.random()*4); 
   y1 = (y-2)+(math.random()*4); 
   x2 = (x-2)+(math.random()*4); 
   y2 = (y-2)+(math.random()*4); 
   local moneyAmmount = getPlayerMoney(player); 
   moneyAmmount = math.floor(moneyAmmount/2); 
   takePlayerMoney(player, moneyAmmount); 
   moneyAmmount = math.floor(moneyAmmount/2); 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
   setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
end 
  
function moneyPickupHit(player) 
   local money = getElementData(source, "ammount"); 
   if money then 
      givePlayerMoney(player, money); 
      destroyElement(source); 
   end 
end 
  
function playerJustGotDied(ammo, attacker, weapon, bodypart) 
if (isElement(attacker)) then 
    createMoney(source) 
    end 
end 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied); 

I didn't fully made this script, it was in the forums and I just searched for it for you and fixed some bugs.

the money doesn't drop (bad argumnets the setElementData(createPickup...))

and from where i must trigger the moneyPickupHit?

Link to comment
Strange, I tested it and worked fine o_O.

P.S: There's a "onPickupUse" event for "moneyPickupHit".

I edited a little bit the code, whit "test" cmd the pickup is created but i can't drop it :S

function createMoney(killed) 
   local x, y, z = getElementPosition(killed) 
   local x1, y1, x2, y2 
   x1 = (x-2)+(math.random()*2) 
   y1 = (y-2)+(math.random()*2) 
   x2 = (x-2)+(math.random()*2) 
   y2 = (y-2)+(math.random()*2) 
   local moneyAmmount = getPlayerCount() * 4 
   addStat(getPlayerAccount(killed), "cash", -moneyAmmount) 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount) 
end 
addCommandHandler("test", createMoney) 
  
function moneyPickupHit(player) 
if isGuestAccount(getPlayerAccount(player)) == false then 
   local money = getElementData(source, "ammount") 
   if money then 
      addStat(getPlayerAccount(player), "cash", money) 
      destroyElement(source) 
   end 
end 
end 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit) 

Link to comment
Strange, I tested it and worked fine o_O.

P.S: There's a "onPickupUse" event for "moneyPickupHit".

I edited a little bit the code, whit "test" cmd the pickup is created but i can't drop it :S

function createMoney(killed) 
   local x, y, z = getElementPosition(killed) 
   local x1, y1, x2, y2 
   x1 = (x-2)+(math.random()*2) 
   y1 = (y-2)+(math.random()*2) 
   x2 = (x-2)+(math.random()*2) 
   y2 = (y-2)+(math.random()*2) 
   local moneyAmmount = getPlayerCount() * 4 
   addStat(getPlayerAccount(killed), "cash", -moneyAmmount) 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount) 
end 
addCommandHandler("test", createMoney) 
  
function moneyPickupHit(player) 
if isGuestAccount(getPlayerAccount(player)) == false then 
   local money = getElementData(source, "ammount") 
   if money then 
      addStat(getPlayerAccount(player), "cash", money) 
      destroyElement(source) 
   end 
end 
end 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit) 

P.S: I didn't see the events xD

Link to comment
DON'T DOUBLE POST, EVEN WORST FOR SOMETHING LIKE THAT.

What are you trying to achieve?

So, when a players die, the server creates the money pickup and when a player get it get the amount of pickup, just this :D

P.S: OMFG T_T sry for double post

Link to comment
Why not just use CreateElement("foo", createPickup(...)) when the player dies?

I don't understand you either... createPickup returns a pickup element already.

Infact, but think that i'll use the classic method of money getting:

function onWasted (killer) 
   givePlayerMoney(killer, 500) 
end 

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