Jump to content

[ AJUDA ] onPickupHit


Recommended Posts

Gostaria de fazer um pickup quando o jogador morrer, ao passar nele , outro jogador recebe o dinheiro do que morreu.

function dropPickup()
	local playerMoney = getPlayerMoney(source)
	local x,y,z = getElementPosition(source)
    moneyPickup = createPickup(x,y,z,3,1212)

	setElementData(moneyPickup, "moneydrop", playerMoney)
	takePlayerMoney(source, playerMoney)
end
addEventHandler("onPlayerWasted", root, dropPickup)

function onPickup(player)
	local moneyDrop = getElementData(source, "moneydrop")
		givePlayerMoney(player,moneyDrop)
		destroyElement(source)
end
addEventHandler("onPickupHit", moneyPickup, onPickup)

Estou tendo o seguinte erro : Bad argument  'addEventHandler' Expected element at argument 2, got nil.

Link to comment
Quote

function dropPickup()
	local playerMoney = getPlayerMoney(source)
	local x,y,z = getElementPosition(source)
    moneyPickup = createPickup(x,y,z,3,1212)

	setElementData(moneyPickup, "moneydrop", playerMoney)
	takePlayerMoney(source, playerMoney)
end
addEventHandler("onPlayerWasted", getRootElement(), dropPickup)

function onPickup(player)
	local moneyDrop = getElementData(source, "moneydrop")
		givePlayerMoney(player, moneyDrop)
		destroyElement(source)
end
addEventHandler("onPickupHit", moneyPickup, onPickup)

 

Acho que só tinha um erro kk, testa ai

  • Like 1
Link to comment

@Arantes, diante de sua questão eu tentei fazer algo semelhante e assim foi feito:
 

Dados = {}

addEventHandler('onPlayerWasted', root, 
	function ()
		if (Dados[source]) then
			destroyElement(Dados[source].pick)
		end
		local pos = Vector3(getElementPosition(source))
		Dados[source] = {}
		Dados[source].pick = createPickup(pos, 3, 1212)
		Dados[source].money = math.max(0, getPlayerMoney(source))
		Dados[Dados[source].pick] = source

		addEventHandler('onPickupUse', Dados[source].pick, 
			function (p)
				local oMorto = Dados[source]
				if (oMorto and Dados[oMorto]) then
					givePlayerMoney(p, Dados[oMorto].money)
					destroyElement(Dados[oMorto].pick)
					Dados[oMorto] = nil
					Dados[source] = nil
				end
			end
		)
	end
)

 

  • Thanks 1
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...