LUA:Gamemode from Scratch Part Two
From GMod Wiki
(Redirected from LUA:Gamemode from Scratch Advanced)
Lua: Part two |
Description: | Continues the tutorial. |
Original Author: | Philip Dyplin |
Created: | 2nd July, 2009 |
Contents |
Now we get more stuff in
- So, I hope you have followed the other tutorial I wrote, if so, then you should have done it first because now we will go on with more funny coding and advanced features.
What will you learn?
- We will add additional teams and set the player model.
- You will learn how to setup 4 teams with models and more weapons.
So let's get started
- Now we will set up two more teams for our gamemode
- In shared.lua add
team.SetUp( 3, "Warrior", Color( 100, 100, 100, 255 ) ) team.SetUp( 4, "Admin", Color( 0, 255, 255, 255 ) )
So, now we have two more teams. We have a warrior team and an admin team.
- Now we will setup the loadout for them, this part can be a bit long.
- In init.lua add
function GM:PlayerLoadout( ply ) if ply:Team() == 1 then ply:Give( "weapon_physcannon" ) --Give the player the Gravity Gun ply:SetModel( "models/player/kleiner.mdl" ) --Set the players model ply:Give( "item_battery", 5 ) --Give them 5 battries elseif ply:Team() == 2 then ply:Give( "weapon_physgun" ) ply:SetModel( "models/player/Eli.mdl" ) elseif ply:Team() == 3 then ply:Give( "weapon_pistol" ) ply:GiveAmmo( 180, "pistol" ) --Give the player 180 pistol rounds ply:SetModel( "models/player/barney.mdl" ) elseif ply:Team() == 4 then ply:Give( "weapon_physgun" ) ply:Give( "weapon_357" ) ply:GiveAmmo( 32, "357" ) ply:SetModel( "models/player/gman_high.mdl" ) end end
- Now we have made the loadout for the 4 teams.
Add two more buttons for the teams and two more commands for the teams.
- In cl_init.lua add and edit
--Edit the frame frame:SetSize( 300, 300 ) //Set the size --Now add the two other buttons team_3 = vgui.Create( "DButton", frame ) team_3:SetPos( 135, 30 ) //Place it next to our previous one team_3:SetSize( 100, 50 ) team_3:SetText( "Team 3" ) team_3.DoClick = function() //Make the player join team 3 RunConsoleCommand( "team_3" ) end team_4 = vgui.Create( "DButton", frame ) team_4:SetPos( 135, 85 ) //Place it next to our previous one team_4:SetSize( 100, 50 ) team_4:SetText( "Team 4" ) team_4.DoClick = function() //Make the player join team 4 RunConsoleCommand( "team_4" ) end
- And in init.lua add
function team_3( ply ) ply:SetTeam( 3 ) //Make the player join team 3 ply:Spawn() end function team_4( ply ) ply:SetTeam( 4 ) //Make the player join team 4 ply:Spawn() end --And after the two previous console commands add concommand.Add( "team_3", team_3 ) //Add the command to set the players team to team 3 concommand.Add( "team_4", team_4 ) //Add the command to set the players team to team 4
Now we have made four teams, added a loadout for each of them, and edited the menu so you can choose team.
Set a custom/existing spawn point
- How to make a player/team chose a specific spawn.
In init.lua add
function GM:PlayerSelectSpawn( ply ) --Make a team select a spawn and randomize where they spawn local spawns = ents.FindByClass( "info_player_start" ) --Make so that we can use spawns instead of info_player_start (they will do the same things) local random = math.random(spawns) --Random spawn of the info_player_start if ply:Team() == 1 --If player is in team 1 then spawns[random] --Make them always spawn from a random point of this class end --End if condition end --End the function
This was requested and may or may not work as I don't have Garry's Mod available at the moment.