Help, I'm unarmed!

I’m currently working on a game mode and for some reason my GM:PlayerLoadout is not being called and I get no errors. and the GM:OnNPCKilled works and it’s in the same file. I have read and looked, and I just don’t see what the problem is.

[lua]
function GM:PlayerLoadout( ply )

print("Player Loadout")
print(ply)

ply:Give("weapon_shotgun")
ply:GiveAmmo(60,"buckshot",true)

ply:Give("weapon_pistol")
ply:GiveAmmo(120,"Pistol",true)

ply:Give("weapon_ar2")
ply:GiveAmmo(160,"AR2",true)
ply:GiveAmmo(8,"AR2AltFire",true)

ply:Give("weapon_smg1")
ply:GiveAmmo(160,"SMG1",true)
ply:GiveAmmo(3, "SMG1_Grenade",true)

ply:Give("weapon_crowbar")

ply:Give("weapon_physcannon")

ply:Give("wepaon_physgun")

ply:SelectWeapon("weapon_physcannon")

end

[/lua]

Thanks for any help.

If you overwrite GM:PlayerSpawn then you need to call self:PlayerLoadout yourself

In your PlayerSpawn function make sure to call self.BaseClass.PlayerSpawn(self, ply).

Ok, well that makes sense, I was just messing with some stuff and found GM:PlayerSpawn is being called so I was just gonna give weapons in there, but now that i know I can fix it thanks.

Don’t just call PlayerLoadout in PlayerSpawn, this will prevent the loadout hooks from running, do what I posted earlier and PlayerLoadout and PlayerSetModel gamemode function and hooks will run correctly.

[editline]17th January 2011[/editline]

If you don’t want to call the base PlayerSpawn (I can’t think why) then you can **[Gamemode.Call

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Gamemode.Call)** PlayerLoadout yourself in your PlayerSpawn function.

Yea, i wasn’t planning on just calling it, I was gonna call the base of playerspawn like you suggested, just didn’t say it, anyway thank you for the information.

I like that the noobs (i’m actually an 05) says disagree when my post is 100% valid and correct.

You CAN call the base if you want, but if you’re making a custom gamemode you don’t need to use garry’s worthless base.

Also the way you called the base is dumb, should be self.BaseClass:PlayerSpawn(ply), metatables exist for a reason.

This has nothing to do with metatables (method calling with : can be used for normal table functions).
Calling it like that will pass self.BaseClass as the first argument to PlayerSpawn, which may work as intended in this case, but when any variables are set on the table, they will be set on the BaseClass gamemode table, not the current gamemode. Calling it the way that I posted will pass the current gamemode (self) not the base gamemode (self.BaseClass) as the first argument.

Your original post may have worked, but it would have fucked up any PlayerLoadout and PlayerSetModel hooks, preventing them from running.

Also, I am not a noob.

[editline]17th January 2011[/editline]

Since when did join date have anything to do with experience in Lua?

Couldn’t you just do GAMEMODE.PlayerLoadout(ply) ?

We have already discussed why you shouldn’t just call the PlayerLoadout function directly.

Thank you for your input, however, I do not think Garry’s code is worthless, it functions so it has worth, and calling the base class function is the proper way to do it, in any language, I just didn’t realize I needed to pass the call on myself.

Anyway thanks to everybody for your help and opinions.