useful class i wrote to handle console commands
Code:
class CConsoleCommand {
char commands[100][100];
float on_value[100];
float off_value[100];
int othertoggle[100];
int* toggle;
int oldtoggle;
int slot;
public:
CConsoleCommand(){
memset(&commands, 0, sizeof(commands));
memset(&on_value, 0, sizeof(on_value));
memset(&off_value, 0, sizeof(off_value));
memset(&othertoggle, 0, sizeof(othertoggle));
toggle = 0;
oldtoggle = 0;
}
CConsoleCommand(int *toggle) {
CConsoleCommand();
this->toggle = toggle;
}
void Add(char* cmd, float on_value, float off_value, int toggle = 0) {
strcpy(commands[slot], cmd);
this->on_value[slot] = on_value;
this->off_value[slot] = off_value;
if(toggle) {
othertoggle[slot] = toggle;
}
slot++;
}
void Execute() {
if(*toggle && *toggle != oldtoggle) {
oldtoggle = *toggle;
char buf[64] = "";
bool found = false;
for(int i = 0; i < slot; i++) {
if(othertoggle[i] == *toggle) {
sprintf(buf, "%s %f", commands[i], on_value[i]);
g_pEngine->m_pLTBase->RunConsoleCommand(buf);
found = true;
}
}
if(found) {
return;
}
for(int i = 0; i < slot; i++) {
if(!othertoggle[i]) {
sprintf(buf, "%s %f", commands[i], on_value[i]);
g_pEngine->m_pLTBase->RunConsoleCommand(buf);
}
}
}
if(!*toggle && *toggle != oldtoggle) {
oldtoggle = *toggle;
char buf[64] = "";
for(int i = 0; i < slot; i++) {
sprintf(buf, "%s %f", commands[i], off_value[i]);
g_pEngine->m_pLTBase->RunConsoleCommand(buf);
}
}
}
};
replace runconsolecommand with ur function
usage;
Code:
//global definition, cvars.Boxes is the variable i use to turn Boxes on or off
CConsoleCommand cmdBoxes(&cvars.Boxes);
//initialization, call it only once
cmdBoxes.Add("ModelDebug_DrawBoxes", 1, 0);
//in a thread:
cmdBoxes.Executes();