Hero192 Posted July 17, 2015 Posted July 17, 2015 (edited) Hello there,i want to release an script but to start on it i need to know this what im gonna tell you I want when the player fire the weapon ID == 17 the element be destroyed I tried that but failed,please give me the functions / events what should i use,thanks in advance I tried that but nothing happened anyone can help me for that ? --Client side: addEventHandler("onWeaponFire", root, function( ) for _, p in ipairs ( getElementsByType ( "player" ) ) do local tear = getPedWeapon(p) if (tear == 17) then triggerServerEvent ("takeweapon",getLocalPlayer()) end end end ) --Server side: addEvent( "takeweapon", true ) addEventHandler("takeweapon", g_Root, function() setTimer ( takeWeapon( tear),1000,1) end ) Edited July 17, 2015 by Guest
Price. Posted July 17, 2015 Posted July 17, 2015 addEventHandler("onWeaponFire", root, function( ) for _, p in ipairs ( getElementsByType ( "player" ) ) do local tear = getPedWeapon(p) if (tear == 17) then setTimer( destroyElement(tear),3000,1) end end ) YOU HAVE TO TRUST SOMEONE TO BE BETRAYED.I NEVER DID
myonlake Posted July 17, 2015 Posted July 17, 2015 You cannot destroy non-elements. You need to use takeWeapon for that server-side. If I helped you, please click the like button on the right Thanks!
Hero192 Posted July 17, 2015 Author Posted July 17, 2015 I tried that but nothing happened anyone can help me for that ? --Client side: addEventHandler("onWeaponFire", root, function( ) for _, p in ipairs ( getElementsByType ( "player" ) ) do local tear = getPedWeapon(p) if (tear == 17) then triggerServerEvent ("takeweapon",getLocalPlayer()) end end end ) --Server side: addEvent( "takeweapon", true ) addEventHandler("takeweapon", g_Root, function() setTimer ( takeWeapon( tear),1000,1) end )
GTX Posted July 17, 2015 Posted July 17, 2015 You're using server-side event in client-side part. Server: addEventHandler("onWeaponFire", root, function() local tear = getPedWeapon(source) if tear == 17 then cancelEvent() takeWeapon(tear) end end ) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
Hero192 Posted July 17, 2015 Author Posted July 17, 2015 So should i use only server side? what i have to do in client
Dealman Posted July 17, 2015 Posted July 17, 2015 You're using server-side event in client-side part.Server: addEventHandler("onWeaponFire", root, function() local tear = getPedWeapon(source) if tear == 17 then cancelEvent() takeWeapon(tear) end end ) You need to specify the player element when running it server-side. addEventHandler("onWeaponFire", root, function() local tear = getPedWeapon(source) if tear == 17 then cancelEvent() takeWeapon(source, tear) end end ) If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
Hero192 Posted July 17, 2015 Author Posted July 17, 2015 But i want it destroy after the fire in 1 second any idea? should i add the setTimer in client / server side
Dealman Posted July 17, 2015 Posted July 17, 2015 Whichever would work, but if you were to put it client-side you'd have to trigger an event, which seems rather unnecessary when you could just put the timer server-side like this; addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() setTimer(function() takeWeapon(source, currentWeaponID) end, 1000, 1) end end ) If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
GTX Posted July 17, 2015 Posted July 17, 2015 Whichever would work, but if you were to put it client-side you'd have to trigger an event, which seems rather unnecessary when you could just put the timer server-side like this; addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() setTimer(function() takeWeapon(source, currentWeaponID) end, 1000, 1) end end ) You forgot to pass source to function inside setTimer. addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() setTimer(function(source) takeWeapon(source, currentWeaponID) end, 1000, 1, source) end end ) Or: addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() -- You can also remove this. setTimer(takeWeapon, 1000, 1, source, currentWeaponID) end end ) Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS. Developer and owner of https://projectbea.st - Project Beast
myonlake Posted July 17, 2015 Posted July 17, 2015 onWeaponFire is not triggered for non-custom weapons. You need to implement your own sender event client-side, which sends the stuff to the server. Make sure to call the server trigger only once, or otherwise you can get hundreds of requests per second, which is not necessarily the thing you want. You can use a timer to do that properly, client-side. You can use onClientPlayerWeaponFire, which you then bind to the localPlayer (instead of triggering for any streamed in players that fires their weapon). If I helped you, please click the like button on the right Thanks!
Dealman Posted July 18, 2015 Posted July 18, 2015 You forgot to pass source to function inside setTimer. addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() setTimer(function(source) takeWeapon(source, currentWeaponID) end, 1000, 1, source) end end ) Or: addEventHandler("onWeaponFire", root, function() local currentWeaponID = getPedWeapon(source) if(currentWeaponID == 17) then cancelEvent() -- You can also remove this. setTimer(takeWeapon, 1000, 1, source, currentWeaponID) end end ) You actually don't need to pass them, so long as the variable is defined before the timer. There are some cases where source won't work, because it will be "discarded" after a few milliseconds. I believe onPlayerLogin does this. If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.
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