Stimuli
When some NPCs in Catharsis Reborn/Postal 3 are fallen down, crawling, knocked out, they are generally not meant to react to some events, however to check that if they are "stimuli-able" you'll need a few if elses for that.
So how do we just turn this into a global function, to avoid spaghetti?
Check if entity can react to environment
In Postal 3, NPCs were only able to be "knocked out" but they would get up shortly after, in Catharsis Reborn it became a little bit more complicated.
We added crawling (incapacitated) state, where they'll just roll on the floor until they bleed out, get knocked out, or die in pain.
But the Stimuli doesn't end there, generally speaking we want to make sure NPCs are in a calm, idling state, so they are okay to stimuli, here's how:
bool CanStimuli(CP3SObj@ obj)
{
// Player should always return true
if ( obj.IsPlayer() )
return true;
// Props cannot stimuli
if ( obj.IsProp() || obj.IsFSM() )
return false;
// Dead men can't talk
if (targ.GetAttr("ea_health") <= 0)
return false;
if (targ.IsCrawling())
return false;
if (targ.IsKnockedOut())
return false;
if (targ.GetCurGroup() != "Neutral")
return false;
return true;
}
Example (How to use)
Then in code, we can just simply call the function, but before doing so put the code in Utils.as
or some global function holding file.
#include "Utils.as"
class MyClass : IPostal3Script
{
void MyFunction()
{
CP3SObj @self = GetContextOwner();
if ( @self == null )
return;
// This array will always get the NPCs, and not props
array<CP3SObj@> arr = engine.GetArrayOfNPCs();
for (uint i = 0; i < arr.length(); i++)
{
if ( arr[i] == null )
continue;
// We shouldn't be working with ourselves here
if ( arr[i] == @self )
continue;
// Can't stimuli
if ( !CanStimuli(arr[i]) )
continue;
// They are gonna hate us now...
arr[i].Relationship(self, D_HT, 1);
}
}
}