Files
garrysmod-coop/gamemode/noheadcrabs.lua
T
2026-09-06 14:38:17 +02:00

46 lines
2.1 KiB
Lua

headcrabsdontexist = false
function NoHeadcrabs(bool)
if(bool) then headcrabsdontexist = true end
if(!bool) then headcrabsdontexist = false end
end
local function RemoveCrabsTick()
if(headcrabsdontexist) then
local Crabs = table.Add( table.Add( table.Add( table.Add( ents.FindByClass( "npc_headcrab" )), ents.FindByClass( "npc_headcrab_fast" ) ), ents.FindByClass( "npc_headcrab_black" ) ), ents.FindByClass( "npc_headcrab_poison" ))
local Zombies = table.Add(table.Add( table.Add( table.Add( table.Add( ents.FindByClass("npc_zombie_torso"), ents.FindByClass( "npc_zombie" )), ents.FindByClass( "npc_fastzombie" ) ), ents.FindByClass( "npc_zombine" ) ), ents.FindByClass("npc_fastzombie_torso")), ents.FindByClass("npc_poisonzombie"))
for _, crab in pairs( Crabs ) do
SafeRemoveEntity( crab )
end
for k, zombie in pairs( Zombies ) do
zombie:SetBodygroup(1,0)
zombie:SetBodygroup(2,0)
zombie:SetBodygroup(3,0)
zombie:SetBodygroup(4,0)
end
end
end
hook.Add( "Tick", "NoHeadcrabsTick", RemoveCrabsTick )
local function HeadcrabsStay(ent,dmg)
if(headcrabsdontexist) then
if (IsValid(ent) && ((ent:GetClass() == "npc_zombie") || (ent:GetClass() == "npc_zombine") || (ent:GetClass() == "npc_fastzombie") || (ent:GetClass() == "npc_zombie_torso") || (ent:GetClass() == "npc_fastzombie_torso") || (ent:GetClass() == "npc_poisonzombie"))) then
--Get zombie data
local Data = ent:GetSaveTable()
--Check if this shot will kill them
local HP = ent:Health()
if dmg:GetDamage()>=HP then
--We will die, change things that we need to to prevent headcrabs
--increase damage to prevent headcrabs if needed
local MaxHP = Data.max_health or 100
if dmg:GetDamage()<MaxHP then
dmg:SetDamage(MaxHP*2) --Increase damage to ensure no headcrab (this _should_ only need to be >= 25% of MaxHP)
end
dmg:SetDamageType(DMG_SLASH)
--Return modified damage
return dmg
end
end
end
end
hook.Add("EntityTakeDamage", "Headcrabs Stay", HeadcrabsStay)