PoA_PRC8/_module/nss/prc_pwonspawn.nss
Jaysyn904 0dbb628b75 Added Skullkeep's dynamic loot generation system
Added Skullkeep's PRC8 compatible dynamic loot generation system.  Full compile.  Updated release archive.
2024-11-08 18:54:51 -05:00

147 lines
3.6 KiB
Plaintext

//:://////////////////////////////////////////////////
//:: prc_pwonspawn
/*
PRC's OnSpawn event handler for NPCs.
*/
//:://////////////////////////////////////////////////
#include "NW_I0_GENERIC"
#include "nw_i0_plot"
#include "rd_level"
#include "inc_sqlite_time"
#include "inc_debug"
#include "prc_inc_racial"
#include "sd_lootsystem"
void ReallyEquipItemInSlot(object oNPC, object oItem, int nSlot);
void ReallyEquipItemInSlot(object oNPC, object oItem, int nSlot)
{
if (GetItemInSlot(nSlot) != oItem)
{
//ClearAllActions();
AssignCommand(oNPC, ActionEquipItem(oItem, nSlot));
DelayCommand(0.5, ReallyEquipItemInSlot(oNPC, oItem, nSlot));
}
}
void main()
{
//:: Initialize Major Variables
effect eVFX;
int nTotalPCs;
int nTotalPCLevel;
int nAveragePCLevel;
int iRacial = GetRacialType(OBJECT_SELF);
int nCommoner = GetLevelByClass(CLASS_TYPE_COMMONER, OBJECT_SELF);
string sCurrentDate = SQLite_GetSystemDate();
string sMonthDay = GetSubString(sCurrentDate, 0, 5);
object oArea = GetArea(OBJECT_SELF);
object oSkelly;
object oPC = GetFirstObjectInArea(oArea);
//:: Testing OnSpawn loot system.
if (iRacial == RACIAL_TYPE_ANIMAL ||
iRacial == RACIAL_TYPE_BEAST ||
iRacial == RACIAL_TYPE_CONSTRUCT ||
iRacial == RACIAL_TYPE_OOZE ||
iRacial == RACIAL_TYPE_PLANT ||
iRacial == RACIAL_TYPE_VERMIN)
{
if(DEBUG) {FloatingTextStringOnCreature("Creature doesn't carry treasure", GetFirstPC(), FALSE);}
}
else
{
sd_droploot(OBJECT_SELF, OBJECT_SELF);
}
//:: Get average PC level for area
//:: Cycle through PCs in Area
while (oPC != OBJECT_INVALID)
{
if (GetIsPC(oPC) == TRUE)
{
nTotalPCs++;
nTotalPCLevel = nTotalPCLevel + GetHitDice(oPC);
}
oPC = GetNextObjectInArea(oArea);
}
if (nTotalPCs > 0)
{
nAveragePCLevel = (nTotalPCLevel / nTotalPCs) - 1;
}
else
{
nAveragePCLevel = 2;
}
//:: Only active during Halloween week.
if ((sMonthDay == "10/24") ||
(sMonthDay == "10/25") ||
(sMonthDay == "10/26") ||
(sMonthDay == "10/27") ||
(sMonthDay == "10/28") ||
(sMonthDay == "10/29") ||
(sMonthDay == "10/30") ||
(sMonthDay == "10/31") ||
(sMonthDay == "11/01"))
{
//: Don't spawn skeletons from skeletons or commoners
if (GetResRef(OBJECT_SELF) == "pa_skeleton" || GetResRef(OBJECT_SELF) == "nw_skeleton" || nCommoner > 0)
return;
//:: 33% chance to spawn
if ( Random(100) < 33 )
{
//:: Spawn Skeleton.
eVFX = EffectVisualEffect(VFX_IMP_EVIL_HELP);
oSkelly = CreateObject(OBJECT_TYPE_CREATURE, "nw_skeleton", GetLocation(OBJECT_SELF));
DelayCommand(0.0, ActionDoLevelUp(oSkelly, nAveragePCLevel));
//:: Assign Weapon
int nResult = d6(1);
int nStackSize = 1; // Create 1 items;
string sItem;
if (nResult == 1)
{
sItem = "nw_wplhb001"; //:: Halberd
}
else if(nResult == 2)
{
sItem = "nw_wplsc001"; //:: Scythe
}
else if(nResult == 3)
{
sItem = "nw_wplss001"; //:: Spear
}
else if(nResult ==4)
{
sItem = "nw_wblfh001"; //:: Heavy Flail
}
else if(nResult == 5)
{
sItem = "nw_wswgs001"; //:: Greatsword
}
else
sItem = "nw_waxgr001"; //:: Greataxe
object oWeapon = CreateItemOnObject(sItem, oSkelly, nStackSize);
ReallyEquipItemInSlot(oSkelly, oWeapon, INVENTORY_SLOT_RIGHTHAND);
//:: Apply VFX & Attack
AssignCommand(oSkelly, DetermineCombatRound(OBJECT_SELF));
DelayCommand(0.3, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVFX, oSkelly));
}
}
}