Hi, I’m doing a menu which includes a toggle item for invincibility
I’m sure that the menu is working because I’ve tried with other things, but the invincibility doesn’t work
Here’s the code that I’ve used:
I made a notify text to be sure that there are no problems in toggling, but with this code I’m still dying when I take damage. Am I invulnerable to everybody (like npcs), aren’t I? Or am I invulnerable only to other players?
local isInvincible = false
local Item3 = NativeUI.CreateCheckboxItem("Diventa invincibile", bool, "Attiva/disattiva l'invincibilità")
submenu.OnCheckboxChange = function(sender, item, checked_)
if item == Item3 then
bool = checked_
Citizen.Wait(0.2)
isInvincible = not isInvincible
SetEntityInvincible(PlayerPedId(), isInvincible)
text = (tostring(isInvincible))
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(true, true)
end
end
When I activate the invincibility, the first notification (bool value) returns “true” and the second notification returns “1”, but I can still die (I’ve tried getting off a high roof).
I found out, that vMenu was blocking this native for me (I think vMenu sets the Invincibility for each frame…). Do you use vMenu? It might be the problem.
EDIT: Forgot to mention this. There is a way around this - not very elegant, but it works. Use the native in a loop. Example:
local isInvincible = false
function toggleInvincible()
isInvincible = not isInvincible
end
RegisterCommand(
'godmode',
toggleInvincible,
false
)
Citizen.CreateThread(
function()
while true do
Wait(0)
if isInvincible then
SetPlayerInvincible(PlayerId(), isInvincible)
else
Wait(5000) -- The player isn't invincible, let the thread rest a little :D
end
end
end
)
The better, but more time-consuming solution would be editing the vMenu and compiling it yourself. (You can find the relevant file here)