Skip to content

Commit

Permalink
Mother zombie infection (#80)
Browse files Browse the repository at this point in the history
* Add a cvar to rely on cs2fixes' team switching

* Move the team switching to round_prestart

* Change round_end to cs_pre_restart

* Add SetTeam(None) before force team change

* Move mz infection to a new function

* don't need this anymore

* stylua format

---------

Co-authored-by: xen <[email protected]>
  • Loading branch information
EasterLee and xen-000 authored Oct 16, 2023
1 parent 0e9be26 commit 4e49590
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
5 changes: 5 additions & 0 deletions scripts/vscripts/ZombieReborn.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ function OnPlayerSpawn(event)
--__DumpScope(0, event)
local hPlayer = EHandleToHScript(event.userid_pawn)

-- Player turned into mother zombie
if tMZList[hPlayer] then
return
end

-- Infect late spawners & change mother zombie who died back to normal zombie
-- Also don't do this if the player spawns as a spectator
if hPlayer:GetTeam() >= CS_TEAM_T and ZR_ZOMBIE_SPAWNED and tCureList[hPlayer] == nil then
Expand Down
43 changes: 35 additions & 8 deletions scripts/vscripts/ZombieReborn/Infect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,43 @@ function Infect(hInflictor, hInfected, bKeepPosition, bDead)
hInfected:TakeDamage(cDamageInfo)
DestroyDamageInfo(cDamageInfo)
else
DebugPrint("Infected player has spawned late or was chosen as a mother zombie")
DebugPrint("Infected player has spawned late")
end

hInfected:SetTeam(CS_TEAM_T)
if ZR_ZOMBIE_SPAWNED == false then
DebugPrint("Setting mother zombie class")
InjectPlayerClass(ZRClass.Zombie.MotherZombie, hInfected)
else
DebugPrint("Setting regular zombie class")
InjectPlayerClass(PickRandomZombieDefaultClass(), hInfected)

DebugPrint("Setting regular zombie class")
InjectPlayerClass(PickRandomZombieDefaultClass(), hInfected)

if bKeepPosition == false then
DebugPrint("Infection is not in-place")
return
end
hInfected:SetOrigin(vecOrigin)
hInfected:SetAngles(vecAngles.x, vecAngles.y, vecAngles.z)
end

tMZList = {}
function InfectMotherZombie(hInfected, bKeepPosition)
DebugPrint("Infecting a player to mother zombie")

if hInfected:GetHealth() == 0 then
--Infect was called on a spectator somehow during initial infection, nope out
print("Attempted to infect a spectator!")
return
end

local vecOrigin = hInfected:GetOrigin()
local vecAngles = hInfected:EyeAngles()

tMZList[hInfected] = true
hInfected:SetTeam(CS_TEAM_NONE)
hInfected:SetTeam(CS_TEAM_T)

DebugPrint("Setting mother zombie class")
InjectPlayerClass(ZRClass.Zombie.MotherZombie, hInfected)

tMZList[hInfected] = nil
if bKeepPosition == false then
DebugPrint("Infection is not in-place")
return
Expand All @@ -58,6 +83,7 @@ function Cure(hPlayer, bKeepPosition)
local vecAngles = hPlayer:EyeAngles()

tCureList[hPlayer] = true
hPlayer:SetTeam(CS_TEAM_NONE)
hPlayer:SetTeam(CS_TEAM_CT)
InjectPlayerClass(PickRandomHumanDefaultClass(), hPlayer)
tCureList[hPlayer] = nil
Expand Down Expand Up @@ -163,7 +189,8 @@ function Infect_PickMotherZombies()
if Convars:GetInt("zr_infect_spawn_crash_fix") == 1 then
DoEntFireByInstanceHandle(player, "SetHealth", "0", 0.01, nil, nil)
else
Infect(nil, player, bSpawnType, false)
-- add a small delay between each just to be extra safe
DoEntFireByInstanceHandle(player, "RunScriptCode", "InfectMotherZombie(thisEntity, " .. tostring(bSpawnType) .. ")", 0.05 * index, nil, nil)
end
end
print("Player count: " .. iPlayerCount .. ", Mother Zombies Spawned: " .. iMotherZombieCount)
Expand Down
34 changes: 0 additions & 34 deletions scripts/vscripts/ZombieReborn/PlayerClass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,37 +161,3 @@ end
--table.dump(ZRClass.Human)
--print("Zombie Class: ")
--table.dump(ZRClass.Zombie)

--For Mappers/Server Operator that want more for their class
--ent_fire !self runscriptcode "InjectPlayerClass(ZRClass.Human.Admin, thisEntity)"
--shoot or ent_fire !self runscriptcode "thisEntity:LaunchGrenade()"
--ent_fire !self runscriptcode "InjectPlayerClass(ZRClass.Human.Base, thisEntity)" to restore
--[[
local CPlayerAdmin = {
health = 9999999,
speed = 1,
scale = 5,
gravity = 0,
color = {
r = 0, g = 0, b = 0
}
}
AddHumanClass(CPlayerAdmin, "Admin")
function CPlayerAdmin:LaunchGrenade()
local hEnt = SpawnEntityFromTableSynchronous("hegrenade_projectile", {
origin = self:EyePosition(),
basevelocity = self:EyeAngles():Forward() * 500
})
DoEntFireByInstanceHandle(hEnt, "InitializeSpawnFromWorld", "", 0, nil, nil);
end
local OnWeaponFired = function(event)
local hPlayer = EHandleToHScript(event.userid_pawn)
if hPlayer:IsInstance(CPlayerAdmin) then
hPlayer:LaunchGrenade()
end
end
CPlayerAdmin.weapon_fire = ListenToGameEvent("weapon_fire", OnWeaponFired, nil)
--]]

--Doesn't support extending custom class on top of each other right now/

0 comments on commit 4e49590

Please sign in to comment.