#Paper Posted July 10, 2011 Share Posted July 10, 2011 How can i make that when a players die it releases some money on the floor and if a player take this take $? Link to comment
Castillo Posted July 10, 2011 Share Posted July 10, 2011 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
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 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
Castillo Posted July 11, 2011 Share Posted July 11, 2011 Strange, I tested it and worked fine o_O. P.S: There's a "onPickupUse" event for "moneyPickupHit". Link to comment
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 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 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
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 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 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 Link to comment
Castillo Posted July 11, 2011 Share Posted July 11, 2011 DON'T DOUBLE POST, EVEN WORST FOR SOMETHING LIKE THAT. What are you trying to achieve? Link to comment
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 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 P.S: OMFG T_T sry for double post Link to comment
Castillo Posted July 11, 2011 Share Posted July 11, 2011 I tested the code I gave you and works fine. Note: This will work if someone kills you, not when you die with some command. Link to comment
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 ok, i tryed whit someone that kills me, i pick up the pickup but i don't get money Link to comment
falseprophet Posted July 11, 2011 Share Posted July 11, 2011 Why not just use CreateElement("foo", createPickup(...)) when the player dies? Link to comment
#Paper Posted July 11, 2011 Author Share Posted July 11, 2011 Why not just use CreateElement("foo", createPickup(...)) when the player dies? what do u mean? Link to comment
Castillo Posted July 11, 2011 Share Posted July 11, 2011 Why not just use CreateElement("foo", createPickup(...)) when the player dies? I don't understand you either... createPickup returns a pickup element already. Link to comment
#Paper Posted July 12, 2011 Author Share Posted July 12, 2011 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
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