Skip to content

Instantly share code, notes, and snippets.

@assyrianic
Last active April 30, 2024 00:32
Show Gist options
  • Save assyrianic/af8186a1506da5bf482e8df26db74e88 to your computer and use it in GitHub Desktop.
Save assyrianic/af8186a1506da5bf482e8df26db74e88 to your computer and use it in GitHub Desktop.
stock void RunScript(const char[] sCode, any ...) {
/**
* Run a VScript (Credit to Timocop)
*
* @param sCode Magic
* @return void
*/
static int iScriptLogic = INVALID_ENT_REFERENCE;
if( iScriptLogic==INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic) ) {
iScriptLogic = EntIndexToEntRef(CreateEntityByName("logic_script"));
if( iScriptLogic==INVALID_ENT_REFERENCE || !IsValidEntity(iScriptLogic) ) {
SetFailState("Could not create 'logic_script'");
}
DispatchSpawn(iScriptLogic);
}
int code_len = strlen(sCode);
char[] sBuffer = new char[code_len + 1];
VFormat(sBuffer, code_len, sCode, 2);
SetVariantString(sBuffer);
AcceptEntityInput(iScriptLogic, "RunScriptCode");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment