Battledale_PRC8/_module/nss/user_worker.nss
Jaysyn904 7b9e44ebbb Initial upload
Initial upload.  PRC8 has been added.  Module compiles, PRC's default AI & treasure scripts have been integrated.  Started work on top hak for SLA / Ability / Scripting modifications.
2024-03-11 23:44:08 -04:00

198 lines
5.5 KiB
Plaintext

//::///////////////////////////////////////////////
//:: user_worker
//:: user_worker.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
*/
//:://////////////////////////////////////////////
//:: Created By: Lysandius
//:: Created On: 19-07-2002
//:://////////////////////////////////////////////
#include "inc_tavern"
void ActionOpenObject(object oObject);
void ActionCloseObject(object oObject);
void GoCheck(object oCrate);
void CheckCrate(object oCrate);
void GetDrinks(int nWine, int nSpirits);
void Restock(object oCrate);
void main()
{
int nUser = GetUserDefinedEventNumber();
if (nUser == 1004) // ON DIALOGUE
{
int nState = GetLocalInt(OBJECT_SELF, "nState");
if (nState)
SpeakString("Excuse me. I have work to do");
}
if (nUser == 10) // ON INVENTORY LOW // GO CHECK
{
int nState = GetLocalInt(OBJECT_SELF, "nState");
if (!nState)
{
SetLocalInt(OBJECT_SELF, "nState", 1);
SpeakString("I better go see if the bar is still stocked.");
ActionMoveToObject(OBJ_WAYPOINT_STAIRS);
GoCheck(OBJ_CRATE_WINE);
GoCheck(OBJ_CRATE_SPIRITS);
ActionForceMoveToObject(OBJ_WAYPOINT_STAIRS);
ActionForceMoveToObject(OBJ_WAYPOINT_STORAGE);
ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(20))); // ON STOCK LOW
}
}
if (nUser == 20) // ON STOCK LOW // GET DRINKS
{
int nWine = GetLocalInt(OBJECT_SELF, "nWine");
int nSpirits = GetLocalInt(OBJECT_SELF, "nSpirits");
if (nWine == 0 && nSpirits == 0)
SetLocalInt(OBJECT_SELF, "nState", 0);
else
{
ActionMoveToObject(OBJ_CRATE_STORAGE);
ActionOpenObject(OBJ_CRATE_STORAGE);
ActionDoCommand(GetDrinks(nWine, nSpirits));
ActionCloseObject(OBJ_CRATE_STORAGE);
ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(30))); // ON GOT DRINKS
}
}
if (nUser == 30) // ON GOT DRINKS // RESTOCK CRATES
{
int nWine = GetLocalInt(OBJECT_SELF, "nWine");
int nSpirits = GetLocalInt(OBJECT_SELF, "nSpirits");
if (nWine == 1 || nSpirits == 1)
ActionMoveToObject(OBJ_WAYPOINT_STAIRS);
if (nWine == 1)
{
ActionMoveToObject(OBJ_CRATE_WINE);
ActionOpenObject(OBJ_CRATE_WINE);
ActionDoCommand(Restock(OBJ_CRATE_WINE));
ActionCloseObject(OBJ_CRATE_WINE);
}
if (nSpirits == 1)
{
ActionMoveToObject(OBJ_CRATE_SPIRITS);
ActionOpenObject(OBJ_CRATE_SPIRITS);
ActionDoCommand(Restock(OBJ_CRATE_SPIRITS));
ActionCloseObject(OBJ_CRATE_SPIRITS);
}
ActionSpeakString("There. That should do it.");
ActionMoveToObject(OBJ_WAYPOINT_STAIRS);
ActionMoveToObject(OBJ_WAYPOINT_STORAGE);
SetLocalInt(OBJECT_SELF, "nState", 0);
}
}
void Restock(object oCrate)
{
int nWine;
int nSpirits;
object oItem = GetFirstItemInInventory();
while (GetIsObjectValid(oItem))
{
string sTag = GetTag(oItem);
if (sTag == "NW_IT_MPOTION021")
{
DestroyObject(oItem);
}
if (sTag == "NW_IT_MPOTION022")
{
nSpirits += GetNumStackedItems(oItem);
}
if (sTag == "NW_IT_MPOTION023")
{
nWine += GetNumStackedItems(oItem);
}
oItem = GetNextItemInInventory();
}
if (oCrate == OBJ_CRATE_WINE)
TransferItem(OBJ_CRATE_WINE, OBJECT_SELF, "NW_IT_MPOTION023", nWine);
else if (oCrate == OBJ_CRATE_SPIRITS)
TransferItem(OBJ_CRATE_SPIRITS, OBJECT_SELF, "NW_IT_MPOTION022", nSpirits);
}
void GetDrinks(int nWine, int nSpirits)
{
int nAmount;
int nMaxAmount;
nMaxAmount = 10 * nWine;
for (nAmount = 0; nAmount < nMaxAmount; nAmount++)
{
CreateItemOnObject("NW_IT_MPOTION023");
}
nMaxAmount = 10 * nSpirits;
for (nAmount = 0; nAmount < nMaxAmount; nAmount++)
{
CreateItemOnObject("NW_IT_MPOTION022");
}
}
void ActionOpenObject(object oObject)
{
ActionDoCommand(AssignCommand(oObject, DelayCommand(0.5, ActionPlayAnimation(ANIMATION_PLACEABLE_OPEN, 1.0, 2.0))));
ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 1.0, 3.0);
}
void ActionCloseObject(object oObject)
{
ActionDoCommand(AssignCommand(oObject, ActionPlayAnimation(ANIMATION_PLACEABLE_CLOSE, 1.0, 2.0)));
}
void GoCheck(object oCrate)
{
ActionMoveToObject(oCrate);
ActionOpenObject(oCrate);
ActionDoCommand(CheckCrate(oCrate));
ActionCloseObject(oCrate);
}
void CheckCrate(object oCrate)
{
string sTag;
if (oCrate == OBJ_CRATE_WINE)
sTag = "NW_IT_MPOTION023";
if (oCrate == OBJ_CRATE_SPIRITS)
sTag = "NW_IT_MPOTION022";
object oItem = GetFirstItemInInventory(oCrate);
int nAmount;
while (GetIsObjectValid(oItem))
{
if (GetTag(oItem) == sTag)
{
nAmount += GetNumStackedItems(oItem);
}
oItem = GetNextItemInInventory(oCrate);
}
string sVarName;
if (nAmount < INT_STOCKLIMIT_LOW)
{
if (sTag == "NW_IT_MPOTION023")
sVarName = "nWine";
if (sTag == "NW_IT_MPOTION022")
sVarName = "nSpirits";
SetLocalInt(OBJECT_SELF, sVarName, 1);
SpeakString("I'd better fill this crate.");
}
else
{
SetLocalInt(OBJECT_SELF, sVarName, 0);
SpeakString("This crate doesn't need restocking.");
}
}