Trying to write a script to enable god mode when exactly 2 players have died
1 replies, posted
Hi everyone!
I've been trying to tweak the Murder game mode in the Steam workshop so that I can tell the game to enable god mode for all players once 2 or more players have died. I would also like to be able to turn off god mode from the ulx menu after it's been enabled through this script.
Here's what I have so far:
function GM:PlayerDeathThink(ply)
if self:CanRespawn(ply) then
ply:Spawn()
else
self:ChooseSpectatee(ply)
end
if ply:Deaths() >= 2 then
for k, v in pairs( player.GetAll() ) do
v:GodEnable()
end
end
This is located in the sv_player.lua file in the Murder game mode. So far, this script makes it so that after one or more players are killed, god mode activates for all surviving players.... but I am also unable to disable god mode from the ulx menu... I suspect this might be because this script is constantly activating the god mode on a loop....
If anyone could please help point me in the right direction of making it so the god mode won't enable until TWO players have died... and that I can disable the god mode afterward during the same round, that'd pretty much make my month! Any help at all is greatly appreciated!
I've revised my function to be this instead and I'm seeing more progress than before:
function GM:PlayerDeath(ply, Inflictor, attacker )
self:DoRoundDeaths(ply, attacker)
if ply:Deaths() >= 3 then
for k, v in pairs( player.GetAll() ) do
v:GodEnable()
end
local ct = ChatText()
ct:Add(translate.GodModeEnabled)
ct:SendAll()
end
This fixed the looping issue. But now the problem is that the player death count still doesn't reset after each round, and whenever I turn off god mode, the next player death instantly turns it back on again due to this script.
Is there any way I can set the death count to reset itself to 0 after each round? And is there any way I can prevent this script from running when I've disabled the god mode from my ulx menu?
If anyone would like to assist or give any sort of input, I'd be very grateful.
Sorry, you need to Log In to post a reply to this thread.