Xabache Posted February 19, 2015 Share Posted February 19, 2015 I want this money to disappear 15 seconds after being created, like in the real game. How do I make it timeout in the easiest manner? local money = math.random( 1, 8 ); if money > 3 then setElementData(createPickup(x1, y1, z, 3, 1212), "amount1", math.random( 1, 25 ) ); Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 You need to store the pickup in a variable, then use that variable in setElementData. You can then use setTimer along with destroyElement after 15 seconds. local pickup = createPickup(x1, y1, z, 3, 1212) setElementData(pickup, "amount1", math.random( 1, 25 ) ); setTimer(function() if (isElement(pickup)) then destroyElement(pickup) end end, 15000, 1) Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 and now an unrelated question... i want this to create the weapon in hand of the player instead of a random weapon setElementData(createPickup(x5, y5, z, 2, getPedWeapon( client ) ), "weapon", math.random( 50, 100 ) ); Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 You need to specify the amount of ammo to give to the player. Also, you should post your full code, we don't know if you're correctly using client or not. And why are you using element data? Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 This creates a pickup on the death of a ped, so element data is being set so the pickup has the name "weapon" so that onpickuse and pickuphit know what to do. and the ammo value 50-100. addEventHandler("onPickupUse", getRootElement(), PickupHit); The part that creates this serverside event is onpedwasted triggering this money creator is expanded to also do weapons. All i need is to know the weapon in hand of the player who wasted the ped. function createMoney(player) local x, y, z = getElementPosition(player); local x1, y1, x2, y2; x1 = (x-1)+(math.random()*1); y1 = (y-1)+(math.random()*1); x2 = (x-2)+(math.random()*2); y2 = (y-2)+(math.random()*2); x3 = (x-3)+(math.random()*3); y3 = (y-3)+(math.random()*3); x4 = (x-4)+(math.random()*4); y4 = (y-4)+(math.random()*4); x5 = (x-5)+(math.random()*5); y5 = (y-5)+(math.random()*5); local money = math.random( 1, 8 ); -- locaPlayer player if money > 3 then local am1 = createPickup(x1, y1, z, 3, 1212) setElementData(am1, "amount1", math.random( 1, 25 ) ); setTimer(function() if (isElement(am1)) then destroyElement(am1) end end, 10000, 1) if money > 4 then local weaptype = math.random(1,10) if weaptype == 1 then local we = createPickup(x5, y5, z, 2, myRandom()) setElementData(we, "weapon", math.random( 50, 100 ) ); setTimer(function() if (isElement(we)) then destroyElement(we) end end, 10000, 1) else outputChatBox ( "play " .. getPedWeapon(player) ) local we = createPickup(x5, y5, z, 2, getPedWeapon(playerSource) ) setElementData(we, "weapon", math.random( 50, 100 ) ); setTimer(function() if (isElement(we)) then destroyElement(we) end end, 10000, 1) Specifically this bit: local we = createPickup(x5, y5, z, 2, getPedWeapon(playerSource) ) setElementData(we, "weapon", math.random( 50, 100 ) ); setTimer(function() if (isElement(we)) then destroyElement(we) end end, which works fine when it works like this: local we = createPickup(x5, y5, z, 2, myRandom()) setElementData(we, "weapon", math.random( 50, 100 ) ); setTimer(function() if (isElement(we)) then destroyElement(we) end end, 10000, 1) Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 You don't need to handle onPickupHit yourself, when you create a pickup of type 2, it automatically gives the ped a weapon when he hits it. You might only use onPickupHit to destroy the pickup when it's hit. So, you don't really need the element data. You need to specify the ammo argument, so that it gives the ped the correct amount of ammo. I told you to post your code because you're using client, which only refers to the local player who triggered the event, unless you defined client yourself or you used triggerServerEvent, it won't work. Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 This is entirely serverside. From a server side event how do I get the players weapon id in hand? Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 This gets the current weapon in the player's hand: getPedWeapon(player) If it's onPlayerWasted event, then you can use source instead of player. Now note this, I'm not really sure if the player still carries his weapon after he dies (and before he respawns), so I guess you will have to test Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 outputChatBox ( "play " .. getPedWeapon(player) ) returns play 0 regardless of weapon Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 If 'player' is actually a player holding a weapon then it should return the weapon id, just tested it myself actually. EDIT: Just tested onPlayerWasted as well, using getPedWeapon on the player who just died works just fine. Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 Thanks for the advice will clean up those Sets. And not working here, maybe posting your test code would help me. Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 addEventHandler("onPlayerWasted", root, function() outputDebugString(tostring(getPedWeapon(source))) end) Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 Sorry, but that wasn't at all my question. And I see your request for greater specifics now. When the player, kills a ped onPedWasted (serverside only) I want a weapon to be dropped by that ped. I want that weapon to be the same as the weapon used by the player to kill them. So I need to know, what weapon is in the hand of the player when the onPedWasted event occurs serverside for which getPedWeapon(source) and getPedWeapon(player) both return 0 despite the weapon of choice being the minigun. This base code could be used to test it. all i need is the player weaponID on wasted 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); Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 Now I get it, okay, here's the code for that: addEventHandler("onPedWasted", root, function(ammo, killer, weapon) if (weapon == 0) then return end local x,y,z = getElementPosition(source) local pickup = createPickup(x, y, z, 2, weapon, 0, getPedTotalAmmo(killer) or 300) addEventHandler("onPickupHit", pickup, destroyElement) -- destroy the pickup on hit end) Now, you probably will need to edit it to suit your needs. Do you want to detect players being killed or peds? If you want players, change onPedWasted to onPlayerWasted. You might want to edit the ammo argument as well. Link to comment
Xabache Posted February 19, 2015 Author Share Posted February 19, 2015 Very nice code^^ ..almost there. The Ped has no weapon or ammo. It is just a ped on whose death reveals a ""hidden"" weapon that is the same as the one the player used to kill it. So a weaponless ped is killed, to reveal it has 50 ammo of weaponID X == the player's gun. In otherwords, I kill it with a minigun, it gives me minigun ammo. I kill it with a knife it gives me a knife. It is a complex problem with a simple solution, all i need is for the server to tell me the players weapon ID. How? Link to comment
JR10 Posted February 19, 2015 Share Posted February 19, 2015 Check the code again, onPedWasted provides you with the killer and his weapon, 'weapon' there is the killer's weapon. 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