Jump to content

Stop damage for Medics?


Adde

Recommended Posts

Hey guys, I have been tried to understand how to stop the damage from weapon id 41 if the player is in team Emergency. If I understand this right it should be something with:

  
function cancel () 
if getTeamName ( getTeamFromName ( "Emergency" )) then 
if ( attackerWeapon == 41 ) then 
cancelEvent() 
addEventHandler ( "onPlayerDamage", getRootElement, cancel ) 
  

right?

My script looks like this

function medicJob (healer, healerweapon, bodypart, loss) 
    theHealth = getElementHealth (source) 
    theSkin = getPedSkin ( healer ) 
        if (healerweapon == 41) and (loss > 1) and ( theHealth < 80 ) and ( theSkin == 276 ) then 
       setElementHealth ( source, getElementHealth(source) + 20 ) 
               givePlayerMoney (healer, 30) 
    end 
end 
addEventHandler ("onPlayerDamage", getRootElement(), medicJob ) 

Link to comment

soooo..

function cancel ( attackerWeapon ) 
if getTeamName ( getPlayerTeam ( getLocalPlayer() ) ) == "Emergency" then 
if ( attackerWeapon == 41 ) then 
cancelEvent() 
end 
end 
end 
addEventHandler ( "onClientPlayerDamage", getLocalPlayer(), cancel ) 

??

Link to comment

function cancel ( attackerWeapon, player ) 
    if getElementType( player ) == "player" then 
        if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then 
            if ( attackerWeapon == 41 ) then 
            cancelEvent() 
            end 
        end 
    end 
end  
addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) 
Link to comment

Is that what you wanted to?

function cancel ( attacker, attackerWeapon ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            cancelEvent ( ) 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

Link to comment
Is that what you wanted to?
function cancel ( attacker, attackerWeapon ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            cancelEvent ( ) 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc..

Link to comment
Is that what you wanted to?
function cancel ( attacker, attackerWeapon ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            cancelEvent ( ) 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc..

as i did lol

function cancel ( attackerWeapon, player ) 
    if getElementType( player ) == "player" then 
        if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then 
            if ( attackerWeapon == 41 ) then 
            cancelEvent() 
            end 
        end 
    end 
end  
addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) 

Link to comment
Is that what you wanted to?
function cancel ( attacker, attackerWeapon ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            cancelEvent ( ) 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

You should use getElementType(attacker) to check if is a player instead of vehicle, object, etc..

as i did lol

function cancel ( attackerWeapon, player ) 
    if getElementType( player ) == "player" then 
        if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then 
            if ( attackerWeapon == 41 ) then 
            cancelEvent() 
            end 
        end 
    end 
end  
addEventHandler ( "onPlayerDamage", getLocalPlayer(), cancel ) 

But the event and parameters is wrong.

"onClientPlayerDamage" --[[ 
attacker: A player element representing the attacker or vehicle element (when being run over or falling off a bike). 
weapon: An integer representing the weapon ID the attacker used 
]] 

Should be:

function cancel ( player, attackerWeapon ) 
    if getElementType( player ) == "player" then 
        if getTeamName ( getPlayerTeam ( player ) ) == "Emergency" then 
            if ( attackerWeapon == 41 ) then 
            cancelEvent() 
            end 
        end 
    end 
end  
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

Link to comment
Post the script.

Ok

Server

function medicJob (healer, healerweapon, bodypart, loss) 
    theHealth = getElementHealth (source) 
    theSkin = getPedSkin ( healer ) 
        if (healerweapon == 41) and (loss > 1) and ( theHealth < 80 ) and ( theSkin == 276 ) then 
       setElementHealth ( source, getElementHealth(source) + 20 ) 
               givePlayerMoney (healer, 30) 
    end 
end 
addEventHandler ("onPlayerDamage", getRootElement(), medicJob ) 

Client

function cancel ( attacker, attackerWeapon ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            cancelEvent ( ) 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

Link to comment

-- client side:

function cancel ( attacker, attackerWeapon, bodypart, loss ) 
    if ( getTeamName ( getPlayerTeam ( attacker ) ) == "Emergency" ) then 
        if ( attackerWeapon == 41 ) then 
            local theSkin = getElementModel ( attacker ) 
            local theHealth = getElementHealth ( localPlayer ) 
            if ( loss > 1 ) and ( theHealth < 80 ) and ( theSkin == 276 ) then 
                triggerServerEvent ( "healPlayer", localPlayer, attacker ) 
                cancelEvent ( ) 
            end 
        end 
    end 
end 
addEventHandler ( "onClientPlayerDamage", root, cancel ) 

-- server side:

function medicJob ( healer ) 
    setElementHealth ( source, getElementHealth ( source ) + 20 ) 
    givePlayerMoney ( healer, 30 ) 
end 
addEvent ( "healPlayer", true ) 
addEventHandler ( "healPlayer", getRootElement(), medicJob ) 

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