Calling AngelScript in Postal3Script
Class and Function execution
This tutorial is briefly explained on the Using AngelScript page.
AngelScript code can be used/called inside Postal3Script, here's how in an example:
In Postal3Script:
xpt_CheckCallerNPC
{
actions
{
TargetCaller 1
SetAttr "checkresult 0"
AngelScript "Object:self Misc xpt_CheckCallerNPC"
IfAttr "checkresult == 1 Block begin"
// do something according to the result...
Block end
}
}
In AngelScript:
class Misc : IPostal3Script
{
void xpt_CheckCallerNPC()
{
// Note: the context owner is always the one who called the function from P3S!
CP3SObj@ self = GetContextOwner();
// We can't check without 'self'
if (self == null)
return;
// Doesn't have any target
if (self.GetTarget() == null)
return;
if (self.GetTarget().IsNPC() == true)
bResult = true;
if (bResult == true)
self.SetAttr("checkresult", 1);
}
}
Function-only execution
You can also just specify the function name, but when you do that the class name must match the executioner's behavior name from P3S.
You should only use this when you are 100% sure the behavior name won't change, for example, if you are trying to call the AngelScript function in a class that's inherited from, it'll always be the main, current behavior name, the console will always warn you if it tries to execute an unknown function from a(n) (unknown) class.
It's highly recommended you also use class when executing.
In Postal3Script:
behavior
{
name bh_mybehavior
States
{
st_init
{
Group Neutral
Patterns
{
pt_default
{
actions
{
AngelScript "Object:self Setup"
}
}
}
}
}
}
In AngelScript:
class bh_mybehavior : IPostal3Script
{
// st_init in AngelScript, kinda ...
void Setup()
{
// Note: the context owner is always the one who called the function from P3S!
CP3SObj@ self = GetContextOwner();
if (self == null)
return;
self.SetAttr("NPC", 0);
self.SetAttr("Dog", 0);
self.SetAttr("Cat", 0);
self.SetAttr("Human", 0);
self.SetAttr("Player", 0);
if (self.IsNPC())
{
self.SetAttr("NPC", 1);
if (self.IsDog())
self.SetAttr("Dog", 1);
else if (self.IsCat())
self.SetAttr("Cat", 1);
else if (self.IsHuman())
self.SetAttr("Human", 1);
}
else if (self.IsPlayer())
self.SetAttr("Player", 1);
}
}