Jump to content

onClientPlayerDamage


Recommended Posts

onClientPlayerDamage doesn't get triggered if the weapon was a spraycan! it was working fine but suddenly it became untriggerable for the spraycan weapon... i tried it on other weapons and it works but on spraycan it won't work.

  
addEventHandler('onClientPlayerDamage', getRootElement(), 
    function(attacker, weapon, bodypart ,loss) 
        outputChatBox('1') 
    end 
) 
  

is this a MTA bug or what?

please try it on your local server and tell me the result.. because my mind will explode soon :shock: !

Link to comment
  • Moderators
addEventHandler("onClientPlayerWeaponFire", root, 
function (weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement, startX, startY, startZ) 
  
    local attacker = source 
     
    if weapon == 41 then 
        if getDistanceBetweenPoints3D (hitX, hitY, hitZ,startX, startY, startZ) < 3 then -- anti bug 
            outputChatBox('spraycan hit') 
        end 
    else 
        outputChatBox('1') 
    end 
     
     
end) 
  

Or you can use:(this event can cancel the damage/animation)

addEventHandler("onClientPlayerChoke", root, 
function (weapon,attacker) 
    if weapon == 41 then 
        outputChatBox("hit with spraycan > onClientPlayerChoke ") 
    end 
end) 

Link to comment
addEventHandler("onClientPlayerWeaponFire", root, 
function (weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement, startX, startY, startZ) 
  
    local attacker = source 
     
    if weapon == 41 then 
        if getDistanceBetweenPoints3D (hitX, hitY, hitZ,startX, startY, startZ) < 3 then -- anti bug 
            outputChatBox('spraycan hit') 
        end 
    else 
        outputChatBox('1') 
    end 
     
     
end) 
  

Thanks you now i get it. but the thing is .. the source get damaged and cancelEvent() has no effect. what's the solution for that?

Link to comment
  • Moderators

By using the second example + cancelEvent() of my previous post.

    addEventHandler("onClientPlayerChoke", root, 
    function (weapon,attacker) 
        if weapon == 41 then 
            outputChatBox("hit with spraycan > onClientPlayerChoke ") 
  
  
cancelEvent() 
  
  
        end 
    end) 

You have to read the information better from the event's.

Only events that have information about cancelling events can do that, others cannot.

Link to comment
By using the second example + cancelEvent() of my previous post.
    addEventHandler("onClientPlayerChoke", root, 
    function (weapon,attacker) 
        if weapon == 41 then 
            outputChatBox("hit with spraycan > onClientPlayerChoke ") 
  
  
cancelEvent() 
  
  
        end 
    end) 

You have to read the information better from the event's.

Only events that have information about cancelling events can do that, others cannot.

your code prevent the player from doing the action but it still getting damage!

Link to comment

Check this out

addEventHandler ( "onClientPlayerChoke", localPlayer, 
    function ( weapon ) 
        if ( source ~= localPlayer ) then return end 
        if ( weapon == 41 ) 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...