Jump to content

Toggle invincibility


rusztamas

Recommended Posts

function halhatatlansag() 
    if getElementData(source, "halhatatlan", true) then 
        cancelEvent() 
    end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), halhatatlansag)

If you join the server, it sets your elementData(halhatatlansag) to true, but i still get damages, and my hp is going down... i'd like to do it like setElementData (source, "invincible", true) and setElementData (source, "invincible", false) so it would be like "toggleable" but i have no idea how to do that. Could you please help me?

Link to comment
1 minute ago, NeXuS™ said:

Replace line nr 2. with 


if getElementData(source, "halhatatlan") then 

Changed "true" with the default (true)? mmm
 

i would suggest posting the code where you set the data (on connect)
Also, you may add an outputchatbox that tells you the data value when the player gets damaged
Another advice, it could be better not binding the event to root but to localPlayer (so every player won't use it on other players, since they will have their own clientside script doing it)

  • Like 1
Link to comment

Buddy, you don't understand my post above at all.

He thought he wrote 

if getElementData(...) == true then

with

if getElementData(..., ..., true) then

So if he wanted to write

if getElementData(...) == false then

he would just write

if getElementData(..., ..., false) then

So before he thought that this is the way he would do it, I corrected his code, so he doesn't think that he is checking the elementdata with that true as the last argument.

Edited by NeXuS™
  • Like 1
Link to comment

Still getting damage. :( Script:
 

addEventHandler ("onPlayerJoin", getRootElement(), function()
	setElementData (source, "halhatatlan", true)
end
)

addCommandHandler ("am_i_halhatatlan", function()
	if setElementData (source, "halhatatlan", true) then
		outputChatBox ("#A1D490[King of the Kill]#FFFFFF Aha.", admin, 255, 255, 255, true)
	else
		outputChatBox ("#A1D490[King of the Kill]#FFFFFF Nem.", admin, 255, 255, 255, true)
	end
end
)

addCommandHandler ("disable_halhatatlan", function()
		if setElementData (source, "halhatatlan", false) then
		outputChatBox ("#A1D490[King of the Kill]#FFFFFF Kikapcsolva: halhatatlan.", admin, 255, 255, 255, true)
	end
end
)

function halhatatlansag() 
    if getElementData(source, "halhatatlan") then
		cancelEvent() 
    end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), halhatatlansag)

 

Link to comment

Server side

addEventHandler("onPlayerJoin", getRootElement(), function()
	setElementData(source, "halhatatlan", true)
end)

addEventHandler("onResourceStart", getResourceRootElement(), function()
	for i, k in ipairs(getElementsByType("player")) do
		setElementData(k, "halhatatlan", true)
	end
end)

Client side

function halhatatlansag() 
	if getElementData(source, "halhatatlan") then 
		cancelEvent() 
	end 
end 
addEventHandler("onClientPlayerDamage", localPlayer, halhatatlansag)

addCommandHandler("godmode", function()
	setElementData(localPlayer, "halhatatlan", not getElementData(localPlayer, "halhatatlan"))
	outputChatBox("#FF0000[INFO]#FFFFFF Halhatalanság " .. (getElementData(localPlayer, "halhatatlan") and "bekapcsolva" or "kikapcsolva") .. ".", 0, 0, 0, true)
end)

Works just totally fine for me.

Edited by NeXuS™
  • Like 1
Link to comment
39 minutes ago, NeXuS™ said:

Server side


addEventHandler("onPlayerJoin", getRootElement(), function()
	setElementData(source, "halhatatlan", true)
end)

addEventHandler("onResourceStart", getResourceRootElement(), function()
	for i, k in ipairs(getElementsByType("player")) do
		setElementData(k, "halhatatlan", true)
	end
end)

Client side


function halhatatlansag() 
    if getElementData(source, "halhatatlan") then 
        cancelEvent() 
    end 
end 
addEventHandler("onClientPlayerDamage", getRootElement(), halhatatlansag)

addCommandHandler("godmode", function()
	setElementData(localPlayer, "halhatatlan", not getElementData(localPlayer, "halhatatlan"))
	outputChatBox("#FF0000[INFO]#FFFFFF Halhatalanság " .. (getElementData(localPlayer, "halhatatlan") and "bekapcsolva" or "kikapcsolva") .. ".", 0, 0, 0, true)
end)

Works just totally fine for me.

it works thanks

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