Player loadout on start?

I’m trying to learn lua by coding a simple gamemode, but i can’t get the player tp start with the right sweps.

This is the code i’m using now but it does’nt work so can some plz post a correct code?

function GM:PlayerLoadout( ply )
ply:StripWeapons( ply )

ply:Give("hl2_combo_fists")

ply:SelectWeapon("hl2_combo_fists")

return true

end

hook.Add( “PlayerLoadout”, “gravAndShot”, Loadout)

Well, there’s a couple things I could think of wrong here.

  1. There is no “ply” argument to player.StripWeapons. All you need is ply:StripWeapons().
  2. Are you sure you have a hl2_combo_fists swep?
  3. Is this in the right file?
  4. You don’t need to hook if you’re overriding it in your gamemode.

[lua]
function GM:PlayerLoadout( ply )

if( ply:Team() == 1 ) then

ply:StripWeapons()

ply:Give(“hl2_combo_fists”)
ply:SelectWeapon(“hl2_combo_fists”)

end

end
[/lua]

thanks!

but none of this worked… still spawning with: graitygun, crowbar, stunstik, smg, grenade and pistol…

i tried with that code but it won’t work…

It’s some other issue. Open up the console and paste in the lines around the COULDN’T LOAD GAMEMODE error in this thread.

I don’t get any errors in the console…

Where are you storing this code?

in the init.lua in gamemodes/mygamemodename/gamemode ^^

[lua]
function GM:PlayerLoadout( p )
if( p:Team() == 1 ) then
p:StripWeapons()
p:Give(“hl2_combo_fists”)
p:SelectWeapon(“hl2_combo_fists”)
end
self.BasClass:PlayerLoadout( p )
end
[/lua]

Are you overriding PlayerSpawn, by any chance?

sorry, new to lua so don’t know what “overriding” is :S

[editline]11:03PM[/editline]

did’nt work, i’m probebly making some other this wrong…

[editline]11:06PM[/editline]

Here’s my whole init.lua code so far

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

include( ‘shared.lua’ )

resource.AddFile(“models/weapons/w_fists_t.mdl”)
resource.AddFile(“models/weapons/w_fists_t.vvd”)
resource.AddFile(“models/weapons/w_fists_t.phy”)
resource.AddFile(“models/weapons/w_fists_t.sw.vtx”)
resource.AddFile(“models/weapons/w_fists_t.dx90.vtx”)
resource.AddFile(“models/weapons/w_fists_t.dx80.vtx”)
resource.AddFile(“models/weapons/v_punch.mdl”)
resource.AddFile(“models/weapons/v_punch.vvd”)
resource.AddFile(“models/weapons/v_punch.sw.vtx”)
resource.AddFile(“models/weapons/v_punch.dx90.vtx”)
resource.AddFile(“models/weapons/v_punch.dx80.vtx”)
resource.AddFile(“sound/weapons/fists/hl2_slash1.wav”)
resource.AddFile(“sound/weapons/fists/hl2_slash2.wav”)

// Serverside only stuff goes here

/---------------------------------------------------------
Name: gamemode:PlayerLoadout( )
Desc: Give the player the default spawning weapons/ammo
---------------------------------------------------------
/
function GM:PlayerSpawn( ply )
ply:SetGravity( 0, 1 )
ply:setMaxHealth( 100, true )
ply:SetWalkSpeed( 200 )
ply:SetRunSpeed( 300 )
end
end

function GM:PlayerLoadout( ply )
if( ply:Team() == 1 ) then
ply:StripWeapons()
ply:Give(“hl2_combo_fists”)
ply:SelectWeapon(“hl2_combo_fists”)
end
self.BasClass:PlayerLoadout( ply )
end

function GM:PlayerInitialSpawn ( ply )
self.BaseClass:PlayerInitialSpawn( ply )
if ply:IsAdmon() then
pl:PrintMessage( HUD_PRINTTALK, “Hello there admin!” )
end
end

function GM:GetFallDamage( ply, fspeed )

return ( fspeed / 8 )

end

function FirstSpawn( ply )

ply:PrintMessage(HUD_PRINTCENTER,"Welcome to Engborg's server!")

end

hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

if ply:IsAdmon() then

i think you missspelled that a bit it should be:
if ply:IsAdmin() then

haha, yeah thanks.

[editline]12:04AM[/editline]

i’ve fixed the other thing now but i’m not starting with the fists, i’m starting without any weapon at all.

You’re not called PlayerLoadout. You have too many ends as well. Change your PlayerSpawn function to:
[lua]function GM:PlayerSpawn( ply )

ply:SetGravity( 0, 1 )
ply:setMaxHealth( 100, true )
ply:SetWalkSpeed( 200 )
ply:SetRunSpeed( 300 )

GAMEMODE:PlayerLoadout( ply )

end[/lua]

I removed the second end you had (which is causing errors that prevent the file from loading) and called the loadout function.