LoD_PRC8/_module/nss/elv_caveinctr.nss
Jaysyn904 94990edc60 Initial Upload
Initial Upload
2023-09-21 21:20:34 -04:00

154 lines
4.4 KiB
Plaintext

const int nCaveInCycle = 7;
const int SHAKE_CHANCE = 90;
const int FURTHER_SHAKE_CHANCE = 67;
const int CAVEIN_CHANCE = 30;
const int DO_NOTHING = 0;
const int DO_SHAKE = 1;
const int DO_FURTHER_SHAKE = 2;
const int DO_CAVEIN = 3;
const int SHAKE_EVENT = 100;
const int NEAR_CAVEIN_EVENT = 200;
const int FULL_CAVEIN_EVENT = 300;
int isPCInArea(object oArea)
{
object oThing = GetFirstObjectInArea(oArea);
while(oThing != OBJECT_INVALID)
{
if( GetIsPC(oThing) )
{
return TRUE;
}
oThing = GetNextObjectInArea(oArea);
}
return FALSE;
}
void sendMessageToAllPCsInArea(object oArea, string sMessage)
{
object oThing = GetFirstObjectInArea(oArea);
while(oThing != OBJECT_INVALID)
{
if( GetIsPC(oThing) )
{
if( !GetLocalInt(oThing, "alreadyWarnedAboutCaveIn") )
{
DelayCommand(1.0f, SendMessageToPC(oThing, sMessage));
SetLocalInt(oThing, "alreadyWarnedAboutCaveIn", TRUE);
}
}
oThing = GetNextObjectInArea(oArea);
}
}
void main()
{
int nTimer = GetLocalInt(OBJECT_SELF, "timer");
if( nTimer != nCaveInCycle )
{
SetLocalInt(OBJECT_SELF, "timer", ++nTimer);
return;
}
else
{
int nCaveEvent = DO_NOTHING;
if(d100(1) <= SHAKE_CHANCE)
{
// SpeakString("Shake", TALKVOLUME_SHOUT);
nCaveEvent = DO_SHAKE;
if(d100(1) <= FURTHER_SHAKE_CHANCE)
{
// SpeakString("Further Shake", TALKVOLUME_SHOUT);
nCaveEvent = DO_FURTHER_SHAKE;
if(d100(1) <= CAVEIN_CHANCE)
{
// SpeakString("Cave In", TALKVOLUME_SHOUT);
nCaveEvent = DO_CAVEIN;
}
}
}
// SpeakString( "nCaveEvent = " + IntToString(nCaveEvent));
object oArea = GetArea(OBJECT_SELF);
int bIsPCsInArea = isPCInArea(oArea);
if( nCaveEvent != DO_NOTHING && bIsPCsInArea )
{
int bHasCaveInSpots = FALSE;
int nCurrentCount = 0;
object oCaveInSpot;
bHasCaveInSpots = GetLocalInt(OBJECT_SELF, "hasCaveInSpots");
if(!bHasCaveInSpots)
{
oCaveInSpot = GetFirstObjectInArea();
}
else
{
oCaveInSpot = GetLocalObject(OBJECT_SELF, "caveInGenerator" + IntToString(nCurrentCount));
}
while( oCaveInSpot != OBJECT_INVALID )
{
if( bHasCaveInSpots || GetTag(oCaveInSpot) == "elv_caveingenerator" )
{
event evShake = EventUserDefined(SHAKE_EVENT);
event evNearCaveIn = EventUserDefined(NEAR_CAVEIN_EVENT);
event eFullCaveIn = EventUserDefined(FULL_CAVEIN_EVENT);
switch(nCaveEvent)
{
case DO_SHAKE:
// SpeakString("Doing Shake", TALKVOLUME_SHOUT);
SignalEvent(oCaveInSpot, evShake);
break;
case DO_FURTHER_SHAKE:
// SpeakString("Doing Further Shake", TALKVOLUME_SHOUT);
SignalEvent(oCaveInSpot, evNearCaveIn);
break;
case DO_CAVEIN:
// SpeakString("Doing Cave In", TALKVOLUME_SHOUT);
SignalEvent(oCaveInSpot, eFullCaveIn);
break;
}
}
if(!bHasCaveInSpots)
{
SetLocalObject(OBJECT_SELF, "caveInGenerator" + IntToString(nCurrentCount++), oCaveInSpot);
oCaveInSpot = GetNextObjectInArea();
}
else
{
oCaveInSpot = GetLocalObject(OBJECT_SELF, "caveInGenerator" + IntToString(++nCurrentCount));
}
}
if(!bHasCaveInSpots)
{
SetLocalInt(OBJECT_SELF, "hasCaveInSpots", TRUE);
}
}
if (bIsPCsInArea)
{
sendMessageToAllPCsInArea( oArea, "Be careful, this cave appears to be very unstable.");
}
DeleteLocalInt(OBJECT_SELF, "timer");
}
}