Let's try a slightly different approach. And I picked a different "red" color that should stand out better.
Goal: Pulsing red/white tattoo when a certain NPC is nearby.
Assumptions for this exercise:
Target NPC's tag: "myskinhurts"
Desired distance for warning: 20 meters (2 tiles)
Normally checked every 18 seconds (3 rounds)
Checked every 6 seconds (1 round) if NPC already detected
Let's use the current module's on enter script to get things started.
---------------------------------------------------------
Above the void main(), let's define a nice little custom function:
// Runs a cycling check to see if an NPC with the sNPCTag is within fMeters distance.
// If yes, oPC's tattoos pulse from red to white or white to red (switching every every fCheckDelay2 seconds)
// fCheckDelay1 is the delay in seconds between checks when the targeted NPC is NOT detected
// fCheckDelay2 is the delay in seconds between checks when the targeted NPC IS detected
// nTatSaved is a local int that just checks to see if oPC's tattoo has been checked yet, no
// need to fill it in with anything yourself
void TattooCheck(object oPC, string sNPCTag, float fMeters, float fCheckDelay1, float fCheckDelay2, int nTatSaved=999);
void TattooCheck(object oPC, string sNPCTag, float fMeters, float fCheckDelay1, float fCheckDelay2, int nTatSaved=999)
{
int nTatColor = 999;
float fDelay;
location lPC = GetLocation(oPC);
int nEnemy = 0;
object oEnemyNPC = GetFirstObjectInShape(SHAPE_SPHERE, fMeters, lPC);
while (oEnemyNPC != OBJECT_INVALID)
{
if (GetTag(oEnemyNPC) == sNPCTag)
{
nEnemy = nEnemy + 1;
}
oEnemyNPC = GetNextObjectInShape(SHAPE_SPHERE, fMeters, lPC);
}
if (nEnemy > 0)
{
fDelay = fCheckDelay2;
if (nTatSaved == 999)
{
nTatColor = 62;
}
else if (nTatSaved == 62)
{
nTatColor = 88;
}
else if (nTatSaved == 88)
{
nTatColor = 62;
}
SetColor(oPC, COLOR_CHANNEL_TATTOO_1, nTatColor);
SetColor(oPC, COLOR_CHANNEL_TATTOO_2, nTatColor);
}
else
{
fDelay = fCheckDelay1;
}
DelayCommand(fDelay, TattooCheck(oPC, sNPCTag, fMeters, fCheckDelay1, fCheckDelay2, nTatColor));
}
---------------------------------------------------------
Within the main part of the script, add this (after defining oPC as the entering object):
// Starts the "magic tattoo" cycling 30 seconds after the PC enters the module.
DelayCommand(30.0, AssignCommand(oPC, TattooCheck(oPC, "myskinhurts", 20.0, 18.0, 6.0)));
Modifié par The Amethyst Dragon, 04 juillet 2011 - 06:54 .