Jump to content

help with simple script :D


golanu21

Recommended Posts

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

XajVsWV.png

168_zps269f1907.gif[Dev]BloWnRPG - We BloW the World [1%]168_zps269f1907.gif

Posted

And what's the problem?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Is it set as server side?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted

You wear the correct skin? and you test it on a real player?

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Hold on, you want when the skin is 9, only take 1% of damage and cancel the rest?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You changed the script type on the meta.xml to "client", right?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted

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.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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