Jump to content

Help with cancelEvent


boro

Recommended Posts

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
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

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...