Hero192 Posted July 17, 2015 Share 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 Link to comment
Price. Posted July 17, 2015 Share 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 ) Link to comment
myonlake Posted July 17, 2015 Share Posted July 17, 2015 You cannot destroy non-elements. You need to use takeWeapon for that server-side. Link to comment
Hero192 Posted July 17, 2015 Author Share 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 ) Link to comment
GTX Posted July 17, 2015 Share 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 ) Link to comment
Hero192 Posted July 17, 2015 Author Share Posted July 17, 2015 So should i use only server side? what i have to do in client Link to comment
Dealman Posted July 17, 2015 Share 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 ) Link to comment
Hero192 Posted July 17, 2015 Author Share 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 Link to comment
Dealman Posted July 17, 2015 Share 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 ) Link to comment
GTX Posted July 17, 2015 Share 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 ) Link to comment
myonlake Posted July 17, 2015 Share 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). Link to comment
Dealman Posted July 18, 2015 Share 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. 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