"nextmap" command
Closed this issue · 1 comments
Hey!
I am trying to implement the "nextmap" command in a FFA FTEQW server (to go automatically to the next map in the rotation). But, in compilation the code below is giving errors:
"
nextmapping.qc:12: error: Unknown value "read_file".
nextmapping.qc:29: warning Q106: Assignment to const
nextmapping.qc:3: const float g_mapCycleLength = 0 is defined here
nextmapping.qc:29: warning Q106: Assignment to constant g_mapCycleLength
nextmapping.qc:3: const float g_mapCycleLength = 0 is defined here
at global scope,
nextmapping.qc:69: error: redeclaration of function body
voting.qc:18: const void(entity, string) ChatMessage_Parse is defined here
nextmapping.qc:114: error: incompatible redeclaration
voting.qc:18: const void(entity, string) ChatMessage_Parse is defined here
"
--- code init ---
// This will store the maps loaded from the file
string g_mapCycle[405];
float g_mapCycleLength = 0;
// Function to load maps from the mapcycle.txt file
void LoadMapCycle(void)
{
string mapCycleContent;
float mapIndex = 0;
// Load the file content into a string
mapCycleContent = read_file("mapcycle.txt");
if (!mapCycleContent) {
qw_bprint(PRINT_CHAT, "Erro: Não foi possível carregar mapcycle.txt\n");
return;
}
// Tokenize the content by newline or space, assuming each map is on a new line
float numMaps = tokenize(mapCycleContent);
// Store each map in the g_mapCycle array
for (float i = 0; i < numMaps; i++) {
g_mapCycle[mapIndex] = argv(i);
mapIndex++;
}
// Set the total number of maps
g_mapCycleLength = mapIndex;
qw_bprint(PRINT_CHAT, sprintf("%d mapas carregados de mapcycle.txt\n", g_mapCycleLength));
}
// Function to switch to the next map in the cycle
void NextMap(void)
{
// Get the current map name
string currentMap = serverkey("mapname");
// Find the current map's index in the rotation
float currentIndex = -1;
for (float i = 0; i < g_mapCycleLength; i++) {
if (g_mapCycle[i] == currentMap) {
currentIndex = i;
break;
}
}
// If the current map was found, load the next one
if (currentIndex != -1) {
float nextIndex = currentIndex + 1;
// If we're at the end of the cycle, go back to the first map
if (nextIndex >= g_mapCycleLength) {
nextIndex = 0;
}
// Change to the next map
localcmd(sprintf("map %s\n", g_mapCycle[nextIndex]));
qw_bprint(PRINT_CHAT, sprintf("Carregando o próximo mapa: %s\n", g_mapCycle[nextIndex]));
} else {
qw_bprint(PRINT_CHAT, "Mapa atual não encontrado no ciclo. Não foi possível carregar o próximo mapa.\n");
}
}
// Modify ChatMessage_Parse to include the nextmap command
void
ChatMessage_Parse(entity sayingEnt, string commandString)
{
float isMap = 0;
if (whichpack(strcat("maps/", commandString, ".bsp"))) {
isMap = 1;
}
float args = tokenize(commandString);
switch (argv(0)) {
case "sim":
self = sayingEnt;
Vote_Cmd_VoteYes();
break;
case "nao":
self = sayingEnt;
Vote_Cmd_VoteNo();
break;
case "rtv":
qw_bprint(PRINT_CHAT, sprintf("Rock The Vote solicitado por %s\n", sayingEnt.netname));
break;
case "timeleft":
string msg;
string timestring;
float timeleft;
timeleft = cvar("timelimit") - (time / 40);
timestring = Util_TimeToString(timeleft);
msg = sprintf("nos temos %s minutos restando\n", timestring);
qw_sprint(sayingEnt, PRINT_CHAT, msg);
break;
case "callvote":
Vote_Cmd_CallVote(commandString);
break;
case "votehelp":
Vote_Help(sayingEnt);
break;
case "nextmap":
NextMap();
break;
default:
if (isMap) {
qw_bprint(PRINT_CHAT, sprintf("%s foi indicado por %s\n", commandString, sayingEnt.netname));
}
break;
}
}
--- code end ---
Please, can you help me?
@eukara has a fork of Quake's progs that implements these features, you should check it out here: https://code.idtech.space/eukara/quake-qw-qc
I just want to note that I'm closing this issue because GitHub isn't really the place for these kinds of questions, it's more for reporting engine or compiler bugs. However, you can always feel free to join our Matrix or IRC, and we can provide modding help there :)