Jump to content

Receive damage


dima3367

Recommended Posts

Posted
Hello everybody!
I did the prison system. But players can get out of it if you die.
I did this test here of the fact that the player would not receive damage:
function onDmg()
	if getElementData(source,'_inJail') == true then
		cancelEvent()
	end
end
addEventHandler('onPlayerDamage',root,onDmg)

But the player still takes damage from another player

How to fix it?

Sorry for my bad english

 
 
 
Posted (edited)
function onDmg()
	if getElementData(localPlayer,'_inJail') == true then
		cancelEvent()
	end
end
addEventHandler('onClientPlayerDamage',localPlayer,onDmg)

 

Edited by Walid
  • Like 2
Posted
15 minutes ago, Walid said:

function onDmg()
	if getElementData(localPlayer,'_inJail') == true then
		cancelEvent()
	end
end
addEventHandler('onClientPlayerDamage',localPlayer,onDmg)

 

<div id="inner-editor"></div>
 
 
 
 
the player will still take damage
Posted
2 minutes ago, dima3367 said:
<div id="inner-editor"></div>
 
 
 
 
 
the player will still take damage

Are you sure it's a client side ? and the player have data?

  • Like 1
Posted

 

1 minute ago, dima3367 said:

One moment please

Here is a very simple way to debug your code.

-- debug 
function onDmg()
    if isPlayerInJail(localPlayer) then
        outputChatBox("Yes it's") -- if you can't see this message in your chat box then you need to check if the element data ("_inJail") exist or not.
        cancelEvent()
    end
end
addEventHandler('onClientPlayerDamage',localPlayer,onDmg)

-- check if the player is in jail
function isPlayerInJail(player)
    if player and isElement(player) then
        local returns = getElementData(player,"_inJail") and true or false
        return returns
    end 
    return false
end 

 

  • Like 1
Posted
1 minute ago, dima3367 said:

Thank you very much for your help, everything turned out! Keep my likes to your posts!

You're welcome.

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