Skip to content

Help Combining OnActivateItem Scripts

I combined two OnActivteItem module scripts in order to get players to drop heads when killed, and to accomplish some crafting for player housing. It compiled successfully :

void main()
{
object oItem = GetItemActivated();
object oActivator = GetItemActivator();

if (GetTag(oItem) == "PCHead")
{
string sSkullName = GetLocalString(oItem, "SkullName");
string sKillerName = GetLocalString(oItem, "KillerName");

string sMessage = "SKULL: I be the head of " + sSkullName + ", woe to my killer known as " + sKillerName + "!";
SendMessageToPC(oActivator, sMessage);
}

// * 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;
}

}
ExecuteScript("struc_tool_onuse", OBJECT_SELF); // Player Housing
ExecuteScript("struc_activ_furn", OBJECT_SELF); // Player Housing
}




But I can't seem to get it to compile with the recall script I want, posted below.
Can anyone combine the two scripts? Hopefully seeing it done will help me understand the process better.



object oActivated = GetItemActivated();
switch(2);
{
// Item 1 = Stone of Recall type item.
case 1: if(GetTag(oActivated) == "item1")
{
object oObject = GetItemActivator();
object oTarget = GetItemActivator();
location lLocation = GetLocation(oObject);
{
// Object 1 = A Placeable object (invisible object works best). Must be the blueprint name NOT TAG!!
CreateObject(OBJECT_TYPE_PLACEABLE, "object1", lLocation, FALSE);
}
{
// stonerecall02 = name of second script
ExecuteScript("stonerecall02", oTarget);
}
}
}

Comments

  • WilliamDracoWilliamDraco Member Posts: 175
    void main()
    {
      object oItem = GetItemActivated();
      object oActivator = GetItemActivator();
      string sItemTag = GetTag(oItem);
    
      if (sItemTag == "PCHead")
      {
      string sSkullName = GetLocalString(oItem, "SkullName");
      string sKillerName = GetLocalString(oItem, "KillerName");
    
      string sMessage = "SKULL: I be the head of " + sSkullName + ", woe to my killer known as " + sKillerName + "!";
      SendMessageToPC(oActivator, sMessage);
      }
      else if(sItemTag == "item1")
      {
        location lLocation = GetLocation(oActivator);
        // Object 1 = A Placeable object (invisible object works best). Must be the blueprint name NOT TAG!!
        CreateObject(OBJECT_TYPE_PLACEABLE, "object1", lLocation, FALSE);
        // stonerecall02 = name of second script
        ExecuteScript("stonerecall02", oActivator);
      }
    
      ExecuteScript("struc_tool_onuse", OBJECT_SELF); // Player Housing
      ExecuteScript("struc_activ_furn", OBJECT_SELF); // Player Housing
      
      // * 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;
        }
      }
    }
    

    That's a strict combining of the two. It appears you had extracted a part out of a bigger script, and the switch was messy and unnecessary for the snippet you pasted here.

    Do note that the above means that the player house scripts will run every time any item is activated... That would be fairly unusual although I have to assume those scripts have their own code for confirming appropriate triggers & behavior.
  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    Thanks so much!

    There's some kind of string that goes with them in my variables. I don't understand it but it's been working.
  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    This one comes up with the same error message I got before:

    11/3/2019 7:57:55 PM: Error. 'x2_mod_def_act3' did not compile.
    x2_mod_def_act3.nss(32): ERROR: NO RIGHT BRACKET ON EXPRESSION

    And highlights the same expression:

    if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)

    Is there some newb mistake I'm making with copy/paste?
  • BalanorBalanor Member Posts: 176
    Put this at the top of your script above the void main() line:
    #include "x2_inc_switches"
  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    Very cool that one compiled! Woohoo, thanks!
  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    Wow these instructions for making a recall stone must be ancient. The next script in the sequence doesn't compile either. Would you happen to know of a simpler recall stone system?

    https://nwn.fandom.com/wiki/Stone_of_recall_system


    void main()
    {
    object oActivated = GetItemActivated();
    switch(2);
    {
    case 1: if(GetTag(oActivated) == "item1")
    {
    object oPC = GetItemActivator();
    // waypoint1 = Tag of waypoint where the player will be taken to when they activate the stone
    object oTarget = GetWaypointByTag ("waypoint1");
    AssignCommand (oPC,JumpToObject(oTarget));
    ApplyEffectToObject (DURATION_TYPE_INSTANT, EffectVisualEffect (VFX_IMP_HOLY_AID), oPC);
    }
    }
    }



    The command (switch2) cannot be followed by a null statement...whatever that is.

    But then why could it be followed with a null statement, whatever that is, when this tutorial was created?


  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    edited November 2019
    Your script compiled, so much appreciated, However, I ended up going with this other Stone of Recall Script that doesn't need OnActivateItem, since the next part of that tutorial yielded a second problematic script.
  • WilliamDracoWilliamDraco Member Posts: 175
    I've no idea what those instructions were trying to do. a switch statement says "Depending on (this thing in brackets) trigger the appropriate Case # statement".
    Therefore, saying switch(2) just says "trigger Case 2" - which is pointless to begin with, it should just directly use whatever is in Case 2.
    And secondly there is no Case 2, which might have been the cause for the Null statement thing.

    Either way, happy that you found an alternative.
  • GruffbaneJoeGruffbaneJoe Member Posts: 39
    edited November 2019
    I looked back at my old saves and the switch (2) seems to have been part of the original default bioware script. I added lines per the instructions of two haks, a Headhunter hak and a housing hak.

    I'm not sure if the headhunter thing works, as I don't have another player to kill me and see if I drop a head. The housing thing works. It has another couple lines of script that go in another module property, scripts to go along with the items and in the Area functions, and a variable called FURNITURE int 1. I haven't yet tried to see if it works outside of housing, but it's not supposed to and I sure hope it doesn't because folks would be sprouting buildings all over the server.
Sign In or Register to comment.