• Assigning Player Classes
    9 replies, posted
I have tried many different ways to assign my player classes but none have worked. I am trying to assign a specific player class to a specific team, as far as I know I set up the player classes correctly. But how do I assign them to a specific team within my init.lua? (If necessary I will provide the code I have.) Please help!
PlayerSpawn where _p is the Player / argument: [code] player_manager.SetPlayerClass( _p, "player_default" ); player_manager.OnPlayerSpawn( _p ) player_manager.RunClass( _p, "Spawn" )[/code] That will set the player class to player_default and run OnPlayerSpawn and run the class Spawn function.
[QUOTE=Acecool;45377314]PlayerSpawn where _p is the Player / argument: [code] player_manager.SetPlayerClass( _p, "player_default" ); player_manager.OnPlayerSpawn( _p ) player_manager.RunClass( _p, "Spawn" )[/code] That will set the player class to player_default and run OnPlayerSpawn and run the class Spawn function.[/QUOTE] Is _p your variable for player?
[QUOTE=D3athChick3n;45377879]Is _p your variable for player?[/QUOTE] Yes.
Yes, I added "Where _p is the Player/Argument" meaning GM:PlayerSpawn( _p ) is what I use, you may use GM:PlayerSpawn( ply ) or GM:PlayerSpawn( Player ) or something else. Hope it helps! Here's how I do things: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_tutorial_quizzes/_coding_standards.lua.html[/url]
SetPlayerClass - attempt to use unknown player class player_human! That is the new error I am getting. Here is how I registered it within the player class [CODE]player_manager.RegisterClass( "player_human", PLAYER, "player_default" )[/CODE] Within the init.lua I used this to assign it (Under GM:PlayerSpawn) [CODE] if ply:Team() == 1 then player_manager.SetPlayerClass( ply, "player_human" ); player_manager.OnPlayerSpawn( ply ) player_manager.RunClass( ply, "Spawn" )[/CODE] I also had this in init [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "player_human.lua" ) AddCSLuaFile( "player_juggernaut.lua" ) include( 'resources.lua' ) include( 'shared.lua' ) include( 'player_human.lua' ) include( 'player_juggernaut.lua' )[/CODE]
[QUOTE=D3athChick3n;45378265]SetPlayerClass - attempt to use unknown player class player_human! That is the new error I am getting. Here is how I registered it within the player class [CODE]player_manager.RegisterClass( "player_human", PLAYER, "player_default" )[/CODE] Within the init.lua I used this to assign it (Under GM:PlayerSpawn) [CODE] if ply:Team() == 1 then player_manager.SetPlayerClass( ply, "player_human" ); player_manager.OnPlayerSpawn( ply ) player_manager.RunClass( ply, "Spawn" )[/CODE] I also had this in init [CODE]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) AddCSLuaFile( "player_human.lua" ) AddCSLuaFile( "player_juggernaut.lua" ) include( 'resources.lua' ) include( 'shared.lua' ) include( 'player_human.lua' ) include( 'player_juggernaut.lua' )[/CODE][/QUOTE] Use if ply:Team( ) == TEAM_HUMAN then ... end instead of hardcoding the numbers. Also, add: DeriveGamemode( "base" ); right before you load your game-mode. Chancels are the default class didn't load, so it didn't set yours up?? Either that or a possible error; launch the server with -condebug and show us the contents of the console.log in your server garrysmod/ folder.
[QUOTE=Acecool;45378446]Use if ply:Team( ) == TEAM_HUMAN then ... end instead of hardcoding the numbers. Also, add: DeriveGamemode( "base" ); right before you load your game-mode. Chancels are the default class didn't load, so it didn't set yours up?? Either that or a possible error; launch the server with -condebug and show us the contents of the console.log in your server garrysmod/ folder.[/QUOTE] I already have DeriveGamemode( base ) in shared.lua should I add quotations or add it to init.lua?
Shared it right, but it won't work without the quotes.... you'll end up with errors, unless you defined local base = "base";... Example of how I'd recommend it ( shared, before you load your game-mode... This is old variant of auto-loader, new version is up on bit ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/basedev_gamemode.rar[/url]
[QUOTE=Acecool;45381587]Shared it right, but it won't work without the quotes.... you'll end up with errors, unless you defined local base = "base";... Example of how I'd recommend it ( shared, before you load your game-mode... This is old variant of auto-loader, new version is up on bit ): [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_zipped_code/basedev_gamemode.rar[/url][/QUOTE] Still doesn't work maybe it is something with my player class file. Here is the file [url]https://www.dropbox.com/s/59h4fod1anr2em0/player_human.lua[/url]
Sorry, you need to Log In to post a reply to this thread.