168 lines
4.7 KiB
Plaintext
168 lines
4.7 KiB
Plaintext
//::///////////////////////////////////////////////
|
|
//:: wererat_userdef.nss
|
|
//:: Copyright (c) 2022 Project RATDOG
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
OnUserDefined script for Wererats.
|
|
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Jaysyn
|
|
//:: Created On: 20220730
|
|
//:://////////////////////////////////////////////
|
|
|
|
#include "nw_i0_tool"
|
|
|
|
const int EVENT_USER_DEFINED_PRESPAWN = 1510;
|
|
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
|
|
|
|
int RA_DEBUG = FALSE;
|
|
|
|
object GetFarthestInThrowingRange(object oSelf);
|
|
|
|
object GetFarthestInThrowingRange(object oSelf)
|
|
{
|
|
// Get the calling object
|
|
object oSelf = OBJECT_SELF;
|
|
object oTarget;
|
|
|
|
// Initialize variables to store the farthest creature and its distance
|
|
location lCenter = GetLocation(oTarget);
|
|
|
|
float fMaxDistance = 0.0;
|
|
float MAX_DISTANCE = 10.0; // Maximum distance in feet
|
|
|
|
// Get a list of all hostile creatures within 10 feet of oSelf
|
|
object oNearbyCreature = GetFirstObjectInShape(SHAPE_SPHERE, 6.6f, lCenter, TRUE, OBJECT_TYPE_CREATURE);
|
|
|
|
// Iterate through the list and find the farthest hostile creature
|
|
while (GetIsObjectValid(oNearbyCreature))
|
|
{
|
|
// Check if the current object is hostile towards oSelf
|
|
if (GetIsEnemy(oNearbyCreature, oSelf))
|
|
{
|
|
// Calculate the distance between oSelf and the current creature
|
|
float fDistance = GetDistanceBetween(oSelf, oNearbyCreature);
|
|
|
|
// If this creature is farther than the current farthest, update the target
|
|
if (fDistance > fMaxDistance)
|
|
{
|
|
oTarget = oNearbyCreature;
|
|
fMaxDistance = fDistance;
|
|
}
|
|
}
|
|
|
|
// Move to the next nearby creature
|
|
oNearbyCreature = GetNextObjectInShape(SHAPE_SPHERE, 6.6f, lCenter, TRUE, OBJECT_TYPE_CREATURE);
|
|
}
|
|
// At this point, oTarget will contain the farthest hostile creature within 10 feet of oSelf
|
|
return oTarget;
|
|
}
|
|
|
|
void main()
|
|
{
|
|
|
|
//:: Declare major variables
|
|
int nUser = GetUserDefinedEventNumber();
|
|
int nChange = GetLocalInt(OBJECT_SELF,"NW_LYCANTHROPE");
|
|
|
|
effect eShape = EffectPolymorph(POLYMORPH_TYPE_WERERAT);
|
|
effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
|
|
|
|
if(nUser == EVENT_HEARTBEAT ) //HEARTBEAT
|
|
{
|
|
|
|
}
|
|
else if(nUser == EVENT_PERCEIVE) // PERCEIVE
|
|
{
|
|
|
|
}
|
|
else if (nUser == EVENT_END_COMBAT_ROUND)
|
|
{
|
|
object oTarget = GetFarthestInThrowingRange(OBJECT_SELF);
|
|
|
|
location lTarget = GetLocation(oTarget);
|
|
itemproperty ip;
|
|
|
|
int nSpellID = SPELL_GRENADE_CHOKING;
|
|
int nItemSpell;
|
|
int nSubtype;
|
|
int nStop = FALSE;
|
|
|
|
object oItem = GetFirstItemInInventory();
|
|
|
|
while(GetIsObjectValid(oItem) && nStop == FALSE)
|
|
{
|
|
ip = GetFirstItemProperty(oItem);
|
|
while(GetIsItemPropertyValid(ip) && nStop == FALSE)
|
|
{
|
|
if(GetItemPropertyType(ip) == ITEM_PROPERTY_CAST_SPELL)
|
|
{
|
|
// This returns an ID from iprp_spells - ie; it is a spell, but the level / spell ID is codified in another 2DA. So look it up.
|
|
nSubtype = GetItemPropertySubType(ip);
|
|
nItemSpell = StringToInt(Get2DAString("iprp_spells","SpellIndex",nSubtype));
|
|
|
|
// Checking spell property Debug
|
|
if(RA_DEBUG)
|
|
{
|
|
SpeakString("Checking spell ID: " + IntToString(nSpellID) + " called: " + Get2DAString("iprp_spells","Label",nSubtype) + " on item: " + GetName(oItem) + " checking: " + IntToString(nItemSpell));
|
|
}
|
|
if(nItemSpell == nSpellID)
|
|
{
|
|
// Debug
|
|
if(RA_DEBUG)
|
|
{
|
|
SpeakString("Found spell ID and trying to use: " + IntToString(nSpellID) + " called: " + Get2DAString("iprp_spells","Label",nSubtype) + " on item: " + GetName(oItem) + " firing against target: "+ GetName(oTarget));
|
|
}
|
|
ClearAllActions();
|
|
|
|
ActionUseItemAtLocation(oItem, ip, lTarget);
|
|
|
|
if(RA_DEBUG)
|
|
{
|
|
ActionSpeakString("I should have used an item");
|
|
}
|
|
|
|
nStop = TRUE;
|
|
}
|
|
}
|
|
ip = GetNextItemProperty(oItem);
|
|
}
|
|
oItem = GetNextItemInInventory();
|
|
}
|
|
}
|
|
else if(nUser == EVENT_DIALOGUE) // ON DIALOGUE
|
|
{
|
|
|
|
}
|
|
else if(nUser == EVENT_ATTACKED && nChange == 0) // ATTACKED
|
|
{
|
|
DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eShape, OBJECT_SELF));
|
|
DelayCommand(1.0, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVis, GetLocation(OBJECT_SELF)));
|
|
SetLocalInt(OBJECT_SELF, "NW_LYCANTHROPE", 1);
|
|
}
|
|
else if(nUser == EVENT_DAMAGED) // DAMAGED
|
|
{
|
|
|
|
}
|
|
else if(nUser == 1007) // DEATH - do not use for critical code, does not fire reliably all the time
|
|
{
|
|
|
|
}
|
|
else if(nUser == EVENT_DISTURBED) // DISTURBED
|
|
{
|
|
|
|
}
|
|
else if (nUser == EVENT_USER_DEFINED_PRESPAWN)
|
|
{
|
|
|
|
}
|
|
else if (nUser == EVENT_USER_DEFINED_POSTSPAWN)
|
|
{
|
|
|
|
}
|
|
|
|
//:: Execute the PRC NPC OnUserDef script
|
|
ExecuteScript("prc_npc_userdef", OBJECT_SELF);
|
|
|
|
} |