sure, just don’t beat me up if it becomes all mangled XD
//::///////////////////////////////////////////////
//:: Cop Library
//:://////////////////////////////////////////////
/*
Function Library for all the cop functions
*/
//:://////////////////////////////////////////////
//:: Created By: RustySpring ( breakbeatpete@yahoo.co.uk ) and HueyPLong ( huey@shadowtears.com )
//:: Created On: July-August 2002
//:://////////////////////////////////////////////
#include “NW_I0_GENERIC”
#include “NW_I0_PLOT”
// Cops library
// Settings
string sHeadCopTag = “POLICEHeadCop”;
string sJailCellTag = “COP_JAIL”;
string sCopYellWitnessCrime = “I have witnessed a crime!”;
string sCopYellSpotWanted = “I’ve spotted a wanted person!”;
float fChaseTime = 15.0; // Cop chase time in seconds
// Function Declarations
object GetNearestCop(object oTarget, float nDistance, int nNth=1);
void CopMakeWanted(object oTarget, int nFine);
int CopIsWanted(object oTarget);
int CopGetFine(object oTarget);
void CopAbsolveCrimes(object oTarget);
void CopSendToJail(object oTarget, float fSentence);
void CopPayFine(object oTarget);
void CopReportCrime(object oTarget, int nFine=50);
int CopObjectDC(int DC, int nSkill, object oTarget);
int IsWeapon(int nBaseType);
int IsArmed(object oPC);
// Functions
// Gets the nearest cop - anyone with a tag prefixed POLICE - who has line of sight to the
object GetNearestCop(object oTarget, float nDistance, int nNth=1)
{
location lTarget=GetLocation(oTarget);
object oIsPolice=GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, oTarget, nNth);
while(!(oIsPolice == OBJECT_INVALID))
{
string sTag = GetTag(oIsPolice);
string sPrefix = GetSubString(sTag,0,6);
if (sPrefix == “POLICE” && GetDistanceBetween(oTarget, oIsPolice)<nDistance)
{
return(oIsPolice);
}
nNth++;
oIsPolice=GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, oTarget, nNth);
}
return(OBJECT_INVALID);
}
// Called ONLY by a policeman in his ONUSERDEFINED for dialogue 35353. Otherwise you break things.
// Make the oTarget wanted and set the fine to nFine GP
void CopMakeWanted(object oTarget, int nFine)
{
// Get the tag for the wanted PC:
string sWantedMan = GetTag(oTarget);
// Get the head cop:
object oHeadCop = GetObjectByTag(sHeadCopTag);
// Get the current fine from the head cop if it exists:
int nCurrentFine = GetLocalInt(oHeadCop, sWantedMan+"_MYFINE");
int nCrimeCount = GetLocalInt(oHeadCop, sWantedMan+"_CRIMECOUNT");
nCrimeCount++;
int nNewFine = ( nCurrentFine+((nCrimeCount*nFine)/2) );
// Contact all cops in the faction and let them know about the wanted PC
object oThisCop = GetFirstFactionMember(oHeadCop, FALSE);
while (GetIsObjectValid(oThisCop) == TRUE)
{
// Set it on each cop
SetLocalInt(oThisCop, sWantedMan+"_ISWANTED", 1);
SetLocalInt(oThisCop, sWantedMan+"_MYFINE", nNewFine); //Overwrites nCurrentFine
SetLocalInt(oThisCop, sWantedMan+"_CRIMECOUNT", nCrimeCount);
oThisCop = GetNextFactionMember(oHeadCop, FALSE);
}
}
// Check to see if oTarget is wanted
int CopIsWanted(object oTarget)
{
// Get the tag of the target
string sWantedMan = GetTag(oTarget);
// Check wanted level
if (GetLocalInt(OBJECT_SELF, sWantedMan+"_ISWANTED")) {
return TRUE;
}
return FALSE;
}
// Return value of oTarget’s current fine:
int CopGetFine(object oTarget)
{
// Get the tag of the target
string sWantedMan = GetTag(oTarget);
// Check for a fine and return it:
int nCurrentFine = GetLocalInt(OBJECT_SELF, sWantedMan+"_MYFINE");
return nCurrentFine;
}
// Wipe out all crimes and set GP fine to 0
void CopAbsolveCrimes(object oTarget)
{
// Get the tag for the wanted PC
string sWantedMan = GetTag(oTarget);
// Get the head cop
object oHeadCop = GetObjectByTag(sHeadCopTag);
// Contact all cops in the faction and let them know about the absolved PC
object oThisCop = GetFirstFactionMember(oHeadCop, FALSE);
while (GetIsObjectValid(oThisCop) == TRUE)
{
// Set it on each cop
DeleteLocalInt(oThisCop, sWantedMan+"_ISWANTED");
DeleteLocalInt(oThisCop, sWantedMan+"_MYFINE");
oThisCop = GetNextFactionMember(oHeadCop, FALSE);
}
}
// Send oTarget to jail:
void CopSendToJail(object oTarget, float fSentence)
{
// Absolve them of their crimes:
CopAbsolveCrimes(oTarget);
// Send them to the jail waypoint:
object oJailCell = GetObjectByTag(sJailCellTag);
location lJailCell = GetLocation(oJailCell);
SetLocalInt(oTarget, “JAILED”, 1);
SetLocalFloat(oTarget, “SENTENCE”, fSentence);
AssignCommand( oTarget, ActionJumpToLocation(lJailCell) );
}
// Take the fine from oTarget:
void CopPayFine(object oTarget)
{
// Get the fine:
int nMyFine = GetLocalInt(OBJECT_SELF, GetTag(oTarget)+"_MYFINE");
// Take their money:
TakeGoldFromCreature(nMyFine, oTarget, TRUE);
// Absolve them of their crimes:
CopAbsolveCrimes(oTarget);
}
// Reports oTarget’s crime and sets the fine:
void CopReportCrime(object oTarget, int nFine=50)
{
// Set the criminal and fine:
SetLocalObject( OBJECT_SELF, “COP_CRIMINAL”, oTarget );
SetLocalInt( OBJECT_SELF, “COP_FINE”, nFine );
// Send out a call:
SpeakString (“COP_REPORT_CRIME”, TALKVOLUME_SILENT_TALK);
}
//Determines DC of outcome based on distance of nearest cop, stealth of PC, and daylight.
int CopObjectDC(int DC, int nSkill, object oTarget)
{
/*
Easy = Lvl/4 …rounded up
Moderate = 3/Lvl + Lvl …rounded up
Difficult = Lvl * 1.5 + 6 …rounded up
*/
object oCop=GetNearestCop(oTarget, 25.0);
int nDistance=FloatToInt(GetDistanceToObject(oCop));
SendMessageToPC(oTarget, "The distance of the nearest cop, " + GetTag(oCop) + ", is " + IntToString(nDistance));
int nLevel = 25 - nDistance;
int nTest = 0;
switch (DC)
{
case 0: nTest = nLevel / 4 + 1; break;
case 1: nTest = (3 / nLevel + nLevel) - abs( (nLevel/2) -2); break;
case 2: nTest = FloatToInt(nLevel * 1.5 + 6) - abs( ( FloatToInt(nLevel/1.5) -2)); break;
}
//Begin calculation of SKILL
int iDex = GetAbilityModifier (ABILITY_DEXTERITY, oTarget);
int SKILL = GetSkillRank(nSkill, oTarget);
if(GetIsDay())
{
SendMessageToPC(oTarget, “It’s broad daylight! You are penalised and hide skill is halved.”);
SKILL = SKILL / 2;
}
// FINAL ROLL
if(SKILL + iDex +d4(1)>= (nTest + 10))
{
return TRUE;
}
return FALSE;
}
// This function determines if the specified base-type is a weapon base-type
// Returns TRUE if a weapon, FALSE if not
int IsWeapon(int nBaseType)
{
// int nResult;
switch (nBaseType)
{
case BASE_ITEM_BASTARDSWORD :
case BASE_ITEM_BATTLEAXE :
case BASE_ITEM_CBLUDGWEAPON :
case BASE_ITEM_CLUB :
case BASE_ITEM_DAGGER :
case BASE_ITEM_DART :
case BASE_ITEM_DIREMACE :
case BASE_ITEM_DOUBLEAXE :
case BASE_ITEM_GREATAXE :
case BASE_ITEM_GREATSWORD :
case BASE_ITEM_HALBERD :
case BASE_ITEM_HANDAXE :
case BASE_ITEM_HEAVYCROSSBOW :
case BASE_ITEM_HEAVYFLAIL :
case BASE_ITEM_KAMA :
case BASE_ITEM_KATANA :
case BASE_ITEM_KUKRI :
case BASE_ITEM_LIGHTCROSSBOW :
case BASE_ITEM_LIGHTFLAIL :
case BASE_ITEM_LIGHTHAMMER :
case BASE_ITEM_LIGHTMACE :
case BASE_ITEM_LONGBOW :
case BASE_ITEM_LONGSWORD :
case BASE_ITEM_MAGICROD :
case BASE_ITEM_MAGICSTAFF :
case BASE_ITEM_MAGICWAND : // maybe shouldn’t treat this as weapon??
case BASE_ITEM_MORNINGSTAR :
case BASE_ITEM_QUARTERSTAFF :
case BASE_ITEM_RAPIER :
case BASE_ITEM_SCIMITAR :
case BASE_ITEM_SCYTHE :
case BASE_ITEM_SHORTBOW :
case BASE_ITEM_SHORTSPEAR :
case BASE_ITEM_SHORTSWORD :
case BASE_ITEM_SHURIKEN :
case BASE_ITEM_SICKLE :
case BASE_ITEM_SLING :
case BASE_ITEM_THROWINGAXE :
case BASE_ITEM_TWOBLADEDSWORD :
case BASE_ITEM_WARHAMMER : return TRUE;
break;
}
return FALSE;
} // end IsWeapon
// This function checks if the specified character has weapons drawn
// Returns TRUE or FALSE
int IsArmed(object oPC)
{
object oItem = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC);
int nBaseType1 = GetBaseItemType(oItem);
object oItem2 = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC);
int nBaseType2 = GetBaseItemType(oItem2);
if (IsWeapon(nBaseType1) == TRUE || IsWeapon(nBaseType2) == TRUE)
{
return TRUE;
}
return FALSE;
} // end IsArmed
Maybe to make it easier I am using this system : https://neverwintervault.org/project/nwn1/module/rusty-constabulary
And trying to combine it with https://neverwintervault.org/project/nwn1/script/craftable-natural-resources-cnr
and also have this installed: https://neverwintervault.org/project/nwn1/script/axe-murderers-killer-death-system-1
So I am very much hoiping this helps…