Files
garrysmod-coop/gamemode/shared.lua
T

183 lines
4.7 KiB
Lua
Raw Normal View History

2026-09-06 14:38:17 +02:00
GM.Name = "Feedc0de's coop Mode"
GM.Author = "0xFEEDC0DE64"
GM.Email = "daniel@brunner.ninja"
GM.Website = "brunner.ninja"
2026-09-06 16:38:42 +02:00
DeriveGamemode("sandbox")
include( "levels.lua" )
include( "progression_shared.lua" )
2026-09-06 14:38:17 +02:00
if (SERVER) then
2026-09-06 14:38:38 +02:00
function ChangeRandomLevel()
local randomLevel = GetRandomLevel()
if not randomLevel then
ErrorNoHalt("[custom_coop] No other installed coop map was found in levels.lua\n")
return false
end
print("[custom_coop] Changing to random level " .. randomLevel)
RunConsoleCommand("changelevel", randomLevel)
return true
end
function NextRandomLevel()
local randomLevel = GetRandomLevel()
if not randomLevel then
ErrorNoHalt("[custom_coop] Cannot set nextlevel: no other installed coop map was found\n")
return nil
end
print("[custom_coop] Setting nextlevel to " .. randomLevel)
RunConsoleCommand("nextlevel", randomLevel)
return randomLevel
end
2026-09-06 14:38:17 +02:00
concommand.Add("randomlevel", ChangeRandomLevel)
concommand.Add("randomnextlevel", NextRandomLevel)
2026-09-06 14:38:38 +02:00
hook.Add("Initialize", "SetupRandomLevels", function()
timer.Simple(0, NextRandomLevel)
end)
end
2026-09-06 14:38:17 +02:00
-- timer.Simple(
-- 1,
-- function()
-- function HideThings(name)
-- if (name == "CHudDamageIndicator" or name == "CHudHintDisplay") then
-- return false
-- end
-- end
-- hook.Add("HUDShouldDraw", "HideThings", HideThings)
-- end
-- )
function GM:IsSpawnpointSuitable(ply, spawnpointent, bMakeSuitable)
local Pos = spawnpointent:GetPos()
-- Note that we're searching the default hull size here for a player in the way of our spawning.
-- This seems pretty rough, seeing as our player's hull could be different.. but it should do the job
-- ( HL2DM kills everything within a 128 unit radius )
local Ents = ents.FindInBox(Pos + Vector(-16, -16, 0), Pos + Vector(16, 16, 72))
if (ply:Team() == TEAM_SPECTATOR or ply:Team() == TEAM_UNASSIGNED) then
return true
end
local Blockers = 0
for k, v in pairs(Ents) do
if (IsValid(v) and v:GetClass() == "player" and v:Alive()) then
Blockers = Blockers + 1
if (bMakeSuitable) then
v:SetVelocity(v:GetPos() + Vector(100, 100, 0))
end
end
end
if (bMakeSuitable) then
return true
end
if (Blockers > 0) then
return false
end
return true
end
2026-09-06 17:24:07 +02:00
local hl2dmLoadout
if SERVER then
hl2dmLoadout = CreateConVar(
"gc_hl2dmloadout",
"1",
FCVAR_ARCHIVE,
"Give the standard HL2 Deathmatch spawn weapons expected by legacy coop maps"
)
end
function GM:PlayerLoadout(ply)
if striponspawn then return end
ply:Give("weapon_fists")
if not hl2dmLoadout or not hl2dmLoadout:GetBool() then return end
-- Legacy HL2DM coop maps commonly place ammo for these weapons but rely on
-- CHL2MP_Player::GiveDefaultItems to supply the weapons themselves.
ply:Give("weapon_crowbar")
ply:Give("weapon_pistol")
ply:Give("weapon_smg1")
ply:Give("weapon_frag")
ply:Give("weapon_physcannon")
ply:GiveAmmo(255, "Pistol", true)
ply:GiveAmmo(45, "SMG1", true)
ply:GiveAmmo(1, "Grenade", true)
ply:GiveAmmo(6, "Buckshot", true)
ply:GiveAmmo(6, "357", true)
end
2026-09-06 14:38:17 +02:00
hook.Add( "SpawnMenuOpen", "DisallowSpawnMenu", function ()
return LocalPlayer():IsAdmin()
end)
hook.Add( "ContextMenuOpen", "DisallowSpawnMenu", function ()
return LocalPlayer():IsAdmin()
end)
function GM:PlayerNoClip(ply, desiredState)
if desiredState then
return ply:IsAdmin()
else
return true
end
end
function GM:PlayerDeathSound()
return true
end
function GM:DrawDeathNotice(x, y)
return false
end
function GM:PlayerSpawnVehicle(ply, model, name, table)
return ply:IsAdmin()
end
function GM:PlayerSpawnSWEP(ply, weapon, info)
return ply:IsAdmin()
end
function GM:PlayerSpawnSENT(ply, class)
return ply:IsAdmin()
end
function GM:PlayerSpawnRagdoll(ply, model)
return ply:IsAdmin()
end
function GM:PlayerSpawnProp(ply, model)
return ply:IsAdmin()
end
function GM:PlayerSpawnObject(ply, model, skin)
return ply:IsAdmin()
end
function GM:PlayerSpawnNPC(ply, npc_type, weapon)
return ply:IsAdmin()
end
function GM:PlayerSpawnEffect(ply, model)
return ply:IsAdmin()
end
function GM:PlayerGiveSWEP(ply, weapon, swep)
return ply:IsAdmin()
end
--function GM:HUDAmmoPickedUp( item, amount )
-- return false;
--end