I have been getting this error (no I’m not using the usermsg library, unless PrintMessage does) every tick when running this test gamemode I’ve been brewing up.
I’m fairly new to making gamemodes so please be open minded when viewing.
(Note: The sniper rifle has been replaced with a pistol for testing purpouses.)
Join Message: (Uses ply:PrintMessage() )
“Welcome to Sniper Party! Crowbars will kill instantly, but the same can only be said with your sniper if you hit your target’s head. Otherwise, they will be able to see you through walls! During the first 40 seconds (you will be spectating this round if you joined afterwards) you are invincible!” (Maybe a culprit for the error)
init.lua
sniperparty_isinvincible = true;
local aliveplayers = {};
local deadplayercount = 0;
local start_time = CurTime()
local game_time = 0;
local dev = true;
local dotimesend = false;
local function endgamesequence(ply)
local player = ply;
local winnerexists = true;
if ply == nil then
winnerexists = false;
elseif !ply:IsValid() then
winnerexists = false;
end
if winnerexists then
PrintMessage(HUD_PRINTCENTER, ply:Nick() .. " is victorious! Restarting in 10 seconds...")
else
PrintMessage(HUD_PRINTCENTER, "Time is up! Nobody has won. Boo Hoo. Restarting in 10 seconds...")
end
sniperparty_isinvincible = true;
timer.Simple(10, function()
local maplist = file.Find("../maps/*.bsp");
local size = #maplist
local text = ("changelevel " .. maplist[math.random(1, size)] .. "
")
game.ConsoleCommand(text)
end )
end
function playerSetSpeed(ply)
givethings(ply)
ply:SetMaxSpeed(130)
end
function playerSetSpeedNorm(ply)
ply:SetMaxSpeed(500)
end
util.AddNetworkString("playerwallthru")
util.AddNetworkString("SetTime")
function GM:PlayerLoadout(ply)
givethings(ply)
end
function givethings(ply)
ply:StripWeapons()
ply:Give("weapon_crowbar")
ply:Give("weapon_pistol")
end
local invincibilitytimer = start_time + 40
hook.Add("InitPostEntity", "DoTimers", function()
timer.Simple(40, function()
sniperparty_isinvincible = false;
PrintMessage( HUD_PRINTCENTER, "Players are no longer invincible!'")
invincibilitytimer = nil;
end )
end )
hook.Add("Think", "sniperpartychecks", function()
for k,v in pairs(player.GetAll()) do
if !v:Alive() then return end
local typeam = v:GetActiveWeapon():GetPrimaryAmmoType()
v:SetAmmo(20, typeam)
if !table.HasValue( aliveplayers, v ) then
table.Add( aliveplayers, {v} )
end
end
deadplayercount = table.Count( player.GetAll() ) - table.Count( aliveplayers )
if table.Count(aliveplayers) == 1 then
endgamesequence(aliveplayers[1])
end
if (invincibilitytimer == 20) then
PrintMessage( HUD_PRINTCENTER, "20 Seconds of Invincibility left!")
end
if (invinicibilitytimer == 5) then
timer.Create("5secinvincibility", 1, 4, function()
local text = ( tostring(invincibilitytimer) .. " Seconds of Invincibility left!" )
PrintMessage( HUD_PRINTCENTER, "20 Seconds of Invincibility left!")
end )
end
if (invincibilitytimer == nil) then
game_time = ( CurTime() + 180 )
timer.Create("gametimer", 1, 0, function()
if (game_time == CurTime()) then
game_time = nil;
timer.Remove("gametimer")
return end
if dotimesend then
net.Start("SetTime")
net.WriteInt(game_time, 32)
net.Send( player.GetAll() )
end
end )
end
if (game_time == nil) then
endgamesequence(nil)
end
end )
hook.Add("SetupMove", "GiveInfoSniperParty", function(ply, mv, cmd)
ply:PrintMessage( HUD_PRINTCENTER, "Welcome to Sniper Party! Crowbars will kill instantly, but the same can only be said with your sniper if you hit your target's head. Otherwise, they will be able to see you through walls! During the first 40 seconds (you will be spectating this round if you joined afterwards) you are invincible!")
if (sniperparty_isinvincible == false) then
ply:Spectate(OBS_MODE_ROAMING)
end
end )
hook.Add("PlayerSay", "forcerespawn", function(sen, txt, tchat)
if dev then
if (txt=="frspawn") then
sen:UnLock()
sen:Spawn()
end
end
end )
hook.Add( "PlayerSpawn", "playerSetSpeedtest", playerSetSpeed )
function revealply(att, vic)
if !vic:Alive() then return end
net.Start("playerwallthru")
net.WriteEntity(att)
net.Send(vic)
playerSetSpeedNorm(vic)
att:ChatPrint("You have been seen!")
end
hook.Add("PlayerInitialSpawn", "modelsethitbox", function(ply)
ply:SetModel("models/player/police.mdl")
end )
function ScaleDamage( ply, hitgroup, dmginfo )
if sniperparty_isinvincible then
dmginfo:ScaleDamage( -1 )
return end
local att = dmginfo:GetAttacker()
if att:IsPlayer() then
revealply(att, ply)
else
dmginfo:ScaleDamage( 9999999 )
return end
if ( hitgroup == HITGROUP_HEAD || att:GetClass() == "npc_zombie" ) then
dmginfo:ScaleDamage( 9999999 )
elseif !(att:GetActiveWeapon():GetClass() == "weapon_crowbar") then
dmginfo:ScaleDamage( -1 )
else
dmginfo:ScaleDamage( 9999999 )
end
end
hook.Add("ScaleNPCDamage","ScaleNPCHeadshotDAM",function(npc,hit,inf)
local att = inf:GetAttacker()
if hit == HITGROUP_HEAD or (att:GetActiveWeapon():GetClass() == "weapon_crowbar") then
inf:ScaleDamage( 9999999 )
else
inf:ScaleDamage( -1 )
end
end)
hook.Add("ScalePlayerDamage","ScaleDamage",ScaleDamage)
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:Lock()
ply:CreateRagdoll()
ply:AddDeaths( 1 )
table.remove( aliveplayers, ply )
if ( attacker:IsValid() && attacker:IsPlayer() ) then
if !( attacker == ply ) then
attacker:AddFrags( 1 )
else
ply:KillSilent()
ply:UnLock()
return end
else
if attacker:IsValid() && !attacker:IsWorld() then
ply:Spectate(OBS_MODE_CHASE)
ply:SpectateEntity(attacker)
end
ply:UnLock()
return end
ply:Spectate(OBS_MODE_IN_EYE)
ply:SpectateEntity(attacker)
timer.Simple(2, function()
if ply:IsValid() then
ply:SetObserverMode(OBS_MODE_ROAMING)
end
end )
end
cl_init.lua
net.Receive("playerwallthru", function()
halo.Add( {net.ReadEntity()}, Color( 255, 0, 0 ), 5, 5, 1, true, true )
end )
local msgtime = nil;
net.Receive("SetTime", function()
msgtime = net.ReadInt(32)
end )
surface.CreateFont( "coolvetica", ScreenScale(30), 400, true, false, "HUDFONT" ) -- You don't have to create it on every frame.
local function TimeHud()
if !IsValid( msgtime ) then return end
local time = msgtime - CurTime() -- The current time minus the time the player got when the usermessage was sent.
surface.SetTextColor( 255, 255, 255, 255 )
surface.SetTextPos( 34, ( ScrH() / 12 ) + ( ScrH() / 14 ) )
surface.SetFont( "HUDFONT" )
surface.DrawText( time )
end
hook.Add( "HUDPaint", "draw_time", TimeHud )