HoS_PRC8/_mod/_module/nss/crime_to_prison.nss
Jaysyn904 04165202c0 Initial upload
Initial upload
2024-11-25 19:36:07 -05:00

163 lines
6.0 KiB
Plaintext

// send to prison
#include "x3_inc_string"
void fnDoTeleport(object oWP)
{
object oMe=OBJECT_SELF;
AssignCommand(oMe,JumpToObject(oWP));
if (GetArea(oWP)!=GetArea(oMe)) DelayCommand(1.0,fnDoTeleport(oWP));
}
void fnPutInChest(object oItem,object oChest,string sPID)
{
object oCopy=CopyItem(oItem,oChest,TRUE);
SetStolenFlag(oCopy,TRUE);
if (GetStolenFlag(oItem)!=TRUE) SetLocalString(oCopy,"sOwner",sPID);
SetItemCharges(oCopy,GetItemCharges(oItem));
DestroyObject(oItem);
}// fnPutInChest()
void fnGiveBack(object oItem)
{
object oPC=OBJECT_SELF;
object oCopy=CopyItem(oItem,oPC,TRUE);
SetItemCharges(oCopy,GetItemCharges(oItem));
if (GetIsObjectValid(oCopy))
{
SetStolenFlag(oCopy,FALSE);
DelayCommand(0.8,DestroyObject(oItem));
}
else
{ // error
SendMessageToPC(oPC,"'crime_to_prison' ERROR in item return for item with ResRef='"+GetResRef(oItem)+"'!");
} // error
}
void fnGiveItemsBack()
{ // return belongings
object oPC=OBJECT_SELF;
object oChest=GetObjectByTag("MUNICIPALGOODS");
object oItem;
string sPID=GetPCPublicCDKey(oPC)+GetPCPlayerName(oPC)+GetName(oPC);
SendMessageToPC(oPC,"Your belongings are being returned.");
if (GetIsObjectValid(oChest))
{ // return inventory
oItem=GetFirstItemInInventory(oChest);
while(GetIsObjectValid(oItem))
{
if (GetLocalString(oItem,"sOwner")==sPID) fnGiveBack(oItem);
oItem=GetNextItemInInventory(oChest);
}
} // return inventory
else
{ // error
SendMessageToPC(oPC,"ERROR: crime_to_prison : Could not find chest tagged 'MUNICIPALGOODS'");
} // error
SendMessageToPC(oPC,"All of your items should have been returned except those which were stolen.");
} // return belongings
void fnFreePC(object oDest)
{
if (GetDistanceBetween(OBJECT_SELF,oDest)>3.0)
{ // teleport
AssignCommand(OBJECT_SELF,JumpToObject(oDest));
DelayCommand(0.5,fnFreePC(oDest));
} // teleport
}
void fnFreePrisoner()
{ // free the prisoner
object oPC=OBJECT_SELF;
object oWP=GetWaypointByTag("PRISON_FREEDOM");
if (GetIsObjectValid(oWP))
{ // freedom waypoint exists
if (GetArea(oWP)==GetArea(oPC))
{ // free them
AssignCommand(oPC,fnGiveItemsBack());
DelayCommand(3.0,fnFreePC(oWP));
} // free them
else
{ // prison escape
SetLocalInt(oPC,"bPRISONESCAPE",TRUE);
} // prison escape
} // freedom waypoint exists
} // fnFreePrisoner
void fnPrisoner(float fSentence)
{
string sMsg=StringToRGBString("You will be set free in "+IntToString(FloatToInt(fSentence))+" seconds.","777");
object oPC=OBJECT_SELF;
object oWP=GetWaypointByTag("PRISON_FREEDOM");
float fRemaining=fSentence-20.0;
if (GetArea(oWP)==GetArea(oPC)&&fRemaining>0.0)
{ // still in prison
SendMessageToPC(oPC,sMsg);
DelayCommand(20.0,fnPrisoner(fRemaining));
} // still in prison
else
{ // free
fnFreePrisoner();
} // free
DeleteLocalInt(OBJECT_SELF,"nCRIMECOUNT");
}
int fnIsPCTool(object oItem)
{
string sTag=GetTag(oItem);
if (sTag=="rts_powerres"||sTag=="npcact_dm"||sTag=="rtsa_message"||sTag=="RTSCreation_Tool") return TRUE;
else if (sTag=="rts_vampire"||sTag=="rts_it_report"||sTag=="rts_it_squadbadge"||sTag=="RTSStatus_Tool") return TRUE;
else if (sTag=="rts_it_teamwand"||sTag=="RTSUnit_Creation"||sTag=="rts_it_vote"||sTag=="rts_it_manual") return TRUE;
return FALSE;
} // fnIsPCTool()
void main()
{
object oPC=GetPCSpeaker();
object oWP=GetWaypointByTag("MUNICIPAL_PRISON");
object oCHEST=GetObjectByTag("MUNICIPALGOODS");
object oItem;
string sPID=GetPCPublicCDKey(oPC)+GetPCPlayerName(oPC)+GetName(oPC);
float fSentence=180.0;
if (GetIsObjectValid(oWP))
{ // teleport
AssignCommand(oPC,fnDoTeleport(oWP));
if (GetIsObjectValid(oCHEST))
{ // strip inventory
oItem=GetFirstItemInInventory(oPC);
while(GetIsObjectValid(oItem))
{ // put inventory in chest
if (fnIsPCTool(oItem)==FALSE) DelayCommand(0.8,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetNextItemInInventory(oPC);
} // put inventory in chest
oItem=GetItemInSlot(INVENTORY_SLOT_ARROWS,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_BELT,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_BOLTS,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_BOOTS,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_BULLETS,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_CHEST,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_CLOAK,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_HEAD,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_LEFTRING,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_NECK,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
oItem=GetItemInSlot(INVENTORY_SLOT_RIGHTRING,oPC);
if(GetIsObjectValid(oItem))DelayCommand(0.9,fnPutInChest(oItem,oCHEST,sPID));
AssignCommand(oPC,fnPrisoner(fSentence));
} // strip inventory
} // teleport
}