-
-
Save D4edalus/a038fb89056a9fdc37ccfbd4e031b5de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Called by the server when a registered function is executed | |
*/ | |
CodeCallback_ScriptCommand(command, arguments) | |
{ | |
executeRegisteredCommand(command, arguments); | |
} | |
/* | |
enter "$testcmd asdf 123 fdas" into chat to execute | |
*/ | |
testcmd(args) | |
{ | |
iprintln("Called Testcmd: "); | |
if(isDefined(args)) | |
{ | |
for(i = 0; i < args.size; i++) | |
iprintln("Arguemnt " + i + " = " + args[i]); | |
} | |
} | |
/* | |
registers a new script command by storing it into an array with alias and function pointer | |
*/ | |
registerScriptCommand(command, fun) | |
{ | |
addscriptcommand(command, 1); // registers the function to be called by: CodeCallback_ScriptCommand | |
if(!isDefined(level.registeredCommands)) | |
level.registeredCommands = []; | |
level.registeredCommands[command] = fun; | |
} | |
/* | |
looks up the command alias, and executes the function iff it exists | |
*/ | |
executeRegisteredCommand(command, args) | |
{ | |
cmd = level.registeredCommands[command]; | |
if(isDefined(cmd)) | |
{ | |
argsarr = strtok(args, " "); | |
[[cmd]](argsarr); | |
} | |
else | |
{ | |
// command does not exist | |
} | |
} | |
/* | |
already existing function, just add the register part to it | |
*/ | |
CodeCallback_StartGameType() | |
{ | |
registerScriptCommand("testcmd", ::testcmd); | |
... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment