Simple gamemode issue (probably an easy fix)

Hello,

First off, I am by no means good at Lua programming, I just picked it up again after about 8 months, and back then I still didn’t know as much as I would have liked to. Also, I apologise if I missed any other threads that ask the same question, but I did search and couldn’t find anything.

So here is my issue:
I followed the Wiki’s tutorial on how to build a simple gamemode from scratch, and it went well until I joined the gamemode on single player and noticed that I spawned with a crowbar, baton, smg, gravity gun and grenades.

I read online that you can fix the issue by stripping the player’s weapons before you give them the weapons that you want them to have, but the problem is that my gamemode is in teams, and I’m not sure where to take the weapons away.

I would imagine that the issue is easy to fix, but I’m too new to Lua to actually see it.

nl_init.lua

[lua]include(‘shared.lua’)

function set_team()

Ready = vgui.Create(“DFrame”)
Ready:SetPos(ScrW() / 2, ScrH() / 2)
Ready:SetSize(175, 75)
Ready:SetTitle(“Are you ready to join?”)
Ready:SetVisible(true)
Ready:SetDraggable(false)
Ready:ShowCloseButton(false)
Ready:MakePopup()

ready1 = vgui.Create(“DButton”, Ready)
ready1:SetPos(20, 25)
ready1:SetSize(140, 40)
ready1:SetText(“Hell yeah!”)
ready1.DoClick = function()
RunConsoleCommand(“sb_team1”)

end

end

concommand.Add(“sb_start”, set_team)[/lua]

init.lua

[lua]AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
AddCSLuaFile(“specialchars.lua”)

include(‘shared.lua’)
include(‘specialchars.lua’)

function GM:PlayerSpawn(ply)

self.BaseClass:PlayerSpawn(ply)
									
ply:SetGravity(1)  
ply:SetMaxHealth(100, true)  

ply:SetWalkSpeed(325)  
ply:SetRunSpeed(325) 

end

function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
if ply:IsAdmin() then 
	sb_team2(ply)
else
joining(ply)
RunConsoleCommand("sb_start")

end

function GM:PlayerLoadout(ply)

if ply:Team() == 1 then

	ply:Give("weapon_physcannon")
	ply:Give("weapon_physgun")
	ply:Give("weapon_camera")
	ply:Give("gmod_tool")


elseif ply:Team() == 2 then

	ply:Give("weapon_physcannon")
	ply:Give("weapon_physgun")
	ply:Give("weapon_AR2")
	ply:Give("weapon_camera")
	ply:Give("gmod_tool")

end

end

function sb_team1(ply)

ply:UnSpectate()
ply:SetTeam(1)
ply:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome to the server, " .. ply:Nick())

end

function sb_team2(ply)

ply:SetTeam(2)
ply:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome, we recognise you as an admin, " .. ply:Nick())

end
concommand.Add(“sb_team1”, sb_team1)

function joining(ply)

ply:Spectate(5)
ply:SetTeam(4)

end[/lua]

shared.lua

[lua]GM.Name = “easyBuild”
GM.Author = “N/A”
GM.Email = “N/A”
GM.Website = “N/A”

DeriveGamemode(“sandbox”)

team.SetUp(1, “Guest”, Color(125, 125, 125, 255))
team.SetUp(2, “Admin”, Color(255, 255, 255, 255))
team.SetUp(3, “SuperAdmin”, Color(148, 0, 211, 255))
team.SetUp(4, “Joining”, Color(0, 0 , 0, 255))[/lua]

specialchars.lua

[lua]function CheckSpecialCharacters(ply)

--SA 1
if (ply:SteamID() == "STEAM_0:0:26967041") then
 
	ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome back, " .. ply:Nick() .. "

You connected under the IP: " … ply:IPAddress())
ply:SetTeam(3)

	ply:Give("weapon_physcannon")
	ply:Give("weapon_physgun")
	ply:Give("gmod_tool")
    ply:Give("gmod_camera")
	
--SA 2
elseif (ply:SteamID() == "STEAM_0:0:4678674") then
		
	ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome to the server, " .. ply:Nick() .. "

You have connected under the IP: " … ply:IPAddress())
ply:SetTeam(3)

	ply:Give("weapon_physcannon")
	ply:Give("weapon_physgun")
	ply:Give("gmod_tool")
	ply:Give("gmod_camera")
		
end

end[/lua]

I apologise if the answer is blatantly clear.

EDIT:

I also don’t get ANY errors when in-game.

I also want to add that this gamemode has worked before, I don’t know what I did to break it though.

Try checking for errors. nl_init.lua?

Change in init.lua Line 23:
[lua]function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
if ply:IsAdmin() then
    sb_team2(ply)
else
joining(ply)
RunConsoleCommand("sb_start")

end
[/lua]
to
[lua]function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
if ply:IsAdmin() then
    sb_team2(ply)
else
joining(ply)
RunConsoleCommand("sb_start")
end

end
[/lua]

You was missing an end.

And add an Admin check on to SetTeam2
[lua]
function sb_team2(ply)
if ply:IsAdmin() then
ply:SetTeam(2)
ply:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome, we recognise you as an admin, " … ply:Nick())
end
end
concommand.Add(“sb_team1”, sb_team1)[/lua]

Ahg, I was right, super easy reason to understand… thanks, RetTurtl3!
Much appreciated.

Thanks for your input too, yoBrelliKX. :slight_smile:

EDIT:

There’s actually another issue, when I join the server, I should be different to the admin user group, as I’m in a different group, but it welcomes me as admin, I guess I need to do another check somewhere?
Though, the gamemode now works. :stuck_out_tongue:

Replace my init.lua with yours

[lua]AddCSLuaFile(“cl_init.lua”)
AddCSLuaFile(“shared.lua”)
AddCSLuaFile(“specialchars.lua”)

include(‘shared.lua’)
include(‘specialchars.lua’)

function GM:PlayerSpawn(ply)

self.BaseClass:PlayerSpawn(ply)
                                     
ply:SetGravity(1)  
ply:SetMaxHealth(100, true)  

ply:SetWalkSpeed(325)  
ply:SetRunSpeed(325) 

end

function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
sb_team2(ply)
if !ply:IsAdmin() and 
!ply:IsSuperAdmin() and 
!ply:SteamID() == "STEAM_0:0:26967041" and 
!ply:SteamID() == "STEAM_0:0:4678674" then  //Don't switch these people to spectate
joining(ply)
end
RunConsoleCommand("sb_start")

end

function GM:PlayerLoadout(ply)

if ply:Team() == 1 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")


elseif ply:Team() == 2 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_AR2")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")
 
end

end

function sb_team1(ply)

ply:UnSpectate()
ply:SetTeam(1)
ply:Spawn()
ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome to the server, " .. ply:Nick())

end
concommand.Add(“sb_team1”, sb_team1)

function sb_team2(ply)

if ply:IsAdmin() then
	ply:SetTeam(2)
	ply:Spawn()
	ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome, we recognise you as an admin, " .. ply:Nick())
elseif ply:IsSuperAdmin() || ply:SteamID() == "STEAM_0:0:26967041" || ply:SteamID() == "STEAM_0:0:4678674" then 
	ply:SetTeam(3)
	ply:Spawn()
	ply:PrintMessage(HUD_PRINTTALK, "[easyBuild]Welcome, we recognise you as an SuperAdmin, " .. ply:Nick())
end 

end

function joining(ply)

ply:Spectate(5)
ply:SetTeam(4)

end[/lua]

Thanks, I’ll give it a spin, I guess it’s good that I understand all of it, right? :stuck_out_tongue:

Whoops just saw an major error.
Change on Line 23
[lua]
function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
sb_team2(ply)
if !ply:IsAdmin() and
!ply:IsSuperAdmin() and
!ply:SteamID() == "STEAM_0:0:26967041" and
!ply:SteamID() == "STEAM_0:0:4678674" then  //Don't switch these people to spectate
joining(ply)
end
RunConsoleCommand("sb_start")

end
[/lua]
To
[lua]function GM:PlayerInitialSpawn(ply)

CheckSpecialCharacters(ply)
sb_team2(ply)
if !ply:IsAdmin() and
!ply:IsSuperAdmin() and
!ply:SteamID() == "STEAM_0:0:26967041" and
!ply:SteamID() == "STEAM_0:0:4678674" then  //Don't switch these people to spectate
joining(ply)
end
ply:ConCommand("sb_start") // We want to execute to client not server, Duhhh.

end
[/lua]

And Line 37

[lua]function GM:PlayerLoadout(ply)

if ply:Team() == 1 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")


elseif ply:Team() == 2 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_AR2")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")
  
end

end[/lua]

[lua]
function GM:PlayerLoadout(ply)

if ply:Team() == 1 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")


elseif ply:Team() == 2 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_AR2")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")
  
elseif ply:Team() == 3 then

    ply:Give("weapon_physcannon")
    ply:Give("weapon_physgun")
    ply:Give("weapon_AR2")
    ply:Give("weapon_camera")
    ply:Give("gmod_tool")
  
end

end[/lua]