Using AngelScript
Important AngelScript commands:
Debugging: (These might or might not be useful for script writers)
Warning
Client version of AngelScript commands start with the wj_c_ prefix
-
wj_angelscript_debug
Enable or disable the entire logging of AngelScript to the console.
(Default: 1) -
wj_angelscript_debug_info
Enable or disable the INFO logging during compilation of AngelScript to the console.
(Default: 1) -
wj_angelscript_debug_warn
Enable or disable the WARN logging during compilation of AngelScript to the console.
(Default: 1) -
wj_angelscript_debug_script_warn
Enable or disable AngelScript script warnings.
(Default: 1) -
wj_angelscript_debug_scriptobj
Enable or disable GetScriptObj logging to the console.
(Default: 0) -
wj_angelscript_debug_cache
Prints out debug information for cache.
(Default: 0) -
wj_angelscript_debug_precache
Prints out debug information for Precaching functions.
(Default: 0) -
wj_angelscript_debug_console
Brings out the console the moment a red error was logged.
(Default: 0) -
wj_angelscript_debug_log
Saves every kind of AngelScript log to file called!angelscript_log.txt.
(Default: 1)
Dumping: (For misc. purposes)
-
wj_angelscript_dump
Dumps out information about AngelScript. (engine, module, functions, methods, etc...) -
wj_angelscript_dump_behaviors
Whether to dump out Object type's behavior to the console or not.
(Default: 0) -
wj_angelscript_dump_docs
Dumps out information about AngelScript in a way that's format-friendly for Docs. -
wj_angelscript_dump_docs_globalfuncnames
Should it also dump out global function's name, or not.
(Default: 1) -
wj_angelscript_dump_script
Dumps out information about user written scripts. (from !as_scripts.txt) -
wj_angelscript_dump_script_class_methods
Should it dump out the methods of script classes, or not.
(Default: 0) -
wj_angelscript_dump_script_class_properties
Should it dump out the properties (variables) of script classes, or not.
(Default: 0) -
wj_angelscript_dump_syntax
Dumps out information about all the global functions, the object types and their functions, variables without declaration. -
wj_angelscript_dump_syntax_npp_xml
Dumps out all the hardcoded object types, global functions, their names and declarations to a Notepad++ AutoCompletion file. -
wj_angelscript_debug_typeid
Dumps out the typeids for variable types. Only useful for programmers. -
wj_angelscript_debug_array
<datatype>
Dumps out information about this specific array. I.e.CP3SObj@
General:
-
wj_angelscript_enabled
Enable or disable AngelScript completely.
(Default: 1) -
wj_angelscript_recompile
Recompile AngelScript files included from '!as_scripts.txt', memory is purged. -
wj_angelscript_recompile_alt
Same as wj_angelscript_recompile, but the console is cleared out before printing out AngelScript log. -
wj_angelscript_exec
<class><function>
Executes AngelScript with a class and function name globally.
Has auto-completion.
AngelScript's main script file is located at '../%gameFolder%/scripts/AngelScript/!as_scripts.txt'
%gameFolder% is the mod folder loaded with the -game param.
Example: '../p3/scripts/AngelScript/!as_scripts.txt'
Addons might have their own AngelScript loader files, which is something like
'../%gameFolder%/addons/%addonName%/<defined_by_addon>
'../p3/addons/my_cool_addon/angelscript.as
Inside !as_scripts.txt or inside <defined_by_addon> you include all the files you want the game to load and compile
(this could be game start, load, or by forcing the game to recompile via the wj_angelscript_recompile command)
Example:
#include "enums.as"
#include "Utils.as"
#include "WantedReinforcement.as"
#include "bh_player.as"
#include "bh_npc_citizen.as"
#include "engine.as"
//#include "misc/tools.as"
Calling AngelScript in Postal3Script
In Postal3Script you can call any AngelScript function via the AngelScript P3S function. (UP+A or CR only)
Syntaxes:
-
AngelScript "Object:<pointer> <className> <functionName>" -
AngelScript "Object:<pointer> <functionName>"
(Note:<className>will be the entity's current P3S behavior)
In Postal3Script:
(this could also be placed inside events if wanted)
In AngelScript:
Tip
Make sure to add a factory function (ex.: <className>(CP3SObj@ obj)) to store the self pointer for later use
class Utils : IPostal3Script
{
CP3SObj@ self;
CUtils(CP3SObj@ obj)
{
@self = @obj;
}
void RandomizeState()
{
if (self == null)
return;
int iState = RandomInt(0,2);
switch (iState)
{
case 0: self.State("st_idle"); break;
case 1: self.State("st_sit"); break;
case 2: self.State("st_rest"); break;
}
}
}
If everything went well, the code should have been executed properly.