I've been mucking around with a custom game mode to add some functions to my build server and I could use some help, Im not much of a coder but would appreciate some help.
anyway. here are the issues im getting.
1. ULX gets really snippy and spams group errors at you when you open the scoreboard
2. players other than me are unable to change teams using the set convars.(may have fixed this)
3. odd error which could be related and pops up whenever a player joins
"Please rename your current gamemode folder to look EXACTLY like this: nbuild"
which doesn't make sense what with the folder being named exactly that, as well as in the shared.lua and the info.txt
anyone seen this before?
anyone?
I can of course post all the code and whatnot
[QUOTE=Fenrix;19076149] Im not much of a coder [/QUOTE]
there's your problem
Don't flame Raven119, either help (by posting) or don't (post).
Anyway. I got the error where it insists I rename my gamemode folder for no apparent reason to stop by reinstalling gmod XD
but now it just refuses to accept the concommands I have for clients.
as soon as you join it switches you to a new team called Neutral and that works perfectly (had to set weapons and stuff too, that works)
the idea is players can enter a console command "join_pirates" to join the pirates team and a couple of other teams with slightly different starting weapons.
but on entering the command, it just says unknown command for everyone.
init.lua
[lua]AddCSLuaFile( "cl_init.lua" ) --dl that
AddCSLuaFile( "shared.lua" ) --dl that too
include( 'shared.lua' ) --load that
include( 'commands.lua' ) --console commands
--normal player spawn - sets speed and hp
function GM:PlayerSpawn( ply ) --What happens when the player spawns
self.BaseClass:PlayerSpawn( ply )
ply:SetGravity( 1.0 )
ply:SetMaxHealth( 100, true )
ply:SetWalkSpeed( 160 )
ply:SetRunSpeed( 260 )
end
--first player spawn, used to set you to neutral on joining the server.
function GM:PlayerInitialSpawn( ply ) --what happens on first spawn
ply:SetTeam( 1 )
ply:Spawn()
end
--where player teams are given their weapons
function GM:PlayerLoadout( ply ) -- What should the player recieve when joining a team?
if ply:Team() == 1 then --Neutral team, they get no guns.
ply:Give( "weapon_physcannon" ) -- A Gravity gun
ply:Give( "weapon_physgun" ) -- A Physics gun
ply:Give( "gmod_tool" ) -- and don't forget the tool gun!
elseif ply:Team() == 2 then --Pirates they get some nice weps
ply:Give( "weapon_physcannon" ) --Assuming he is, then give him Gravity gun
ply:Give( "weapon_physgun" ) -- Physics gun
ply:Give( "gmod_tool" ) -- and the gmod tool
ply:Give( "weapon_pmusket" )
ply:Give( "weapon_PVK_Flintlock_Pistol" )
ply:Give( "weapon_sabre" )
ply:GiveAmmo(300, "Buckshot")
ply:GiveAmmo(50, "Pistol")
elseif ply:Team() == 3 then --Navy nice weps
ply:Give( "weapon_physcannon" ) --Assuming he is, then give him Gravity gun
ply:Give( "weapon_physgun" ) -- Physics gun
ply:Give( "gmod_tool" ) -- and the gmod tool
ply:Give( "weapon_pmusket" )
ply:Give( "weapon_ppistol" )
ply:Give( "weapon_sabre" )
ply:GiveAmmo(300, "Buckshot")
ply:GiveAmmo(50, "Pistol")
elseif ply:Team() == 4 then --East india taders they get weps too.
ply:Give( "weapon_physcannon" ) --Assuming he is, then give him Gravity gun
ply:Give( "weapon_physgun" ) -- Physics gun
ply:Give( "gmod_tool" ) -- and the gmod tool
ply:Give( "weapon_ppistol" )
ply:Give( "weapon_sabre" )
ply:Give( "weapon_PVK_Blunderbuss" )
ply:GiveAmmo(300, "Buckshot")
ply:GiveAmmo(50, "Pistol")
--I should mention at this point you can put in else, but there is no point. All possible scenarios are covered. Thus we end it
end --right here.
end -- End the function
function JoinTeam1(ply, cmd, args)
ply:SetTeam( 1 )
ply:StripWeapons()
ply:Spawn()
local name = ply:GetName()
local message = name .. " has become decidedly neutral"
for _, v in pairs(player.GetAll()) do
v:ChatPrint(message)
end
end
--team2= the pirates
function JoinTeam2(ply, cmd, args)
ply:SetTeam( 2 )
ply:StripWeapons()
ply:Spawn()
local name = ply:GetName()
local message = name .. " has sunken low and fallen in with Pirates!"
for _, v in pairs(player.GetAll()) do
v:ChatPrint(message)
end
end
--team3= the royal marines
function JoinTeam3(ply, cmd, args)
ply:SetTeam( 3 )
ply:StripWeapons()
ply:Spawn()
local name = ply:GetName()
local message = name .. " has Joined Her Majesties Royal Navy"
for _, v in pairs(player.GetAll()) do
v:ChatPrint(message)
end
end
--team4= the east india trading company.
function JoinTeam4(ply, cmd, args)
ply:SetTeam( 4 )
ply:StripWeapons()
ply:Spawn()
local name = ply:GetName()
local message = name .. " Has joined the East India Trading Company"
for _, v in pairs(player.GetAll()) do
v:ChatPrint(message)
end
end
[/lua]
cl_init.lua
[lua]
include( 'shared.lua' )
include( 'commands.lua' )
[/lua]
shared.lua
[lua]
GM.Name = "nbuild" //What is your Gamemode's name?
GM.Author = "Fenrix" // Who authored it?
DeriveGamemode("sandbox")
team.SetUp( 1, "Team 1", Color( 140, 140, 140, 255 ) )
team.SetUp( 2, "Team 2", Color( 255, 0, 0, 255 ) )
team.SetUp( 3, "Team 3", Color( 0, 255, 255, 255 ) )
team.SetUp( 4, "Team 4", Color( 255, 255, 0, 255 ) )
[/lua]
commands.lua
[lua]
concommand.Add("join_neutral", JoinTeam1)
concommand.Add("join_pirates", JoinTeam2)
concommand.Add("join_navy", JoinTeam3)
concommand.Add("join_indiacompany", JoinTeam4)
[/lua]
I used bits and pieces of a couple of lua tutorials and examples on the forums.
anything obvious jumping out?
I don't really want to go as far as coding dema yet but i was thinking if I built a menu to choose teams, it might bypass the issue of clients
not being able to use the con-commands.
although... menu's are really annoying from my limited experiance with them.
You are defining the concommand functions on the SERVER (init.lua), but adding them in a seperate file (commands.lua). Which means the functions are on one end of the gamemode, and the actual commands are on the other. Move lines 76-118 from init.lua to concommands.lua (Make sure you add them ABOVE THE "concommand.Add" lines or you will recieve the same error.)
Also, you could have ONE console command called changeteams with an argument that lets the player choose their team. As such:
[B]concommand.lua[/B]
[lua]
function cc_changeTeam( ply, cmd, arg )
-- Store the first argument passed
local newTeam = arg[ 1 ]
-- Force the player to switch
ply:SetTeam( newTeam )
ply:KillSilent( )
end
concommand.Add( "changeteam", cc_changeTeam )
[/lua]
As for the menus: I find Derma is one of the simplest forms of GUI to manipulate. You can use the following Derma code for the function above:
[B]cl_init.lua[/B]
[lua]
function vgui_changeTeam( )
-- Make a frame
local dframe = vgui.Create( "DFrame" )
dframe:SetSize( 256, 256 )
dframe:Center( )
dframe:SetTitle( "Choose a Team" )
dframe:MakePopup( true )
-- Add a button to it
local dbutton = vgui.Create( "DButton", dframe )
dbutton:SetText( "Random Team" )
dbutton:SetSize( 256, 64 )
dbutton:CenterHorizontal( )
dbutton.DoClick = function( )
-- Randomize the client´s team-choice
local random = math.random( 1, 4 )
RunConsoleCommand( "changeteam", random )
end
end
usermessage.Hook( "vguiChangeTeam", vgui_changeTeam )
[/lua]
This is a simple Derma menu, you should probably add one button for each team.
[B]
init.lua[/B]
[lua]
function GM:ShowTeam( pl )
umsg.Start( "vguiChangeTeam", pl )
umsg.End( )
end
[/lua]
All this will do is open the team menu when the player presses F2.
Thanks for the quick reply.
and thanks for the derma code. though i'm considering chat commands rather than derma I'll give that a shot anyhow.
Sorry, you need to Log In to post a reply to this thread.