Arantes Posted May 27, 2020 Share Posted May 27, 2020 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
Blaack Posted May 27, 2020 Share Posted May 27, 2020 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 1 Link to comment
Arantes Posted May 27, 2020 Author Share Posted May 27, 2020 Desculpe , não informei a linha kk . Esta dando erro na linha 17 , no onPickupHit . Link to comment
KronoS Lettify Posted May 27, 2020 Share Posted May 27, 2020 @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 ) 1 Link to comment
Arantes Posted May 27, 2020 Author Share Posted May 27, 2020 Muito obrigado , funcionou certinho ! So adicionei para o jogador perder o dinheiro quando morrer. Link to comment
KronoS Lettify Posted May 27, 2020 Share Posted May 27, 2020 16 minutes ago, Arantes said: Muito obrigado , funcionou certinho ! So adicionei para o jogador perder o dinheiro quando morrer. Boa, tinha esquecido desse detalhe 1 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