Help Combining OnActivateItem Scripts
GruffbaneJoe
Member Posts: 39
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);
}
}
}
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);
}
}
}
0
Comments
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.
There's some kind of string that goes with them in my variables. I don't understand it but it's been working.
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?
#include "x2_inc_switches"
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?
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.
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.