Using AngelScript

Important AngelScript commands:

Debugging: (These might or might not be useful for script writers)

  • 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_test
    Call 'Test' function in class 'bh_player', used to debug AngelScript functions and execute them easily.

  • wj_angelscript_test2
    Call 'Test2' function in class 'bh_player', used to debug AngelScript functions and execute them easily.

  • wj_angelscript_test_example
    Call 'Test3' function in class 'bh_player', used to debug AngelScript functions and execute them easily.

  • wj_angelscript_exec <class> <function>
    Executes AngelScript with a class and function name globally.

AngelScript's main script file is located at '../%gameFolder%/scripts/AngelScript/!as_scripts.txt' %gameFolder% is the mod folder loaded with the -game param, for CR it is called cr_base.
Example: '../cr_base/scripts/AngelScript/!as_scripts.txt'

In !as_scripts.txt you include all the files you want the game to load during compilation
(this could be game start, load, or by forcing the game to recompile via wj_angelscript_recompile cheat 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"

In Postal3Script you can call any AngelScript function via the AngelScript P3S function. (Angel/CR only)

Syntaxes:

  • AngelScript "Object:<pointer> <className> <functionName>"

  • AngelScript "Object:<pointer> <functionName>"
    (Note: <className> will be the entity's current P3S behavior)

In Postal3Script:

xpt_randomizeState
{
    actions
    {
        AngelScript "Object:self Utils RandomizeState"
    }
}

In AngelScript:

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;
        }
    }
}

Hardcoded Classes and it's Functions

The Hardcoded Classes and it's functions can be found in the engine.as file.
(In Catharsis Reborn, atleast.)


'Player' class:

  • Event_Killed(CTakeDamageInfo@ info)

  • OnTakeDamage(CTakeDamageInfo@ info)

  • OnWantedStarGain (CR only)

  • OnWantedStarReduction (CR only)

  • OnWantedStarSet (CR only)

  • OnRestore -- (Transition, Save game load)

  • OnWantedClear (CR only)

  • OnWantedGain (CR only)

  • OnWantedReduction (CR only)

  • OnWeaponDeployOnce (CR only)

  • OnSpecialAmmoPickup (CR only)

  • OnAmmoPickup (CR only)

  • OnHostageTaken

  • OnHostageReleased_Killed

  • OnHostageReleased_Kicked (CR only)

  • OnNPCArrested

  • OnOutOfBoundary -- (When Player's ragdoll touches a Player clip) (CR only)


'NPC' class: (this class is shared with ALL NPC types)

  • Event_Killed(CTakeDamageInfo@ info)

  • OnTakeDamage(CTakeDamageInfo@ info)

  • Event_Unconscious(CTakeDamageInfo@ info)

  • OnCrawling (CR only)

  • OnTakeDamage_Alive(CTakeDamageInfo@ info)

  • OnTakeDamage_Dying(CTakeDamageInfo@ info)


'SEngine' class:

  • LevelInitPostEntity -- (entities are created / spawned / precached here)

  • LevelInitPreEntity -- (Level loaded, but before entities spawned in)

  • LevelShutdownPostEntity -- (Level completely shut down, no entities here)

  • LevelShutdownPreEntity -- (Level not yet shut down, entities are still here)

  • OnRestore -- (Level fully loaded, transition or load game)

  • OnSave -- (Player/server saved the game)

  • Recompile -- (Whenever the scripts are recompiled)

  • PostInit -- (Called when the game starts up and AngelScript successfully compiled)

  • FireGameEvent(CGameEvent@ evt) -- (Whenever a game event is fired and has been registered)

  • OnCVarChanged(string name, string OldString, float OldValue) -- (Whenever a cvar that was manipulated inside AngelScript was changed)

  • OnDoorDestroyed(string name, Vector pos) -- (Whenever a door is destroyed) (CR only)

  • OnDoorSpawned(string name, CBaseEntity@ door) -- (Whenever a door is spawned) (CR only)


'FSMProp' class: (CR only)

  • OnInventoryItemPreSpawn(int type, CBaseEntity@ ptr) -- (When an inventory item is not yet fully spawned)

  • OnInventoryItemSpawn(int type, CBaseEntity@ ptr) -- (When an inventory item is just yet to be spawned)