Mini game Gamemod.

Hey guys.
I’ve been thinking on ways of making a Minigames Gamemod.
The only think that poped up in my head was this:
Make a global value which will be called WhichGamemod.
I’ll make all of the gamemodes in one folder, And i’ll take for example 5-6 gamemodes.
I’ll put a function on each server file to check if WhichGamemod = 1 (for gamemode 1) for example, else Return.
And for gamemod2, i’ll put a checker on each lua file to check if WhichGamemod = 2 else return.
This is my only option that i can think of.
Then use ‘changelevel’ to update it and make all of the lua files load.
Any1 has any other ideas?

Fretta…?

what is Fretta?

Fretta is a gamemode which already does this, in a much better way than you described.

ok found it.
How do i configure it?

bump.

What do you mean configure? I think I’ve explained a few times how to set things up for fretta, so do some quick google searches and you should be able to find some help.

As a thing though, most of fretta is outdated, meaning you’re going to be doing almost everything yourself. If you aren’t experienced with lua, start learning before tackling such a big project.

The way you described, probably has to be one of the worst ways of doing this, maybe it’s just the way I am reading it, but to me it seems really idiotic.

Well got any other way to suggest? :stuck_out_tongue:

I don’t use Fretta, so this is for base gamemode

Well, I am no expert, but if I was gonna do this, have an end map vote or random, I’m sure you got that covered, very easy, the way I suggest doing this is to have a table of all gamemodes, you can hard code this or using a for loop and use file.Find, store each directory into a table, honestly, I don’t like hard coding things, so i will use a for loop and file.Find.

An example would be



// lua/autorun/server/gamemodeManager.lua < make sure the file is in here or some where, where it will be run and not be dependent on gamemode files
directory = "gamemodes/myGamemode/gamemode/"; // Where are the gamemodes in?
gamemodeToLoad = file.Read("gamemodeToLoad.txt", "DATA") // read the string from the file
local files, _ = file.Find( directory..gamemodeToLoad.."/s*.lua", "MOD" ) // Get all the server side gamemode files because we don't need to include client side (assuming your files are labeled as sv_ = server, sh_ = shared and cl_ = client

for k,v in pairs(files) do
	print(v);
	include(gamemodeToLoad.."/"..v); // Include them (run them)
end


Now, the last thing you would need to do is File.Write() when you are gonna load next gamemode, let’s say you have 3 gamemodes in the folder
“Duck Hunt”
“Fat-Kid”
“Tank”
If you are going to load Fat-Kid, you would need to file.Write(“gamemodeToLoad.txt”, “Fat-Kid”)
then for the map part (if each gamemode has it’s own maps), you can hard code or as I would prefer, you could do a file.Find in the maps folder, for each gamemode it could have a specific id (for example, Fat-Kid could be fd, the first and last letter or fa, the first and second letter etc) so it would search for maps with fd or fa, like this
file.Find(“maps/fd_*.bsp”, “MOD”), add each map to a table, randomly pick a map and ta da
Example



function PickNextGamemode()
	directory = "gamemodes/myGamemode/gamemode/"; // Where are the gamemodes in?
	local _, directories = file.Find(directory.."*", "MOD") // our gamemodes
	nextGamemode = table.Random(directories) // randomly choose next gamemode
	file.Write("gamemodeToLoad.txt", nextGamemode) // save gamemode for other file

	local maps, _ = file.Find("maps/"..string.sub(nextGamemode, 0, 2).."*.bsp", "MOD") // all maps for gamemode
	if not table.IsEmpty(maps) then
		game.ConsoleCommand("changelevel "..table.Random(maps)) // change level to random map
	end
end


You can customize it to a map vote etc,

I hope this helps, reply if you need any further help, but I or others may not be this generous next time.

Note: This will include all the sv_ and sh_ files, make sure you name all client side scripts cl_, serverside scripts sv_ and shared sh_
Also, if you are including other scripts from your init.lua or whatever (which I assume), you can remove the includes since this will include all server and shared files in your gamemode folder.