Battledale_PRC8/_module/nss/sc_nightwatch.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

164 lines
5.2 KiB
Plaintext

//::///////////////////////////////////////////////
//:: sc_nightwatch
//:://////////////////////////////////////////////
/*
Lets a NPC walk all objects with the tag LampPost and turn them
on/off depending on night or day. Furthermore, if it is night, the NPC equips
a torch while he walks. When he has no work to do, he will sit down on an object
taged NightWatchRest.
*/
//:://////////////////////////////////////////////
//:: Created By: Pad O'Lion
//:: Created On: 06/25/2002
//:://////////////////////////////////////////////
//
// Placed in NPCs heartbeat event
object FindTorchInInventory();
object FindLanternToSwitch(object oStartSearch);
void SwitchLight(object oLanternToSwitch);
void main()
{
if (IsInConversation(OBJECT_SELF))
{
return;
}
float fDistance = 0.0;
int nAction = 0;
int nDay = GetIsDay();
object oLantern = GetLocalObject(OBJECT_SELF, "oLantern");
if (oLantern != OBJECT_INVALID)
{
//SendMessageToAllDMs("Nightwatch: Going to lantern");
fDistance = GetDistanceToObject(oLantern);
if (fDistance >=0.0 && fDistance <= 2.0)
{
//SendMessageToAllDMs("Nightwatch: Arrived at lantern");
SwitchLight(oLantern);
SetLocalObject(OBJECT_SELF, "oLantern", OBJECT_INVALID);
}
}
else
{
//SendMessageToAllDMs("Nightwatch: Searching lantern");
oLantern = FindLanternToSwitch(OBJECT_SELF);
if (oLantern != OBJECT_INVALID)
{
PlayAnimation(ANIMATION_LOOPING_PAUSE_TIRED);
//SendMessageToAllDMs("Nightwatch: Found lantern");
SetLocalObject(OBJECT_SELF,"oLantern",oLantern);
AssignCommand(OBJECT_SELF, ActionMoveToObject(oLantern,TRUE));
}
else
{
SetLocalObject(OBJECT_SELF, "oLantern", OBJECT_INVALID);
//SendMessageToAllDMs("Nightwatch: Going to rest");
object oRestPlace = GetObjectByTag("NightWatchRest");
AssignCommand(OBJECT_SELF, ActionMoveToObject(oRestPlace,TRUE));
AssignCommand(OBJECT_SELF, ActionSit(oRestPlace));
}
}
// unequip torch when it's day
object oTorch = FindTorchInInventory();
if (oTorch != OBJECT_INVALID && nDay == TRUE)
{
//SendMessageToAllDMs("Nightwatch unequip torch");
AssignCommand(OBJECT_SELF, ActionUnequipItem(oTorch));
}
// equip torch when it's night
if (oTorch != OBJECT_INVALID && nDay == FALSE)
{
//SendMessageToAllDMs("Nightwatch equip torch");
AssignCommand(OBJECT_SELF, ActionEquipItem(oTorch, INVENTORY_SLOT_RIGHTHAND));
}
}
object FindTorchInInventory()
{
object oFound = GetFirstItemInInventory(OBJECT_SELF);
while(GetIsObjectValid(oFound))
{
if(GetTag(oFound) == "NightWatchTorch")
{
return oFound;
}
oFound = GetNextItemInInventory(OBJECT_SELF);
}
oFound = GetItemInSlot(INVENTORY_SLOT_LEFTHAND);
if (GetTag(oFound) == "NightWatchTorch")
{
return oFound;
}
oFound = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND);
if (GetTag(oFound) == "NightWatchTorch")
{
return oFound;
}
return OBJECT_INVALID;
}
object FindLanternToSwitch(object oStartSearch)
{
int nNth = 1;
int nDay = GetIsDay();
int nLimit = 20;
object oCheckLantern;
object oTorch;
oCheckLantern = GetNearestObjectByTag("LampPost", OBJECT_SELF, nNth);
while (oCheckLantern != OBJECT_INVALID && nNth <= nLimit)
{
// SpeakString("Checking Lantern #" + IntToString(nNth));
if (GetLocalInt(oCheckLantern,"NW_L_AMION") == 1 && nDay == TRUE)
{
// Light needs to be turned off
SpeakString("Oh my .. time to turn off the lights.");
//SendMessageToAllDMs("Found lamp to turn off");
return oCheckLantern;
}
if (GetLocalInt(oCheckLantern,"NW_L_AMION") == 0 && nDay == FALSE)
{
// Light needs to be turned on
SpeakString("Oh my .. time to turn on the lights.");
//SendMessageToAllDMs("Found lamp to turn on");
return oCheckLantern;
}
nNth++;
oCheckLantern = GetNearestObjectByTag("LampPost", OBJECT_SELF, nNth);
}
return OBJECT_INVALID;
}
void SwitchLight(object oLanternToSwitch)
{
int nAction = GetLocalInt(oLanternToSwitch,"NW_L_AMION");
float fDistanceSecurityCheck = GetDistanceToObject(oLanternToSwitch);
// Do another distancecheck
if (fDistanceSecurityCheck >=0.0 && fDistanceSecurityCheck <= 2.0)
{
if (nAction == 0)
{
//SendMessageToAllDMs("Switching Lantern on");
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
SetPlaceableIllumination(oLanternToSwitch, TRUE);
SetLocalInt(oLanternToSwitch,"NW_L_AMION",1);
RecomputeStaticLighting(GetArea(oLanternToSwitch));
}
else
{
//SendMessageToAllDMs("Switching Lantern off");
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
SetPlaceableIllumination(oLanternToSwitch, FALSE);
SetLocalInt(oLanternToSwitch,"NW_L_AMION",0);
RecomputeStaticLighting(GetArea(oLanternToSwitch));
}
}
}