Jump to content

Pickup money sound


21gangstreet

Recommended Posts

Hi , i am using pickup money script,when player kills another player drop the money.now i want add pickupmoney sound.i am editing codes but dont work :C where is my bad ? i am sharing codes :

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 valuemoney = 750 -- value take money 
    local moneyAmmount = valuemoney 
    local time = 25000 -- time in mile seconds 
  
   moneyAmmount = math.floor(moneyAmmount/1) 
   takePlayerMoney(player, moneyAmmount) 
   moneyAmmount = math.floor(moneyAmmount/3) 
 
   -- Create the pickups
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount);
   setElementData(createPickup(x2, y2, 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)
   createMoney(source);
end
 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit);
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied);

And client side :

function moneyPickupHit()
	local sound = playSound("money.wav")
	setSoundVolume(sound, 0.5)
end

addEventHandler("onmoneyPickupHit", root, moneyPickupHit)

Just i need help.thanks for time.

Edited by 21gangstreet
Link to comment

 

29 minutes ago, 21gangstreet said:

Hi , i am using pickup money script,when player kills another player drop the money.now i want add pickupmoney sound.i am editing codes but dont work :C where is my bad ? i am sharing codes :


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 valuemoney = 750 -- value take money 
    local moneyAmmount = valuemoney 
    local time = 25000 -- time in mile seconds 
  
   moneyAmmount = math.floor(moneyAmmount/1) 
   takePlayerMoney(player, moneyAmmount) 
   moneyAmmount = math.floor(moneyAmmount/3) 
 
   -- Create the pickups
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount);
   setElementData(createPickup(x2, y2, 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)
   createMoney(source);
end
 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit);
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied);

And client side :


function moneyPickupHit()
	local sound = playSound("money.wav")
	setSoundVolume(sound, 0.5)
end

addEventHandler("onmoneyPickupHit", root, moneyPickupHit)

Just i need help.thanks for time.

Here is the solution.

Serverside:

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 valuemoney = 750 -- value take money 
    local moneyAmmount = valuemoney 
    local time = 25000 -- time in mile seconds 
  
   moneyAmmount = math.floor(moneyAmmount/1) 
   takePlayerMoney(player, moneyAmmount) 
   moneyAmmount = math.floor(moneyAmmount/3) 
 
   -- Create the pickups
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount);
   setElementData(createPickup(x2, y2, 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);
      triggerClientEvent(source,"onmoneyPickupHit",source)
   end
end

 
function playerJustGotDied(ammo, attacker, weapon, bodypart)
   createMoney(source);
end
 
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit);
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied);

Client:

addEvent("onmoneyPickupHit",true)
function moneyPickupHit()
	local sound = playSound("money.wav")
	setSoundVolume(sound, 0.5)
end

addEventHandler("onmoneyPickupHit", root, moneyPickupHit)

You just added a handler without an event called: "onmoneyPickupHit" and you didn't trigger the event on server side on pickup.

I hope this would work.

Edited by Gold9
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...