Need help

My names Devin and this is my first post to FP. Ive been a long time lurker and Ive just started programming a simple game mode in LUA. In my game mode im having two issues. First, I have a classes.lua file that contains data and info for every class in my game mode so far it looks like this.

//contains tables for all the classes and privilages.
//  The first number is the team number the second is the team name as it appears ingame the third is the color of the name in RBG and Alpha Values. The fourth is a CSV of all the weapons the player should get.
local class_citizen={"1, "Citizen", Color( 17, 2, 156, 255 )" }
local class_admin={"2, "Admin", Color( 17, 2, 156, 255 )" }
local class_combine={"3, "Combine", Color( 17, 2, 156, 255 )" }
local class_combine_chief={"4, "Combine Chief", Color( 17, 2, 156, 255 )" }

Now my shared.lua where all the teams get defined for real looks like this.

include( 'classes.lua' )
GM.Name 	= "Test Mod"
GM.Author = "Devin"
GM.Email 	= "N/A"
GM.Website = "N/A"

Will this work or is there a more efficient way of doing this?
Secondly, I was hoping to also define my player load outs in the same file for example the citizens table would look something like this.

local class_citizen={"1, "Citizen", Color( 17, 2, 156, 255 )",  "weapon_fiveseven, weapon_crowbar"}

And then my loadout would be like normal but i want it to use those values in the table.
ply:Give( class_citizen[2] )
the only problem is that ply:Give only supports one weapon as far as i know. So would i have to use some sort of for loop or something?
Thanks for any help you can give,


OK whoever marked this as dumb can you explain why? Because this is a simple modular way for me to modify teams and load outs in one file.

And also sorry for the title its not really descriptive is it? :frowning:

I think there’s a bug with the ratings, don’t bother with them. About the Give issue simply make the weapon a table, and then loop trough it. Here’s an example :

for k,v in pairs(class_citizen[2]) do – For every linked key and value in this table.
ply:Give(v) --Give the player the classname defined in the value (v)

Edit, taken from the wiki, this is how you should define a team : team.SetUp (4, “Guests”, Color (0, 0, 255, 255))

Awesome! I was thinking it was something along those lines :). So correct me if im wrong but i would want to make a weapons table then nest it into class_citizen[2]?

Pretty much. Of course you’ll have to figure out how to properly define teams first. But the wiki has tutorials for that. :slight_smile: You might want to take a look at this one :

Edit : Also that first bit of code you posted will give you plenty of errors, you’d better define them all in one place… ( local class_citizen={“1, “Citizen”, Color( 17, 2, 156, 255 )” } won’t work ). I suggest you get a gmod lua syntax highlighter, it will make it very easy to spot these errors.
Here’s an excellent one for NP++

So your saying I should define all the teams in one table? But class_citizen[1]= 1, “Citizen”, Color( 17, 2, 156, 255 ) right?
So Team.Setup(class_citizen[1]) is really Team.Setup(1, “Citizen”, Color( 17, 2, 156, 255 )) right?

Aww heck im just gonna go for it and see what happens and post back here :slight_smile: i guess trial and error with some help is a good way to learn!

class_citizen[1] is the first value in the class_citizen table, which is 1 in this case. So team.SetUp(class_citizen[1]) is the same as team.SetUp(1). You want something like this:
team.SetUp(class_citizen[1],class_citizen[2],class_citizen[3]) and so on.

Also a tip for help threads, just saying “Need help” is actually rather unhelpful. We already know this, that’s why you’re posting in the newbie questions forum. Use specific titles like “Gamemode classes not working”.

Here’s some code i did up quickly. I bet it could be done a lot better though;
local allClasses = {}

allClasses[1] = { 1, “cat”, Color(0,0,255,255) }
allClasses[2] = { 2, “bee”, Color(0,255,0,255) }
allClasses[3] = { 3, “fox”, Color(255,0,0,255) }

for i=1, #allClasses do

	team.SetUp(allClasses*[1], allClasses*[2], allClasses*[3])


Ok thanks for the information :), I know that the title isint the best and I tried to change it but it didint take so im sorry!

Thanks for the help with the tables and some code for the ideas :slight_smile:


Wait wait wait… if im not mistaken the first value in that table is surrounded by quotes so that should render all those pesky internal commas null and void right?

local wep_citizen = { "weapon_physcannon" ,"weapon_physgun" }
local class_citizen = { "1, "Citizen", Color( 17, 2, 156, 255 )" , wep_citizen }

so for the first value of that table its

1, "Citizen", Color( 17, 2, 156, 255 ) 


Close, but no. See, your table would error, as Lua reads it like this:

"1, "
“, Color( 17, 2, 156, 255 )”

It tries to index a nonexistant Citizen variable, and it fails again becuase you didn’t try to concatenate it or anything.

In Lua (and most programming) you use a special phrase to put quotation marks in strings: "

For example,
“This so called “string” has quotes in it!”

So your string would be like this:
“1, “Citizen”, Color( 17, 2, 156, 255 )”

Similarly, if you want to denote a new line in a string (like pressing enter), you use:

For example,
“This string has
a new line!”

However, the team.SetUp takes individual number, string, and color arguments; it won’t take a string with all three and still work.

Ahhhh! Now it all makes sence :slight_smile: Thanks for the Awesome help you guys! I don’t know why i didn’t catch that earlier.
Thanks so much!