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

293 lines
8.9 KiB
Plaintext

//::///////////////////////////////////////////////
//:: Custom User Defined Event
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
//#include "array_api"
#include "rpo_inc"
#include "NW_I0_GENERIC"
void DoImprison();
void CheckPrisoners();
void Init();
void LockPrison(int nNum);
int GetFreePrison();
void swtWalk();
void swtSit();
void swtChange();
void Init()
{
CreateIntArray("Prisons", 3, TRUE);
SetLocalString(OBJECT_SELF, "PrisonTag", "GuardPrison_");
SetLocalInt(OBJECT_SELF, "Locking", FALSE);
SetLocalInt(OBJECT_SELF, "Freeing", FALSE);
SetLocalInt(OBJECT_SELF, "Init", TRUE);
}
void main()
{
if (GetLocalInt(OBJECT_SELF, "Init") == FALSE)
Init();
int nUser = GetUserDefinedEventNumber();
if(nUser == 1001) //HEARTBEAT
{
int nFreeing = GetLocalInt(OBJECT_SELF, "Freeing");
int nLocking = GetLocalInt(OBJECT_SELF, "Locking");
if (GetIsObjectValid(GetPrisonerToImprison(OBJECT_SELF)))
{
if (!nFreeing)
DoImprison();
}
else
{
if (!nLocking && !GetIsInCombat())
{
int nNum = 0;
location lPrisonDoor;
object oCell = OBJECT_INVALID;
DebugString(GetName(OBJECT_SELF) + " is checking the prison cells.");
while (nNum < 3)
{
oCell = GetObjectByTag("PrisonDoor_" + IntToString(nNum));
lPrisonDoor = GetLocation(GetObjectByTag("GuardPrisonPost_" + IntToString(nNum)));
if (GetIsOpen(oCell))
{
DebugString(GetName(OBJECT_SELF) + ": Cell " + IntToString(nNum) + " is open. Going to close ...");
if (!nLocking)
ClearAllActions();
ActionForceMoveToLocation(lPrisonDoor, TRUE);
ActionCloseDoor(oCell);
nLocking = TRUE;
}
nNum++;
}
if (nLocking)
{
SetLocalInt(OBJECT_SELF, "Locking", TRUE);
ActionDoCommand(SetLocalInt(OBJECT_SELF, "Locking", FALSE));
}
else
SetLocalInt(OBJECT_SELF, "Locking", FALSE);
}
else
ActionDoCommand(SetLocalInt(OBJECT_SELF, "Locking", FALSE));
if(d3() == 1 && !GetIsInCombat() && !nLocking && !nFreeing)
swtChange();
if (!nFreeing && !nLocking)
CheckPrisoners();
}
}
else if(nUser == 1002) // PERCEIVE
{
object oHostile = GetLastHostileActor();
if (GetIsObjectValid(oHostile))
SpeakString("Ey! Leave that alone!");
}
else if (nUser == 1003) // OnCombatRoundEnd
{
object oLastAttacker = GetLastAttacker();
if (GetIsObjectValid(oLastAttacker))
{
if (GetIsObjectValid(oLastAttacker))
if (GetIsPC(oLastAttacker))
if (GetIsObjectValid(oLastAttacker) && GetIsPC(oLastAttacker))
if (!GetIsObjectValid(GetLocalObject(oLastAttacker, "Prisoner")))
{
//SetLocalInt(oLastAttacker, "RPO_Reputation", RPO_PLAYER_REPUTATION_CRIMINAL);
DebugString(GetName(oLastAttacker) + " reputation set to RPO_PLAYER_REPUTATION_CRIMINAL! (OnCombatRoundEnd)");
AddPrisoner(oLastAttacker);
}
}
}
else if(nUser == 1004) // ON DIALOGUE
{
}
else if(nUser == 1005) // ATTACKED
{
}
else if(nUser == 1006) // DAMAGED
{
}
else if(nUser == 1007) // DEATH
{
}
else if(nUser == 1008) // DISTURBED
{
}
else if (nUser == 10001) // Userdefined
{
}
else if (nUser == 10002)
{
}
}
void CheckPrisoners()
{
int nNum = 0;
object oPrisoner = OBJECT_INVALID;
DebugString(GetName(OBJECT_SELF) + " is checking his prisoners.");
while (nNum < GetObjectArraySize("Prisoners") && !GetIsInCombat())
{
oPrisoner = GetObjectArray("Prisoners", nNum);
if (GetLocalInt(oPrisoner, "PlayerState") == PWS_PLAYER_STATE_PRISON)
{
DebugString(GetName(OBJECT_SELF) + " checking prisoner " + GetName(oPrisoner));
int nRandom = Random(99) + 1;
if (nRandom <= 5)
{
SetLocalInt(OBJECT_SELF, "Freeing", TRUE);
int nCell = GetLocalInt(oPrisoner, "PrisonCell");
DebugString("Setting " + GetName(oPrisoner) + " free from cell #" + IntToString(nCell));
object oPrisonDoor = GetObjectByTag("PrisonDoor_" + IntToString(nCell));
SetLocalInt(oPrisoner, "PlayerState", PWS_PLAYER_STATE_ALIVE);
SetLocalInt(oPrisoner, "RPO_Reputation", RPO_PLAYER_REPUTATION_LAWFUL);
RemovePrisoner(oPrisoner);
SetIntArray("Prisons", nCell, TRUE);
AdjustReputation2(oPrisoner, OBJECT_SELF, 50);
SetStandardFactionReputation(STANDARD_FACTION_COMMONER, 50, oPrisoner);
ClearAllFactionMembers (OBJECT_SELF, oPrisoner);
ClearAllActions();
ActionSpeakString(GetName(oPrisoner) + ", ya time is up ... yer free now. But stay out of trouble!");
ActionOpenDoor(oPrisonDoor);
ActionDoCommand(SetLocalInt(OBJECT_SELF, "Freeing", FALSE));
}
else
if (GetTimeSecond() <= 6)
ActionSpeakString("Well, ya time is nay up yet.");
}
nNum++;
}
}
void DoImprison()
{
int nFreePrison;
string sPrisonTag;
DebugString(GetName(OBJECT_SELF) + "is going to imprison ...");
if (!GetIsInCombat())
{
object oPrisoner = GetPrisonerToImprison();
if (GetIsObjectValid(oPrisoner))
{
if (GetLocalInt(oPrisoner, "PlayerState") != PWS_PLAYER_STATE_PRISON &&
!GetIsObjectValid(GetLocalObject(oPrisoner, "Prisoner")) ||
GetLocalObject(oPrisoner, "Prisoner") == OBJECT_SELF)
{
ClearAllActions();
SetLocalInt(OBJECT_SELF, "Freeing", FALSE);
SetLocalInt(OBJECT_SELF, "Locking", FALSE);
DebugString("Going to imprison " + GetName(oPrisoner));
ActionMoveToObject(oPrisoner, TRUE);
ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0f, 5.0f);
ActionDoCommand(SpeakString("Served ya well. Now to the prison with ya!"));
nFreePrison = GetLocalInt(oPrisoner, "PrisonCell");
sPrisonTag = GetLocalString(OBJECT_SELF, "PrisonTag") + IntToString(nFreePrison);
SetLocalInt(oPrisoner, "PrisonCell", nFreePrison);
ActionDoCommand(Imprison(oPrisoner, OBJECT_SELF, sPrisonTag));
ActionJumpToObject(GetObjectByTag("GuardPrisonPost_" + IntToString(nFreePrison)));
ActionDoCommand(SetLocalInt(oPrisoner, "PlayerState", PWS_PLAYER_STATE_PRISON));
//ActionDoCommand(SetLocalInt(oPrisoner, "RPO_REPUTATION", RPO_PLAYER_REPUTATION_CRIMINAL));
LockPrison(nFreePrison);
ActionSpeakString("Ya'll stay in here till ya time is up! Is that understood!?");
}
}
}
}
int GetFreePrison()
{
int nNum = 0;
while (nNum < GetIntArraySize("Prisons"))
{
DebugString("Checking Prison: " + IntToString(nNum));
if (GetIntArray("Prisons", nNum) == TRUE)
return nNum;
nNum++;
}
return 0;
}
void LockPrison(int nNum)
{
object oPrisonDoor = GetObjectByTag("PrisonDoor_" + IntToString(nNum));
location lPrisonDoor = GetLocation(GetObjectByTag("GuardPrisonPost_" + IntToString(nNum)));
SetIntArray("Prisons", nNum, FALSE);
DebugString("Locking Prison #" + IntToString(nNum));
ActionMoveToLocation(lPrisonDoor, TRUE);
ActionDoCommand(AssignCommand(oPrisonDoor, ActionCloseDoor(oPrisonDoor)));
ActionLockObject(oPrisonDoor);
}
void swtWalk()
{
SetLocalInt(OBJECT_SELF, "nSitting", 0);
ActionRandomWalk();
}
void swtChange()
{
if(GetLocalInt(OBJECT_SELF, "nSitting"))
swtWalk();
else
swtSit();
}
void swtSit()
{
object oSittable = GetNearestObjectByTag("Sittable");
ActionMoveToLocation(GetLocation(oSittable)); // a1 No: go to the nearest sittable.
SetLocalInt(OBJECT_SELF, "nSitting", 1);
ActionSit(oSittable); // a2 No: sit down.
}