Editing player loadout

So I’m working on a gamemode (not a remake/redo of DarkRP or a RP for that matter) and I want the player to spawn with only a crowbar.

So far I spawn with the crowbar, grav gun, pistol, .357, smg, and shotgun. Not with the toolgun or physgun.

The main spawn menu is also disabled (the “q” menu). This is a good thing, but I only want the crowbar.

Here is my half-assed attempts at trying to do so in my init.lua file. I would appreciate someone pointing me in the right direction.

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

function GM:PlayerSpawn( ply )

self.BaseClass:PlayerSpawn( ply)

self.StripWeapons() //attempt to get only crowbars
self.Give( "weapon_crowbar" ) //attempt to get only crowbars

ply:SetGravity( 0.75 )
ply:SetMaxHealth( 100, true )

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

end

function GM:PlayerInitialSpawn( ply )
self.StripWeapons() //attempt to get only crowbars
joining( ply )
RunConsoleCommand( “sb_start” )
end
end

function GM:PlayerLoadout( ply )

self.StripWeapons() //attempt to get only crowbars

ply:Give( "weapon_crowbar" ) //attempt to get only crowbars

end

function sb_team1( ply )

ply:UnSpectate()
ply:SetTeam( 1 )
ply:Spawn()

ply:StripWeapons() //attempt to get only crowbars
ply:Give( "weapon_crowbar" ) //attempt to get only crowbars

end

concommand.Add( “sb_team1”, sb_team1 )

function joining( ply )

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

end
[/lua]

Replace self.StripWeapons(), self.Give(), etc by ply:StripWeapons(), ply:Give() and so on. When you use self, you are referencing GM (in this case). That’s not what you want to do. You want to call these functions on the player object (the argument ply).

Would I need to define ply as local player by using:

[lua]ply = LocalPlayer()[/lua]

?

Trying it out without

not unless your doing something clientside.

So I went ahead and replaced all the self.StripWeapons and self.Give( “weapon_crowbar” ) with ply:StripWeapons and ply:Give( “weapon_crowbar” ).

It still has the same result.

self.StripWeapons()
to
self:StripWeapons()

self.Give( “weapon_crowbar” )
to
self:Give( “weapon_crowbar” )

On your code, where are you pulling self from? You have it referenced 5 times, but not declared anywhere.

Wait actually Yeah. replace self with ply.

I have no idea where I was pulling self from, I assumed it was already declared. Also I attempted Freze’s old suggestion and the same result. I have scanned the console after load for any errors and still none.

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

function GM:PlayerSpawn( ply )

self.BaseClass:PlayerSpawn( ply)
 
ply:StripWeapons() //attempt to get only crowbars
ply:Give( "weapon_crowbar" ) //attempt to get only crowbars
 
ply:SetGravity( 0.75 )
ply:SetMaxHealth( 100, true )
 
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 325 )

end

function GM:PlayerInitialSpawn( ply )
ply:StripWeapons() //attempt to get only crowbars
joining( ply )
RunConsoleCommand( “sb_start” )
end
end

function GM:PlayerLoadout( ply )

ply:StripWeapons() //attempt to get only crowbars

ply:Give( "weapon_crowbar" ) //attempt to get only crowbars

end

function sb_team1( ply )

ply:UnSpectate()
ply:SetTeam( 1 )
ply:Spawn()
 
ply:StripWeapons() //attempt to get only crowbars
ply:Give( "weapon_crowbar" ) //attempt to get only crowbars

end

concommand.Add( “sb_team1”, sb_team1 )

function joining( ply )

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

end[/lua]

Should work?

The spawn and loadout logic should be separate.

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

function GM:PlayerSpawn(ply)
– Do spawn logic here

self.BaseClass.PlayerSpawn(self, ply) -- Call the base gamemode PlayerSpawn function using this gamemode table

end

function GM:PlayerInitialSpawn(ply)
– Do initial spawn logic here

self.BaseClass.PlayerInitialSpawn(self, ply) -- Call the base gamemode PlayerInitialSpawn function using this gamemode table

end

function GM:PlayerLoadout(ply)
ply:Give(“weapon_crowbar”)
end[/lua]

I had something like that set up at first, then I started throwing ply:StripWeapon() and
ply:Give( “weapon_crowbar” ) everywhere.

I think your problem may have been that you were calling the base gamemode PlayerSpawn (and PlayerInitialSpawn) function incorrectly. ie
[lua]self.BaseClass:PlayerSpawn(ply)[/lua]
should be
[lua]self.BaseClass.PlayerSpawn(self, ply)[/lua]

I think you are correct. This is my first experience in gamemode programming. Will try that when I can. Thanks!

Testing now

[editline]5th January 2011[/editline]

Mein automerge!

Test unsuccessful, do you think it may be a conflicting add-on. I do not have pointsmod installed.

No don’t need need to strip the weapons if you are editing the hook directily( GM: ).

ply:Give(“weapon_crowbar”) is all you need, put that in playerloadout only and your good, also make sure to call self.BaseClass:PlayerSpawn( ply ) in playerspawn, or the loadout and setmodel hooks will not be called.

This should work:

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

function GM:PlayerSpawn( ply )

ply:SetGravity( 0.75 )
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 325 )
ply:SetRunSpeed( 325 )

self.BaseClass:PlayerSpawn( ply )

end

function GM:PlayerInitialSpawn( ply )
joining( ply )
RunConsoleCommand( “sb_start” )
end

function GM:PlayerLoadout( ply )
if ( ply:Team() == 4 ) then
ply:Give( “weapon_crowbar” );
else
– nothing.
end
end

function sb_team1( ply )
ply:UnSpectate()
ply:SetTeam( 1 )
ply:Spawn()
end
concommand.Add( “sb_team1”, sb_team1 )

function joining( ply )
ply:Spectate( 5 )
ply:SetTeam( 4 )
end
[/lua]

You should call self.BaseClass.PlayerSpawn(self, ply) else the base playerloadout function will be called, not the derived one.

[editline]6th January 2011[/editline]

Actually, that isn’t true. The PlayerLoadout function is called with hook.Call, therefore the most derived PlayerLoadout will be called.

[editline]6th January 2011[/editline]

But this doesn’t mean that you should call the BaseClass functions as you have, you should call them the way I showed so that any modification to the gamemode table (variable assignment etc) occurs on the derived gamemode table.

LuaScript, is setting a team before loadout then checking for it the proper/only way to do this? And I know this is unrelated but I can play a sound on the player after self.BaseClass.PlayerSpawn( ply ) or would that need to be clientside?

[editline]6th January 2011[/editline]

Also, what is the purpose of sb_start? Is this giving me the weapons default to sandbox?

[editline]6th January 2011[/editline]

Sorry, this extra post is to subscribe to my email.