• Player Classes and Addon Integration to Gamemodes?
    3 replies, posted
Hi there! Question 1: I was wondering on how to make player classes (such as Assault, Sniper, etc.) How could I do this? Question 2: How do you make it so if you download a gamemode and it comes with maps and addons? Thanks, MarcusOy
Please define what you mean by downloading a gamemode with maps and addons? There are several things you have to do aside from just creating the classes. You'll need to actually EXECUTE them. On function GM:PlayerSpawn( Player ) you need to add something like this: [lua] player_manager.SetPlayerClass( Player, "player_acecool_dev" ) player_manager.OnPlayerSpawn( Player ) player_manager.RunClass( Player, "Spawn" )[/lua] You need to modify it for each class you do. If you want to set it up so different teams are different classes you can make an array and index them that way. Here's the default player class which can be found in garrysmod/gamemodes/base/gamemode/player_class/player_default.lua [lua] AddCSLuaFile() include( 'taunt_camera.lua' ) local PLAYER = {} PLAYER.DisplayName = "Default Class" PLAYER.WalkSpeed = 400 -- How fast to move when not running PLAYER.RunSpeed = 600 -- 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 = true -- 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] Here's a modified player class called player_acecool_dev. You can see what you can adjust inside. I left default functions within. [lua]// local PLAYER_CLASS = {} PLAYER_CLASS.DisplayName = "AcecoolDev Player Class" PLAYER_CLASS.WalkSpeed = 100 -- How fast to move when not running PLAYER_CLASS.RunSpeed = 300 -- How fast to move when running PLAYER_CLASS.CrouchedWalkSpeed = 0.3 -- Multiply move speed by this when crouching PLAYER_CLASS.DuckSpeed = 0.3 -- How fast to go from not ducking, to ducking PLAYER_CLASS.UnDuckSpeed = 0.3 -- How fast to go from ducking, to not ducking PLAYER_CLASS.JumpPower = 160 -- How powerful our jump should be PLAYER_CLASS.CanUseFlashlight = false -- Can we use the flashlight PLAYER_CLASS.MaxHealth = 100 -- Max health we can have PLAYER_CLASS.StartHealth = 100 -- How much health we start with PLAYER_CLASS.StartArmor = 0 -- How much armour we start with PLAYER_CLASS.DropWeaponOnDie = false -- Do we drop our weapon when we die PLAYER_CLASS.TeammateNoCollide = false -- Do we collide with teammates or run straight through them PLAYER_CLASS.AvoidPlayers = false -- Automatically swerves around other players PLAYER_CLASS.UseVMHands = true -- Uses viewmodel hands -- -- Name: PLAYER:SetupDataTables -- Desc: Set up the network table accessors -- Arg1: -- Ret1: -- -- function PLAYER_CLASS:SetupDataTables() -- end -- -- Name: PLAYER:Init -- Desc: Called when the class object is created (shared) -- Arg1: -- Ret1: -- -- function PLAYER_CLASS:Init() -- end -- -- Name: PLAYER:Spawn -- Desc: Called serverside only when the player spawns -- Arg1: -- Ret1: -- -- function PLAYER_CLASS: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_CLASS:Loadout() -- self.Player:Give( "weapon_pistol" ) -- self.Player:GiveAmmo( 255, "Pistol", true ) -- end -- Clientside only -- if ( CLIENT ) then -- function PLAYER_CLASS:CalcView( view ) end -- Setup the player's view -- function PLAYER_CLASS:CreateMove( cmd ) end -- Creates the user command on the client -- function PLAYER_CLASS:ShouldDrawLocal() end -- Return true if we should draw the local player -- end -- Shared -- function PLAYER_CLASS:StartMove( cmd, mv ) end -- Copies from the user command to the move -- function PLAYER_CLASS:Move( mv ) end -- Runs the move (can run multiple times for the same client) -- function PLAYER_CLASS: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_CLASS:ViewModelChanged( vm, old, new ) -- end -- -- Name: PLAYER:PreDrawViewmodel -- Desc: Called before the viewmodel is being drawn (clientside) -- Arg1: Entity
[QUOTE=Acecool;42421705]Please define what you mean by downloading a gamemode with maps and addons? There are several things you have to do aside from just creating the classes. You'll need to actually EXECUTE them. On function GM:PlayerSpawn( Player ) you need to add something like this: [lua] player_manager.SetPlayerClass( Player, "player_acecool_dev" ) player_manager.OnPlayerSpawn( Player ) player_manager.RunClass( Player, "Spawn" )[/lua] You need to modify it for each class you do. If you want to set it up so different teams are different classes you can make an array and index them that way. Here's the default player class which can be found in garrysmod/gamemodes/base/gamemode/player_class/player_default.lua [lua] AddCSLuaFile() include( 'taunt_camera.lua' ) local PLAYER = {} PLAYER.DisplayName = "Default Class" PLAYER.WalkSpeed = 400 -- How fast to move when not running PLAYER.RunSpeed = 600 -- 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 = true -- 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] Here's a modified player class called player_acecool_dev. You can see what you can adjust inside. I left default functions within. [lua]// local PLAYER_CLASS = {} PLAYER_CLASS.DisplayName = "AcecoolDev Player Class" PLAYER_CLASS.WalkSpeed = 100 -- How fast to move when not running PLAYER_CLASS.RunSpeed = 300 -- How fast to move when running PLAYER_CLASS.CrouchedWalkSpeed = 0.3 -- Multiply move speed by this when crouching PLAYER_CLASS.DuckSpeed = 0.3 -- How fast to go from not ducking, to ducking PLAYER_CLASS.UnDuckSpeed = 0.3 -- How fast to go from ducking, to not ducking PLAYER_CLASS.JumpPower = 160 -- How powerful our jump should be PLAYER_CLASS.CanUseFlashlight = false -- Can we use the flashlight PLAYER_CLASS.MaxHealth = 100 -- Max health we can have PLAYER_CLASS.StartHealth = 100 -- How much health we start with PLAYER_CLASS.StartArmor = 0 -- How much armour we start with PLAYER_CLASS.DropWeaponOnDie = false -- Do we drop our weapon when we die PLAYER_CLASS.TeammateNoCollide = false -- Do we collide with teammates or run straight through them PLAYER_CLASS.AvoidPlayers = false -- Automatically swerves around other players PLAYER_CLASS.UseVMHands = true -- Uses viewmodel hands -- -- Name: PLAYER:SetupDataTables -- Desc: Set up the network table accessors -- Arg1: -- Ret1: -- -- function PLAYER_CLASS:SetupDataTables() -- end -- -- Name: PLAYER:Init -- Desc: Called when the class object is created (shared) -- Arg1: -- Ret1: -- -- function PLAYER_CLASS:Init() -- end -- -- Name: PLAYER:Spawn -- Desc: Called serverside only when the player spawns -- Arg1: -- Ret1: -- -- function PLAYER_CLASS: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_CLASS:Loadout() -- self.Player:Give( "weapon_pistol" ) -- self.Player:GiveAmmo( 255, "Pistol", true ) -- end -- Clientside only -- if ( CLIENT ) then -- function PLAYER_CLASS:CalcView( view ) end -- Setup the player's view -- function PLAYER_CLASS:CreateMove( cmd ) end -- Creates the user command on the client -- function PLAYER_CLASS:ShouldDrawLocal() end -- Return true if we should draw the local player -- end -- Shared -- function PLAYER_CLASS:StartMove( cmd, mv ) end -- Copies from the user command to the move -- function PLAYER_CLASS:Move( mv ) end -- Runs the move (can run multiple times for the same client) -- function PLAYER_CLASS: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_CLASS:ViewModelChanged( vm, old, new ) -- end -- -- Name: PLAYER:PreDrawViewmodel -- Desc: Called before the viewmodel is being drawn (clie
Anyone please correct me if I'm wrong as I haven't yet uploaded to the Workshop, but I'm assuming ( remember assumptions are the basis of all failure ) that the creator included them maps in the package when they uploaded it.
Sorry, you need to Log In to post a reply to this thread.