You are here

WHat happened? Tagbased scripting no longer works?

12 posts / 0 new
Last post
Dragonqueeny
WHat happened? Tagbased scripting no longer works?

#include "ph_cop_inc"

#include "x2_inc_switches"
 
void main()
{
object oUsed=GetItemActivated();
object oPC=GetItemActivator();
object oItem = GetItemActivated();
 
     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }
 
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);
 
{
 
 
     }
 
}
    }
}
 
 
 
So can anyone tell me what I did wrong here to make the tag-activation work?
  • up
    50%
  • down
    50%
Mannast

Do you have a script that sets MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS = TRUE on the module? It would likely be your OnModuleLoad script.

Portable Hole System, Scry and Teleport System, Throwing Objects, Prodding Traps, Portable Placeables and a Vanilla Basemodule, among other things

  • up
    100%
  • down
    0%
TheBarbarian

Is this script in the module's OnActivateItem event, or is it a script named for the tag of an item?

Some of that code is directly from the default state of x2_mod_def_act, but then there's this "ExecuteScript ("cnr_module_onact", OBJECT_SELF);"  line smack dab in the middle that suggests it might be a tagbased script that's circling back to the module's OnItemActivate event?

Here's something that might help. The idea is that the module's OnItemActivate event executes a script named to match the activated item's tag, and signals a specific event type to go with that (as do other module events, like OnAcquireItem or OnPlayerEquipItem). In the script named to match the item's tag, you check which event has been signalled and write in what's supposed to happen for a particular event.

Also:

        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }
^- If the conditions for this are being met, your script is aborting at this point. If you're adding code directly to your OnActivateItem event, add it before this, not after.
  • up
    100%
  • down
    0%
Dragonqueeny

this is my activate item script on mod

  • up
    50%
  • down
    50%
Proleric
Proleric's picture

Is the script firing at all? You can put SendMessageToPC statements at various points in the script to see which sections are executing (if any).

NWN and DAO adventures at http://proleric.com/

  • up
    100%
  • down
    0%
Dragonqueeny

This is a ModonActivate script though the tagbased items are not working!

  • up
    50%
  • down
    50%
TheBarbarian

When all else fails, here's what you do:

Restore the script to it's original or last working state.

You can revert to the Bioware default by deleting your edited x2_mod_def_act. Leave the references intact. When the windows pop up asking for confirmation, hit YES on the first and then NO on the second.

If this is the same module you're using those giant script- and AI-overriding packages in, you might want to check whether those packages shipped with an edited x2_mod_def_act, and use that instead of the Bioware default.

  • up
    50%
  • down
    50%
Mannast

So I suggest 2 scripts instead of the one...
---------------------------OnModActivate script
#include "ph_cop_inc"

#include "x2_inc_switches"

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

// * Generic Item Script Execution Code
// * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
// * it will execute a script that has the same name as the item's tag
// * inside this script you can manage scripts for all events by checking against
// * GetUserDefinedItemEventNumber(). See x2_it_example.nss
ExecuteScript ("cnr_module_onact", OBJECT_SELF);//I moved this up here...
if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
if (nRet == X2_EXECUTE_SCRIPT_END)
{
return;
}
}//close the if here
} //I would end your OnActivate script here
-------------------------script "BLACKJACK" called when oUsed is used as a special power
void main()
{
object oUsed=GetItemActivated();
object oPC=GetItemActivator();
object oTarget=GetItemActivatedTarget();
if(GetTag(oUsed)=="BLACKJACK" && GetTag(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC))=="BLACKJACK")
{
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);
}
}//added statement if first if is invalid.
SendMessageToPC(oPC, "You need to wield this before you try and use it.");//though wielded objects with Special Powers MUST be wielded to be used.
}
---------------------------
Hope that might be helpful! Not being at my toolset, I don't recall if the scripts allow caps - in which case having the all caps tag may be involved... though I think "blackjack" would work just as well

  • up
    50%
  • down
    50%
Dragonqueeny

Getting an error for the last part, something about wrong bracket....

  • up
    50%
  • down
    50%
TheBarbarian

It's probably the missing include files, if you copypasted the second text block in as-is.

Several of the functions in the script come from different files, like CopReportCrime() from "ph_cop_inc", and AutoDC() and DetermineCombatRound() from "nw_i0_generic". If I recall correctly, ph_cop_inc includes nw_i0_generic, though, so you just need to include ph_cop_inc.

#include "InsertTheNameOfTheScriptHere"

Check the first block Mannast posted for you, or your own initial post.

  • up
    100%
  • down
    0%
Mannast

And I think the brackets could very well be off - I didn't run anything through a compiler - I just cut and pasted in the comment entry.  If I get a chance, I might be able to actually do this in a toolset and fix what i posted.

I was able to check - it was just the includes that were off.  The bracketing works.  Since I don't have the includes myself, I couldn't check if the process actually works, but the scripts compiled when I made dummy files.

  • up
    100%
  • down
    0%
Tarot Redhand

A quick and easy way to find problems with brackets and braces is to use notepad++. Copy and paste your code into that. Put the cursor (not just the mouse pointer) next to either a bracket or a brace and it will turn red. Not only that but the bracket or brace that it should be paired with will also turn red. Makes finding missing brackets and braces dead easy.

TR

  • up
    100%
  • down
    0%