Best way to implement in-game Mod selection
by Andreas Heldt · in Torque Game Engine · 11/18/2004 (8:13 am) · 0 replies
Hi there,
In our game we want to implement a in-game selection of the game mod that should be used when loading a mission.
A mod in our game could also be DM,TDM or CTF, so every gametype is taken as a mod.
At the moment I am using the following system:
The mods are having one file, that is named by the short mod name, like:
ctf.cs
dm.cs
tdm.cs
These files are located in a directory that is just for these mod-files.
In these mod-files, there is a structure like this:
When the game is started, i build a list of all mods by listing the files in the directory, looking for a package named "mod_[filename]", and if that package is there, it's activated. I then call the function getModDesc() and deactivate the package. The description and mod name are stored in a global array. Here is the complete code for that procedure:
Later, the list is used to be displayed in a drop-down list when the user selects a mission to load. The loading scripts gives the selected mod to the startServer function, which activates the package once more.
I wanted to ask you, how this could be done in a better way, because it seems to me like a bit of hack by now ( particularly because these packages are not working in the right way ).
In our game we want to implement a in-game selection of the game mod that should be used when loading a mission.
A mod in our game could also be DM,TDM or CTF, so every gametype is taken as a mod.
At the moment I am using the following system:
The mods are having one file, that is named by the short mod name, like:
ctf.cs
dm.cs
tdm.cs
These files are located in a directory that is just for these mod-files.
In these mod-files, there is a structure like this:
package mod_ctf
{
function getModDesc()
{
return "classic Capture-the-flag";
}
[...]
}When the game is started, i build a list of all mods by listing the files in the directory, looking for a package named "mod_[filename]", and if that package is there, it's activated. I then call the function getModDesc() and deactivate the package. The description and mod name are stored in a global array. Here is the complete code for that procedure:
%typesPath = "~/server/scripts/mods/*.cs";
%i = 0;
for(%file = findFirstFile(%typesPath);%file !$= ""; %file = findNextFile(%typesPath))
{
if(strStr(%file, "/CVS/") == -1)
{
exec(%file);
%modName = "mod_" @ fileBase(%file);
// check if there is such a mod package
if(isPackage(%modName))
{
$gameTypeArray[%i,0] = %modName;
$gameTypeArray[%i,1] = fileBase(%file);
// fetch mod info
activatePackage(%modName);
%modDesc = getModDesc();
$gameTypeArray[%i,2] = %modDesc;
deactivatePackage(%modName);
%i++;
echo("Mod <" @ %modName @ "> recognized. Desc:\n" @ %modDesc);
}
else
{
echo("Unknown file as mod: " @ %file @ " (" @ %modName @ ")");
}
}
}Unfortunately, i discovered that package activating and de-activating is not done properly by torque. So the function getModDesc() returns the desc of the first mod, when a second mod is recognized.Later, the list is used to be displayed in a drop-down list when the user selects a mission to load. The loading scripts gives the selected mod to the startServer function, which activates the package once more.
I wanted to ask you, how this could be done in a better way, because it seems to me like a bit of hack by now ( particularly because these packages are not working in the right way ).