CNR And execute script?

Hello here I am again!

This is most likely a very stupid question but I seem to be struggling here…

So here is my issue!

I installed CNR into my module BUT the handles are already taken, the guide was helpful enough to tell me what to do next but now the scripts do not compile…

So I am most likely placing it wrong in the script itself and I was hoping if anyone would be willing and able to take a look and point at the mistake I am making? Yes I did google this but as english is not my native language I seem to struggle a bit

#include “ph_cop_inc”

void main()
{
object oUsed=GetItemActivated();
object oPC=GetItemActivator();

if(GetTag(oUsed)==“BLACKJACK” && GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC))==“BLACKJACK”)
{
object oTarget=GetItemActivatedTarget();
if(GetDistanceBetween(oPC, oTarget)<5.0)
{
if(AutoDC(DC_EASY, SKILL_PICK_POCKET, oTarget) && !GetObjectSeen(oPC, oTarget) && !GetIsEnemy(oPC, oTarget))
{
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectSleep(), oTarget, 120.0);
}
else
{
FloatingTextStringOnCreature(“You have been detected!”, oPC, FALSE);
AssignCommand(oTarget, CopReportCrime(oPC));
SetIsTemporaryEnemy(oPC, oTarget, TRUE);
DetermineCombatRound();
}
}
else
{
FloatingTextStringOnCreature(“You are too far away”, oPC, FALSE);
}
}
} ExecuteScript (“cnr_module_onact”, OBJECT_SELF);

Anyway sorry for all these questions and thank you gor the help guys I really appreciate it…

There seems to be one or two curly brackets missing… I think. I will see if I can fix and compile it.

1 Like

By the way, it is REALLY hard to follow what your script does when you just put every curly bracket in a row on top of one another like this. Try to make use of “tab” so that it is easier to follow. With your current script the curly brackets didn’t make sense at all, so no wonder it doesn’t compile. I had to “clean it up” in Notepad++ to even make sense of it, and I have no idea if I did this the right way here now (since I actually suck at scripting)…

Ok, here’s what I did, but it still doesn’t compile, and I think that might be because I don’t have the include script you have in your script, but that’s just a guess. Anyway, you could take a look at my attempt, I guess:

Edit2: I erased the script here since it was totally wrong.

Edit: Ok, looking at my attempt again, I think I might have also screwed up the "if"s and "else"s here…

I really appreciate the help but it does not work for me still, gives the same error T_T

Looking at your original script: You need to have a } at the end of the script. That much I’m sure of.

What does your error message say? On which line is the error?

25-4-2020 10:58:32: Error. ‘ph_onmodact’ did not compile.
ph_onmodact.nss(14): ERROR: AFTER END COMPOUND STATEMENT < - This is from your script and I keep getting errors on the lower brackets! T_T

Here is your script again (with a bit of clean up). The curly brackets don’t quite add up so what I did now was just a tiny change. I placed the last curly bracket after ExecuteScript instead. Here’s how it looks now (it is really confusing):

#include “ph_cop_inc”

void main()
{
    object oUsed=GetItemActivated();
    object oPC=GetItemActivator();

		if(GetTag(oUsed)==“BLACKJACK” && GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC))==“BLACKJACK”)
		{
		
		object oTarget=GetItemActivatedTarget();
			if(GetDistanceBetween(oPC, oTarget)<5.0)
			{
				if(AutoDC(DC_EASY, SKILL_PICK_POCKET, oTarget) && !GetObjectSeen(oPC, oTarget) && !GetIsEnemy(oPC, oTarget))
    
				{
				ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectSleep(), oTarget, 120.0);
				}
				else
				{
				FloatingTextStringOnCreature(“You have been detected!”, oPC, FALSE);
				AssignCommand(oTarget, CopReportCrime(oPC));
				SetIsTemporaryEnemy(oPC, oTarget, TRUE);
				DetermineCombatRound();
				}
			}
			else
			{
			FloatingTextStringOnCreature(“You are too far away”, oPC, FALSE);
			}
		}
    
	ExecuteScript (“cnr_module_onact”, OBJECT_SELF);
	
}

Well, yes, I don’t know what I’m doing since your script was so confusing. Try the new one here where I just changed the last part.

Tell you what, maybe you could post the include script here? The “ph_cop_inc”. That way it would be easier to help.

P.S. Sorry, but I might be the last person who should try to help you with this. I work almost exclusively with NWN2 and I am quite bad at scripting (though I am getting somewhat better). :zipper_mouth_face: :upside_down_face:

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…

No worries. I still feel like a total noob sometimes even after two years making modules for NWN2. :slightly_smiling_face:

I’ll take another look. By the way, when you post scripts here try and use Edit: Forget it, the forums can’t display what I’m trying to show.

thanks so much… I am just returning to the scripting field and I do appreciate the help, this makes me feel so incredibly incompetent XD

I can also screenshot the script, not sure if that helps haha XD

Please don’t feel that way. Working with NWN and NWN2 is sometimes a steep learning curve, and I also feel totally incompetent with this most of the time. :yum:

I just opened the NWN toolset again (which I am very unfamiliar with since I only work with the NWN2 toolset) but when I post the include script there it seems there are yet other include scripts required that I don’t have. I think I’ll just have to give up now. I am not the right man for this job. If this were for NWN2 I might have downloaded all the systems you’re using and tried to help but…well, this is above me, I’m afraid.

I am quite sure guys like @NWShacker and @Tarot_Redhand will be able to help you a lot better than me.

1 Like

@Dragonqueeny Before you go any further you really need to see this post in this pinned thread. Here is why. Take this snippet of code copied from above -

SetLocalObject( OBJECT_SELF, “COP_CRIMINAL”, oTarget );
SetLocalInt( OBJECT_SELF, “COP_FINE”, nFine );

If we zoom in to this string literal -

“COP_CRIMINAL”

Look at the quotation marks. One feature that was added to this forum software (after much badgering by some users other than of this site) was to “helpfully” convert ordinary quotes into the 66/99 style that you see above. This really screws up copy and pasting code from your posts to such an extent that such code will throw up a bunch of errors in the compiler that weren’t there when you posted it. This doesn’t happen when you post code in the manner shown in that post I linked to. So in a code block your code will retain its original formatting like -

    SetLocalObject(OBJECT_SELF, "COP_CRIMINAL", oTarget);
    SetLocalInt(OBJECT_SELF, "COP_FINE", nFine);

Which has the added bonus of making it easier to help you.

TR

Oh darn…that tour is giving me a slight panic attack…I am so sorry…

I will try to convert it to the proper coding but…well gotta say the tour does not make much sense to me,

Well to get back on topic I am having issues with combining CNR with the current scripts…In the file it says I need to use the execute file line but now the script is not compiling accordingly…

I will be posting here the script I wish the CNR to merge with:

[details="Summary"]
//::///////////////////////////////////////////////
//:: Name: Blackjack
//:: FileName: ph_onmodact
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    A collection of all custom object properties.
    Currently comprised of: blackjack.
*/
//:://////////////////////////////////////////////
//:: Created By: Rusty Spring
//:: Created On: August 2002
//:://////////////////////////////////////////////
#include "ph_cop_inc"

void main()
{
object oUsed=GetItemActivated();
object oPC=GetItemActivator();

if(GetTag(oUsed)=="BLACKJACK" && GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC))=="BLACKJACK")
    {
    object oTarget=GetItemActivatedTarget();
    if(GetDistanceBetween(oPC, oTarget)<5.0)
        {
        if(AutoDC(DC_EASY, SKILL_PICK_POCKET, oTarget) && !GetObjectSeen(oPC, oTarget) && !GetIsEnemy(oPC, oTarget))
            {
            ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectSleep(), oTarget, 120.0);
            }
        else
                {
                FloatingTextStringOnCreature("You have been detected!", oPC, FALSE);
                AssignCommand(oTarget, CopReportCrime(oPC));
                SetIsTemporaryEnemy(oPC, oTarget, TRUE);
                DetermineCombatRound();
                }
            }
        else
        {
            FloatingTextStringOnCreature("You are too far away", oPC, FALSE);
        }

    }
}
[/details]

This is the line I wish it to:
ExecuteScript (“cnr_module_onact”, OBJECT_SELF);

Basically I just need to figure out how to add that execute file to this scipt in order for it to work,

I don’t know where you got that [details=“Summary”] and [/details] from. All you need to do is this -

[code]
    // Put your code here
[/code]

(like the first of the 2 links pointed to says) which will give you -

    // Put your code here

So your code looks like -

//::///////////////////////////////////////////////
//:: Name: Blackjack
//:: FileName: ph_onmodact
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    A collection of all custom object properties.
    Currently comprised of: blackjack.
*/
//:://////////////////////////////////////////////
//:: Created By: Rusty Spring
//:: Created On: August 2002
//:://////////////////////////////////////////////
#include "ph_cop_inc"

void main()
{
    object oUsed = GetItemActivated();
    object oPC = GetItemActivator();

    if(GetTag(oUsed) == "BLACKJACK" && GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC)) == "BLACKJACK")
    {
        object oTarget = GetItemActivatedTarget();

        if(GetDistanceBetween(oPC, oTarget) < 5.0)
        {
            if(AutoDC(DC_EASY, SKILL_PICK_POCKET, oTarget) && !GetObjectSeen(oPC, oTarget) && !GetIsEnemy(oPC, oTarget))
                ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectSleep(), oTarget, 120.0);
            else
            {
                FloatingTextStringOnCreature("You have been detected!", oPC, FALSE);
                AssignCommand(oTarget, CopReportCrime(oPC));
                SetIsTemporaryEnemy(oPC, oTarget, TRUE);
                DetermineCombatRound();
            }
        }
        else
            FloatingTextStringOnCreature("You are too far away", oPC, FALSE);
    }
}

As to your actual problem, I’m not too sure. I’ll take a look.

TR

@Dragonqueeny wanted to pack the code into an expander to keep the post short:

Summary
    // Put your code here

by doing this:

[details="Summary"]
[code]
    // Put your code here
[/code]
[/details]

but got the tags mixed up in the wrong order.

@Tarot_Redhand, It might be a good idea to add such template somewhere higher in the tour thread - it gets buried under other info. Or maybe pin a shorter “how to post your script code” info thread.


@Dragonqueeny tell us what’s your script is supposed to do and what do you want to achieve.

First reformat the code so that each bracket } is in the same column as its matching { bracket for easier read. You can also use automated tools for that, like this website - It will correct invalid brackets.

Okay this site does not explain all that much to me as it does not take anything away or beautify anything but oh well…at least thank you for burning me on the spot for mixing things up.

So the script itself is an onactivation module script from https://neverwintervault.org/project/nwn1/module/rusty-constabulary

What it does is activate an custom item to knock out guards and such. I would like to keep it as II like the system. But I need to incorporate said script with an executefile line which does not seem to happen.

What I want to see as the result is that I IMPLEMENT The scripts for CNR with the ones I currently have and that none of my other pre-existing systems seize to function.

In that case, you probably want to use something like this:

void main()
{
    object oUsed = GetItemActivated();
    object oPC = GetItemActivator();

    if(GetTag(oUsed) == "BLACKJACK")
    {
        // all the stuff about blackjack you already have
    }
    else
    {
        ExecuteScript("cnr_module_onact", OBJECT_SELF);
    }
}

If blackjack is activated, you handle it. If it isn’t, control is passed to cnr_module_onact script.

Okay maybe a very ridiculous question maybe but this line kinda confuses me.

So the script should be taken as is or should I add the text inbetween? Since it feels like I will not be getting the warning messages if I take it as is…