boro Posted May 5, 2013 Share Posted May 5, 2013 Hi i have script for cancel player damage when is shot but this dont work please help me function DamageStop ( attacker, attackerweapon, bodypart, loss ) if (attackerweapon == 1 or attackerweapon == 2 or attackerweapon == 3 or attackerweapon == 4 or attackerweapon == 5 or attackerweapon == 6 or attackerweapon == 7 or attackerweapon == 8 or attackerweapon == 9 or attackerweapon == 22 or attackerweapon == 23 or attackerweapon == 33 or attackerweapon == 34 or attackerweapon == 35 or attackerweapon == 36 or attackerweapon == 37 or attackerweapon == 38 or attackerweapon == 16 or attackerweapon == 17 or attackerweapon == 18 or attackerweapon == 39 or attackerweapon == 42 ) then cancelEvent() end end addEventHandler ( "onPlayerDamage", getRootElement (), DamageStop ) Link to comment
PaiN^ Posted May 5, 2013 Share Posted May 5, 2013 You can't cancel the onPlayerDamage event ! You must do it client side ( using onClientPlayerDamage ) . Link to comment
boro Posted May 5, 2013 Author Share Posted May 5, 2013 function DamageStop ( attacker, attackerweapon, bodypart, loss ) if (attackerweapon == 1 or attackerweapon == 2 or attackerweapon == 3 or attackerweapon == 4 or attackerweapon == 5 or attackerweapon == 6 or attackerweapon == 7 or attackerweapon == 8 or attackerweapon == 9 or attackerweapon == 23 or attackerweapon == 35 or attackerweapon == 36 or attackerweapon == 37 or attackerweapon == 38 or attackerweapon == 16 or attackerweapon == 17 or attackerweapon == 18 or attackerweapon == 39 or attackerweapon == 42 ) then cancelEvent() end end addEventHandler ( "onClientPlayerDamage", getRootElement (), DamageStop ) hmm this dont work too and i dont want cancel damage for all weapons but only for this selected Link to comment
DiSaMe Posted May 5, 2013 Share Posted May 5, 2013 Unless I have missed something, there's nothing in the script what could prevent it from working. Maybe you didn't set it to client-sided in meta.xml? And if you want to prevent some weapons from inflicting damage, there's no need to make a long condition check. Better use tables for that. Instead of doing this: if value == 5 or value == 9 or value == 11 then You can make a table of values (usually at the top of the script): validValues = { [5] = true, [9] = true, [11] = true } And check the condition in this way: if validValues[value] then Link to comment
iPrestege Posted May 5, 2013 Share Posted May 5, 2013 Or i have another best way !! addEventHandler("onClientPlayerDamage",getRootElement(), function ( attacker,weapon ) if ( attacker == source ) then return end for i = 1,46 do if ( i ) == false then return end if ( weapon == i ) then cancelEvent ( true ) end end end ) Link to comment
boro Posted May 5, 2013 Author Share Posted May 5, 2013 Pres[T]ege this dont work and this dont work too weapon = { [36] = true, [37] = true, [38] = true } addEventHandler("onClientPlayerDamage",getRootElement(), function ( attacker,weapon ) if weapon[id] then cancelEvent () end end ) Link to comment
iPrestege Posted May 5, 2013 Share Posted May 5, 2013 Try this : local weapons = { [36] = true, [37] = true, [38] = true } addEventHandler("onClientPlayerDamage",getRootElement(), function ( attacker,weapon ) if weapons[weapon] then cancelEvent () end end ) Link to comment
boro Posted May 5, 2013 Author Share Posted May 5, 2013 and is possible stop heli killing ? Link to comment
TAPL Posted May 5, 2013 Share Posted May 5, 2013 https://wiki.multitheftauto.com/wiki/OnClientPlayerHeliKilled 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