There have been requests on the board for a
weapon like Sting from the Hobbit. That is, if a certain enemy is the
vicinity, then the sword should glow. However, I have failed to figure out
how to apply spell effects to swords, so I wrote a script that makes the
wielder glow instead. Close enough, perhaps.
Currently, if a PC (though my script should be general enough for NPCs as
well; haven't tested that) is wielding the sword with the appropriate tag ("CAL_SWORD")
in either hand, then when the PC is rather close to an object of the
appropriate tag ("CAL_COW"), the PC will start pulsating between white and
red. This is the paralyzed visual effect, which is cool, and has the bonus
that the PC should know whether he is paralyzed or it's actually the sword's
effect. Since this is an OnHeartbeat script, you sometimes have to wait a
bit for the glowing to start and to stop. However, since in most
applications of this script, the distances to check will probably be beyond
perception range, that delay shouldn't be a problem. I have declared at the
beginning of the script all the variables that users of the script will want
to modify to fit their modules.
1. Script Name: cal_glow
2. What It Does: Wielder of a weapon glows when a certain object is near
3. Notes: Call this script OnHeartbeat, and make sure you have a weapon and
an object with tags matching those in the script. Then play around with the
glowing.
4. The Script Itself:
NWScript:
string ITEM_GLOW_TAG = "CAL_SWORD";
string TRIGGER_GLOW_TAG = "CAL_COW";
float PROXIMITY_DISTANCE = 4.;
int VFX_EFFECT = VFX_DUR_PARALYZED;
int CAL_DEBUG = FALSE;
void Alert(string szMessage) {
if(CAL_DEBUG) {
object oPC = GetFirstPC();
SendMessageToAllDMs(szMessage);
while(GetIsObjectValid(oPC)) {
SendMessageToPC(oPC, szMessage);
oPC = GetNextPC();
}
}
}
int Proximity(object oCenter, string sTag, float fDist) {
int nCounter = 0;
object oThing;
Alert("Proximity(): Checking proximity");
while(GetIsObjectValid(oThing = GetNearestObjectByTag(sTag, oCenter, ++nCounter))) {
if((GetArea(oCenter) == GetArea(oThing)) && ((GetDistanceBetween(oCenter, oThing)) < fDist)) {
Alert("Proximity(): Found one thing with tag " + sTag + " in distance " + FloatToString(fDist));
return TRUE;
}
}
Alert("Proximity(): Found " + IntToString(nCounter-1) + " things with tag " + sTag + " outside of distance " + FloatToString(fDist));
return FALSE;
}
void Glow(object oItem) {
object oOwner = GetItemPossessor(oItem);
Alert("Glow(): Item is being carried");
if((GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oOwner) == oItem) ||
(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oOwner) == oItem)) {
if(Proximity(oOwner, TRIGGER_GLOW_TAG, PROXIMITY_DISTANCE)) {
Alert("Glow(): Starting/continuing glow");
effect eVis = EffectVisualEffect(VFX_EFFECT);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oOwner, 7.);
}
}
}
void SearchAndGlow(string sTag) {
int nCounter = -1;
object oOwner, oItem;
while(GetIsObjectValid(oItem = GetObjectByTag(sTag, ++nCounter))) {
oOwner = GetItemPossessor(oItem);
if(GetIsObjectValid(oOwner)) {
Glow(oItem);
}
}
Alert("SearchAndGlow(): Found " + IntToString(nCounter) + " item(s) with tag " + sTag);
}
void main()
{
SearchAndGlow(ITEM_GLOW_TAG);
}
|