const string PLACEABLE_TAG = "OnPerceptionPlaceable"; // The tag of the placeable
const string VAR_SCRIPTACT = "Already_Activated"; // The name of the variable, is script active
const float HEARTBEAT_SEC = 12.0f; // The seconds of the heartbeat
const int DEBUG = FALSE; // Debugstring
#include "x0_i0_position"
void plc_debug(string sMessage)
{
if (DEBUG)
SendMessageToPC(GetFirstPC(),sMessage);
}
int PerceptionCheckForPlaceables(object oEntering, int nNth = 1)
{
// Define needed objects
object oTarget, oPlaceableWithPerception;
location locPlaceable; int nCount;
plc_debug("DEBUG: First of two checks following");
// Do two checks, is the entering object a pc AND later is the targetted placeable valid?
if (!GetIsPC(oEntering)) // 1st check if Entering Object is a PC
return FALSE; // Call FALSE, if wrong
oPlaceableWithPerception = GetObjectByTag(PLACEABLE_TAG);
plc_debug("DEBUG: Second of two checks following");
if (!GetIsObjectValid(oPlaceableWithPerception)) // 2nd check if found Placeable is valid
return FALSE; // Call FALSE, if wrong
// So everything is in place, now get the location of the placeable AND set the function active
locPlaceable = GetLocation(oPlaceableWithPerception);
if (DEBUG)
{
effect eVis = EffectVisualEffect(VFX_DUR_AURA_FIRE);
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVis, locPlaceable, 9.0);
}
plc_debug("DEBUG: "+LocationToString(locPlaceable));
SetLocalInt(oPlaceableWithPerception, VAR_SCRIPTACT, 1);
plc_debug("DEBUG: "+IntToString(GetLocalInt(oPlaceableWithPerception, VAR_SCRIPTACT)));
plc_debug("DEBUG: Placeable found, setting <script at work>");
// Check for the number of players that should be checked
// If its <= 0 then set 1. So it should return TRUE at the first possible target?!
if (nNth <= 0) nNth = 1;
plc_debug("DEBUG: Target should be number "+IntToString(nNth));
// Adapted from AOE Spell 'Slow (nw_s0_slow.nss)'
// Used spheres, due they match perception ranges better than everything else
// Choosed size of the sphere: 5.0f => 5 metres (look at lexicon for RADIUS_SIZE_* Constant Group)
// Center of the sphere should be the location of the placeable, so it looks to be perception?
oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_LARGE, locPlaceable);
// Cycle through the targets within the spell shape until an invalid object is captured or the
// number of targets affected is equal to the given targets.
while (GetIsObjectValid(oTarget))
{
plc_debug("DEBUG: Function at target number: "+IntToString(nCount));
// If the counted Players match the given number, return TRUE. So, if nNth is 1, it should
// return TRUE at the first matching target.
if (nCount == nNth)
return TRUE;
// Count the number of targets
nCount++;
// Select the next target within the spell shape.
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_LARGE, locPlaceable);
}
plc_debug("DEBUG: Counted targets: "+IntToString(nCount)+" but nothing found");
// Else return FALSE if nothing valid could be found
return TRUE;
}
void DoFakeHeartbeatWithPerceptionCheck(object oEntering, int nNth = 1, float fHeartbeatseconds = HEARTBEAT_SEC)
{
if (fHeartbeatseconds == 0.0)
fHeartbeatseconds = HEARTBEAT_SEC;
if (PerceptionCheckForPlaceables(oEntering, nNth))
SendMessageToPC(oEntering, GetName(oEntering)+" you've got it!");
plc_debug("DEBUG: Heartbeatseconds are :"+FloatToString(fHeartbeatseconds, 1, 1));
DelayCommand(fHeartbeatseconds, DoFakeHeartbeatWithPerceptionCheck(oEntering, nNth, fHeartbeatseconds));
DelayCommand(fHeartbeatseconds-1.0, plc_debug("DEBUG: Heartbeat starts in are :"+FloatToString(fHeartbeatseconds-1.0, 1, 1)));
DelayCommand(fHeartbeatseconds-2.0, plc_debug("DEBUG: Heartbeat starts in are :"+FloatToString(fHeartbeatseconds-2.0, 1, 1)));
DelayCommand(fHeartbeatseconds-3.0, plc_debug("DEBUG: Heartbeat starts in are :"+FloatToString(fHeartbeatseconds-3.0, 1, 1)));
}