Jump to content

help with simple script :D


golanu21

Recommended Posts

function skin1() 
local skin = getElementModel(source) 
    if skin == 9 then 
        setElementHealth(source, getElementHealth(source) -1) 
    end 
end 
addEventHandler("onPlayerDamage", getRootElement(), skin1) 

i want when player havee skin ID 9 then when someone shoot him

setElementHealth(source, getElementHealth(source) -1) 

Link to comment
function skin1 ( ) 
    local skin = getElementModel ( source ) 
    outputChatBox ( "THE SKIN IS: ".. tostring ( skin ) ) 
    if ( skin == 9 ) then 
        setElementHealth ( source, ( getElementHealth ( source ) - 1 ) ) 
    else 
        outputChatBox ( "SKIN ISN'T 9" ) 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), skin1 ) 

Try that and see what it outputs to chat when you damage a player.

Link to comment

Then you have to make the script client side, since onPlayerDamage can't be cancelled.

function skin1 ( ) 
    local skin = getElementModel ( source ) 
    if ( skin == 9 ) then 
        cancelEvent ( ) 
        setElementHealth ( source, ( getElementHealth ( source ) - 1 ) ) 
    end 
end 
addEventHandler ( "onClientPlayerDamage", localPlayer, skin1 ) 

Link to comment
  • Moderators

Unfortunately when you change health of a player the same moment he got damaged, the damage doesn't got cancelled.

I don't know why, but this is the way it works.....

try this:

Client

local damageThePlayer = function () 
    local newHealth = getElementHealth(localPlayer)-1 
    if newHealth > 0 then 
        setElementHealth(localPlayer,newHealth) 
    else 
        setElementHealth(localPlayer,0) 
    end 
end 
  
addEventHandler ( "onClientPlayerDamage",localPlayer, 
function () 
    if getElementModel ( localPlayer ) == 9 then 
        cancelEvent() 
        setTimer(damageThePlayer,50,1) 
    end 
end) 

The delay is 50 ms.

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