• How to use player classes in gamemode?
    11 replies, posted
I used Garry's player class tutorial to make classes in my gamemode and he mentioned that they have to be loaded in shared.lua. I tried using "include(player_class/~classname.lua~") but I didn't spawn as the appropriate class. Can someone tell me how to make the gamemode recognize player classes?
Why do you want to use classes btw. ?
Because I want to make a gamemode with individual classes that players can choose from (?)
Are you calling [URL="http://wiki.garrysmod.com/page/player_manager/SetPlayerClass"]player_manager.SetPlayerClass[/URL] with your new class?
Yes, under PlayerSpawn
Show all of your code, we can't help you otherwise.
shared.lua [lua] GM.Name = "TAG" GM.Author = "McManager" GM.Email = "N/A" GM.Website = "N/A" include("player_class/player_default.lua") [/lua] init.lua [lua] function GM:PlayerInitialSpawn(ply) player_manager.SetPlayerClass(ply, "player_default") end function GM:PlayerSpawn(ply) local mobspawn = ents.FindByClass("spawn_mob") local humspawn = ents.FindByClass("spawn_hum") player_manager.SetPlayerClass(ply, "player_default") end [/lua] :|
And the class itself? How do you know it's not the correct class?
straight from the wiki, in gamemode/player_class, as it suggests [lua] AddCSLuaFile() include( 'taunt_camera.lua' ) local PLAYER = {} PLAYER.DisplayName = "Human" PLAYER.WalkSpeed = 450 -- How fast to move when not running PLAYER.RunSpeed = 700 -- How fast to move when running PLAYER.CrouchedWalkSpeed = 0.3 -- Multiply move speed by this when crouching PLAYER.DuckSpeed = 0.3 -- How fast to go from not ducking, to ducking PLAYER.UnDuckSpeed = 0.3 -- How fast to go from ducking, to not ducking PLAYER.JumpPower = 200 -- How powerful our jump should be PLAYER.CanUseFlashlight = true -- Can we use the flashlight PLAYER.MaxHealth = 100 -- Max health we can have PLAYER.StartHealth = 100 -- How much health we start with PLAYER.StartArmor = 0 -- How much armour we start with PLAYER.DropWeaponOnDie = false -- Do we drop our weapon when we die PLAYER.TeammateNoCollide = true -- Do we collide with teammates or run straight through them PLAYER.AvoidPlayers = false -- Automatically swerves around other players PLAYER.UseVMHands = true -- Uses viewmodel hands -- -- Name: PLAYER:SetupDataTables -- Desc: Set up the network table accessors -- Arg1: -- Ret1: -- function PLAYER:SetupDataTables() end -- -- Name: PLAYER:Init -- Desc: Called when the class object is created (shared) -- Arg1: -- Ret1: -- function PLAYER:Init() end -- -- Name: PLAYER:Spawn -- Desc: Called serverside only when the player spawns -- Arg1: -- Ret1: -- function PLAYER:Spawn() local oldhands = self.Player:GetHands(); if ( IsValid( oldhands ) ) then oldhands:Remove() end local hands = ents.Create( "gmod_hands" ) if ( IsValid( hands ) ) then hands:DoSetup( self.Player ) hands:Spawn() end end -- -- Name: PLAYER:Loadout -- Desc: Called on spawn to give the player their default loadout -- Arg1: -- Ret1: -- function PLAYER:Loadout() self.Player:Give( "weapon_pistol" ) self.Player:GiveAmmo( 255, "Pistol", true ) end -- Clientside only function PLAYER:CalcView( view ) end -- Setup the player's view function PLAYER:CreateMove( cmd ) end -- Creates the user command on the client function PLAYER:ShouldDrawLocal() end -- Return true if we should draw the local player -- Shared function PLAYER:StartMove( cmd, mv ) end -- Copies from the user command to the move function PLAYER:Move( mv ) end -- Runs the move (can run multiple times for the same client) function PLAYER:FinishMove( mv ) end -- Copy the results of the move back to the Player -- -- Name: PLAYER:ViewModelChanged -- Desc: Called when the player changes their weapon to another one causing their viewmodel model to change -- Arg1: Entity|viewmodel|The viewmodel that is changing -- Arg2: string|old|The old model -- Arg3: string|new|The new model -- Ret1: -- function PLAYER:ViewModelChanged( vm, old, new ) end -- -- Name: PLAYER:PreDrawViewmodel -- Desc: Called before the viewmodel is being drawn (clientside) -- Arg1: Entity|viewmodel|The viewmodel -- Arg2: Entity|weapon|The weapon -- Ret1: -- function PLAYER:PreDrawViewModel( vm, weapon ) end -- -- Name: PLAYER:PostDrawViewModel -- Desc: Called after the viewmodel has been drawn (clientside) -- Arg1: Entity|viewmodel|The viewmodel -- Arg2: Entity|weapon|The weapon -- Ret1: -- function PLAYER:PostDrawViewModel( vm, weapon ) if ( weapon.UseHands || !weapon:IsScripted() ) then local hands = self.Player:GetHands() if ( IsValid( hands ) ) then hands:DrawModel() end end end -- -- Name: PLAYER:GetHandsModel -- Desc: Called on player spawn to determine which hand model to use -- Arg1: -- Ret1: table|info|A table containing model, skin and body -- function PLAYER:GetHandsModel() -- return { model = "models/weapons/c_arms_cstrike.mdl", skin = 1, body = "0100000" } local cl_playermodel = self.Player:GetInfo( "cl_playermodel" ) return player_manager.TranslatePlayerHands( cl_playermodel ) end player_manager.RegisterClass( "player_default", PLAYER, nil ) [/lua]
What makes you think the class doesn't set?
When I spawn, I start with no weapons (default class starts with a pistol)
[QUOTE=Nornan12;43093190]When I spawn, I start with no weapons (default class starts with a pistol)[/QUOTE] You aren't calling the loadout function in your GM:PlayerSpawn This is the base spawn function:, note how it it runs hook.Call( "PlayerLoadout", GAMEMODE, pl ) [lua] function GM:PlayerSpawn( pl ) -- -- If the player doesn't have a team in a TeamBased game -- then spawn him as a spectator -- if ( GAMEMODE.TeamBased && ( pl:Team() == TEAM_SPECTATOR || pl:Team() == TEAM_UNASSIGNED ) ) then GAMEMODE:PlayerSpawnAsSpectator( pl ) return end -- Stop observer mode pl:UnSpectate() player_manager.OnPlayerSpawn( pl ) player_manager.RunClass( pl, "Spawn" ) -- Call item loadout function hook.Call( "PlayerLoadout", GAMEMODE, pl ) -- Set player model hook.Call( "PlayerSetModel", GAMEMODE, pl ) end [/lua] The player loadout hook is this, which you shouldnt need to change: [lua]function GM:PlayerLoadout( pl ) player_manager.RunClass( pl, "Loadout" ) end[/lua]
Sorry, you need to Log In to post a reply to this thread.