[Fixed!] Improvising a script help

Im not a very good scripter but i created this sysetm that was designed to reward the player when a npc entered a trigger. The problem i am having is i want the trigger to be run when the npc enters the trigger via its unique tag, and I dont have any clue how to do that. would anyone know how I could change it to grab the npc instead?

The issue right now is that the trigger will run regardless if the npc is nearby or not so it repeats, or loops infinitely.

The script is here below

void main()
{
// Get the creature who triggered this event.
object oPC = GetEnteringObject();

// Only fire for (real) PCs.
if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )
    return;

// Have "NPC_Help" say something.
AssignCommand(GetObjectByTag("Sad_Help"), SpeakString("<Insert End Dialogue Here>"));

// Give 12 gold (to party) to the PC.
GiveGoldToAll(oPC, 12);
GiveXPToAll(oPC, 80);

// Destroy an object (not fully effective until this script ends).
DestroyObject(GetObjectByTag("Sad_Help"));

}

#include "x0_i0_partywide"

void main()
{
	object oTarget = GetEnteringObject();
	string sTag = GetTag(oTarget);
	object oPC = GetFirstPC();

	if (sTag == "npc_tag" && !GetLocalInt(OBJECT_SELF, sTag))
	{
		AssignCommand(oTarget, ActionSpeakString("<Insert End Dialogue Here>"));

		GiveGoldToAll(oPC, 12);
		GiveXPToAll(oPC, 80);

		SetLocalInt(OBJECT_SELF, sTag, TRUE);
		AssignCommand(oTarget, ActionDoCommand(SetIsDestroyable(TRUE, FALSE, FALSE)));
		AssignCommand(oTarget, ActionDoCommand(DestroyObject(oTarget));
	}
}

Replace npc_tag with the tag of NPC you want to see.

ah thats what it was! as i understand this the object is the target that is entering the trigger, we get the target by its tag and the rest is history it seems :grinning: thank you for the help Aqvilinus! you just saved me a weeks worth of a headache of trying to figure it out on my own

Okay I had to do a slight change due to the script not compiling this part

AssignCommand(oTarget, ActionDoCommand(SetIsDestroyable(TRUE, FALSE, FALSE));

so i added a combination of your script with my own, and it now works. Im not sure why it didnt compile, it just gave me an error and didnt look at it thoroughly at the time.

You’re welcome, @Wall3t!

Sorry, I missed one bracket on the right. Should be like this:

AssignCommand(oTarget, ActionDoCommand(SetIsDestroyable(TRUE, FALSE, FALSE)));