Lightfoot is right. You're missing this line needed to fully support tag scripting:
// In the OnActivateItem, before the ExecuteScript( sTag, oPC ); line.
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
With all the other lines in there, I was looking at what was there instead of what wasn't.
Could use a lil help with a few scripts.
Débuté par
Lazarus Magni
, sept. 21 2011 07:52
#26
Posté 23 septembre 2011 - 06:19
#27
Posté 23 septembre 2011 - 08:24
Well I can give that a shot and let you all know if that makes any difference... but when I do that I get this error message:
9/23/2011 3:23:14 AM: Error. 'mod_onactivate' did not compile.
mod_onactivate.nss(966): ERROR: UNDEFINED IDENTIFIER (SetUserDefinedItemEventNumber)
9/23/2011 3:23:14 AM: Error. 'mod_onactivate' did not compile.
mod_onactivate.nss(966): ERROR: UNDEFINED IDENTIFIER (SetUserDefinedItemEventNumber)
#28
Posté 23 septembre 2011 - 08:27
That's called from this include:
#include "x2_inc_switches"
When I took a quick look to see if your script had that one, I looked at the mod load include list by mistake. Add that in with the rest of your includes and it should compile.
#include "x2_inc_switches"
When I took a quick look to see if your script had that one, I looked at the mod load include list by mistake. Add that in with the rest of your includes and it should compile.
#29
Posté 23 septembre 2011 - 08:35
Here is the Tagbased Scripting Template Script I use Now...
// my_tbi_template
// (Tag-based Item Script Template)
////////////////////////////////////////////////////////////////////////////////
// Created by: The Krit
// Created on: 04-03-2010
// Modified by: Genisys / Guile
// Modified on: 04-30-2011
///////////////////////////////////////////////////////////////////////////////
// This is intended to be a starting point for writing an item's tag-based script.
// Copy this to a script whose name is the tag of the item in question.
// Edit the event handlers (scroll down to find them) as desired.
// -----------------------------------------------------------------------------
//Required Include (DO NOT TOUCH!)
#include "x2_inc_switches"
//------------------------------------------------------------------------------
// Delcare ALL Common Integers / Floats / Strings
// NOTE: These can be used anywhere in any of the Prototypes
// By declaring at the top of the script they do not need to be delcared anywhere else!
int nInt, i, nGold, nXP, nclass, nCon; // nCon = nConstant
float fDelay, fTime;
string sName, sTag, sMsg, sResref;
//Add more if needed!
// -----------------------------------------------------------------------------
// Event handlers
// -----------------------------------------------------------------------------
// This second part is where you add your desired functionality. Each event
// has its own function with relavant information passed as parameters.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// oItem was acquired (by a PC or an NPC).
// Run by the module.
void OnAcquire(object oItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was activated ("activate item" or "unique power").
// Run by the module.
void OnActivate(object oItem, object oActTarget, location lActTarget, object oActivator)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was equipped by a PC.
// Run by the module.
void OnEquip(object oItem, object oEquippedBy)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem is a weapon that just hit a target, or it is the armor of someone who
// was just hit by someone else's weapon.
// Run by the caster.
void OnHit(object oItem, object oHitTarget, object oCaster)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// Someone cast a spell at oItem.
// Run by the caster.
int OnSpellCast(object oItem, int nSpell, object oCaster)
{
// Enter code to execute when this event happens
return FALSE; //Necessary return (Do this !)
}
// -----------------------------------------------------------------------------
// oItem was unacquired/lost (by a PC or NPC).
// Run by the module.
void OnUnacquire(object oItem, object oLostBy)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was unequipped by a PC.
// Run by the module.
void OnUnequip(object oItem, object oUnequippedBy)
{
// Enter code to execute when this event happens
}
//////////////////////////////////////////////////////////////////////////////
// ##### WARNINING:: DON'T TOUCH ANYTHING BELOW THIS LINE!!! #### ///////////
////////////////////////////////////////////////////////////////////////////
// The main function.
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
// Spells might continue to their spell scripts. All other events are
// completely handled by this script.
if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT )
SetExecutedScriptReturnValue();
// Determine which event triggered this script's execution.
switch ( nEvent )
{
// Item was acquired.
case X2_ITEM_EVENT_ACQUIRE:
OnAcquire(GetModuleItemAcquired(), GetModuleItemAcquiredBy(),
GetModuleItemAcquiredFrom(), GetModuleItemAcquiredStackSize());
break;
// Item was activated ("activate item" or "unique power").
case X2_ITEM_EVENT_ACTIVATE:
OnActivate(GetItemActivated(), GetItemActivatedTarget(),
GetItemActivatedTargetLocation(), GetItemActivator());
break;
// Item was equipped by a PC.
case X2_ITEM_EVENT_EQUIP:
OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy());
break;
// Item is a weapon that just hit a target, or it is the armor of someone
// who was just hit.
case X2_ITEM_EVENT_ONHITCAST:
OnHit(GetSpellCastItem(), GetSpellTargetObject(), OBJECT_SELF);
break;
// A PC (or certain NPCs) cast a spell at the item.
case X2_ITEM_EVENT_SPELLCAST_AT:
if ( OnSpellCast(GetSpellTargetObject(), GetSpellId(), OBJECT_SELF) )
SetExecutedScriptReturnValue();
break;
// Item was unacquired.
case X2_ITEM_EVENT_UNACQUIRE:
OnUnacquire(GetModuleItemLost(), GetModuleItemLostBy());
break;
// Item was unequipped by a PC.
case X2_ITEM_EVENT_UNEQUIP:
OnUnequip(GetPCItemLastUnequipped(), GetPCItemLastUnequippedBy());
break;
}
}
// my_tbi_template
// (Tag-based Item Script Template)
////////////////////////////////////////////////////////////////////////////////
// Created by: The Krit
// Created on: 04-03-2010
// Modified by: Genisys / Guile
// Modified on: 04-30-2011
///////////////////////////////////////////////////////////////////////////////
// This is intended to be a starting point for writing an item's tag-based script.
// Copy this to a script whose name is the tag of the item in question.
// Edit the event handlers (scroll down to find them) as desired.
// -----------------------------------------------------------------------------
//Required Include (DO NOT TOUCH!)
#include "x2_inc_switches"
//------------------------------------------------------------------------------
// Delcare ALL Common Integers / Floats / Strings
// NOTE: These can be used anywhere in any of the Prototypes
// By declaring at the top of the script they do not need to be delcared anywhere else!
int nInt, i, nGold, nXP, nclass, nCon; // nCon = nConstant
float fDelay, fTime;
string sName, sTag, sMsg, sResref;
//Add more if needed!
// -----------------------------------------------------------------------------
// Event handlers
// -----------------------------------------------------------------------------
// This second part is where you add your desired functionality. Each event
// has its own function with relavant information passed as parameters.
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// oItem was acquired (by a PC or an NPC).
// Run by the module.
void OnAcquire(object oItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was activated ("activate item" or "unique power").
// Run by the module.
void OnActivate(object oItem, object oActTarget, location lActTarget, object oActivator)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was equipped by a PC.
// Run by the module.
void OnEquip(object oItem, object oEquippedBy)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem is a weapon that just hit a target, or it is the armor of someone who
// was just hit by someone else's weapon.
// Run by the caster.
void OnHit(object oItem, object oHitTarget, object oCaster)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// Someone cast a spell at oItem.
// Run by the caster.
int OnSpellCast(object oItem, int nSpell, object oCaster)
{
// Enter code to execute when this event happens
return FALSE; //Necessary return (Do this !)
}
// -----------------------------------------------------------------------------
// oItem was unacquired/lost (by a PC or NPC).
// Run by the module.
void OnUnacquire(object oItem, object oLostBy)
{
// Enter code to execute when this event happens
}
// -----------------------------------------------------------------------------
// oItem was unequipped by a PC.
// Run by the module.
void OnUnequip(object oItem, object oUnequippedBy)
{
// Enter code to execute when this event happens
}
//////////////////////////////////////////////////////////////////////////////
// ##### WARNINING:: DON'T TOUCH ANYTHING BELOW THIS LINE!!! #### ///////////
////////////////////////////////////////////////////////////////////////////
// The main function.
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
// Spells might continue to their spell scripts. All other events are
// completely handled by this script.
if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT )
SetExecutedScriptReturnValue();
// Determine which event triggered this script's execution.
switch ( nEvent )
{
// Item was acquired.
case X2_ITEM_EVENT_ACQUIRE:
OnAcquire(GetModuleItemAcquired(), GetModuleItemAcquiredBy(),
GetModuleItemAcquiredFrom(), GetModuleItemAcquiredStackSize());
break;
// Item was activated ("activate item" or "unique power").
case X2_ITEM_EVENT_ACTIVATE:
OnActivate(GetItemActivated(), GetItemActivatedTarget(),
GetItemActivatedTargetLocation(), GetItemActivator());
break;
// Item was equipped by a PC.
case X2_ITEM_EVENT_EQUIP:
OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy());
break;
// Item is a weapon that just hit a target, or it is the armor of someone
// who was just hit.
case X2_ITEM_EVENT_ONHITCAST:
OnHit(GetSpellCastItem(), GetSpellTargetObject(), OBJECT_SELF);
break;
// A PC (or certain NPCs) cast a spell at the item.
case X2_ITEM_EVENT_SPELLCAST_AT:
if ( OnSpellCast(GetSpellTargetObject(), GetSpellId(), OBJECT_SELF) )
SetExecutedScriptReturnValue();
break;
// Item was unacquired.
case X2_ITEM_EVENT_UNACQUIRE:
OnUnacquire(GetModuleItemLost(), GetModuleItemLostBy());
break;
// Item was unequipped by a PC.
case X2_ITEM_EVENT_UNEQUIP:
OnUnequip(GetPCItemLastUnequipped(), GetPCItemLastUnequippedBy());
break;
}
}
Modifié par _Guile, 23 septembre 2011 - 08:35 .
#30
Posté 23 septembre 2011 - 07:23
Hey Guile thanks for the template, and FB indeed, with that include it does now compile. I will see if that make a difference for getting this to work. Thank you everyone!
#31
Posté 23 septembre 2011 - 08:30
Well unfortunately this didn't work. It still stops working after a short while. Really odd that it works for a short while after a restart, but then just stops. There has to be something that is interfering with that is delayed for a little while after a restart before it executes.
#32
Posté 25 septembre 2011 - 03:20
I was thinking about your bug, and I think it comes down to who the script is being executed on. In the standard OnActivateItem, the module is the one executing the item script, since it's OBJECT_SELF, and that's where the even variable is being store.
In your script, the PC is the one the script is being executed on, so they become OBJECT_SELF in the activation script, and that's where the event ID is checked.
To test, try manually setting the variable like this:
SetLocalInt (oPC,"X2_L_LAST_ITEM_EVENT", X2_ITEM_EVENT_ACTIVATE);
between these lines in your script:
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
// <=--- Insert SetLocalInt command here, before the ExecuteScript call is made, to test.
PrintString( "[ mod_onactivate ] Calling " + sTag + " for item: " + GetName( oItem ));
ExecuteScript( sTag, oPC );
In your script, the PC is the one the script is being executed on, so they become OBJECT_SELF in the activation script, and that's where the event ID is checked.
To test, try manually setting the variable like this:
SetLocalInt (oPC,"X2_L_LAST_ITEM_EVENT", X2_ITEM_EVENT_ACTIVATE);
between these lines in your script:
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
// <=--- Insert SetLocalInt command here, before the ExecuteScript call is made, to test.
PrintString( "[ mod_onactivate ] Calling " + sTag + " for item: " + GetName( oItem ));
ExecuteScript( sTag, oPC );
#33
Posté 25 septembre 2011 - 08:59
Hmm, ty FB, I could give this a shot as this version is much more in alignment with the original intent than the workaround (or alternate version) I am currently using. However, if I try this, you say I could test this, but I am not sure what results I would be looking for?
#34
Posté 25 septembre 2011 - 09:10
Well, adding the variable won't change anything else, it's simply a variable on the PC that'll be overwritten next time they're OBJECT_SELF in an event call. "Testing" in this case just means to try it, and see if the item still stops working after awhile.
The other way to test would be to change the execution to OBJECT_SELF, but that might affect other scriptsdoing the testing that way. That's why I figured the direct setting of the variable was the better way to try.
Edit: It looks like X2_ITEM_EVENT_SPELLCAST_AT runs with the PC as OBJECT_SELF, so that might be the event that was triggering that made (or makes, if setting the variable manually doesn't fix it) it stop.
The other way to test would be to change the execution to OBJECT_SELF, but that might affect other scriptsdoing the testing that way. That's why I figured the direct setting of the variable was the better way to try.
Edit: It looks like X2_ITEM_EVENT_SPELLCAST_AT runs with the PC as OBJECT_SELF, so that might be the event that was triggering that made (or makes, if setting the variable manually doesn't fix it) it stop.
Modifié par Failed.Bard, 25 septembre 2011 - 09:18 .
#35
Posté 25 septembre 2011 - 07:44
Are you sure the script isn't getting called? I'd put some kind of debug output into it to be positive it actually stops running. Maybe it's running but some condition exists after a time which prevents the stuff you're doing in the script from having any effect. You need to debug the script and trace the value of all the variables in it to ensure the line that's supposed to do whatever isn't happening is truly not getting executed, and why...or if it is what parameter values are you sending it that's causing it to fail.
#36
Posté 25 septembre 2011 - 11:13
Well this seems to work Faided.Bard! Thank you very much. Will take some more extensive testing to be sure, but so far so good as I haven't been able to reproduce the bug yet. Thank you everyone!





Retour en haut






