Both Unique Powers
#1
Posté 10 décembre 2011 - 05:43
If a device has both Cast Spell: Unique Power (self and targetted), is there a way to tell (for example, in the OnActivated script) which power is being used? Whether the player chose the targetted version or the self-only version?
Here's why I ask:
-- I have a device with both unique powers on it. The target-based power uses one charge. The self-only has unlimited charges.
-- If the player has used their target-based power (say, a fellow PC to heal or a monster to attack) I want to use a charge and script an effect (I know how to do this and have done it before).
-- If the player has used their self-only based power, I want to recharge one charge.
So I'm not sure, during the activate script, how to know if they chose the self-only or the targetted version. GetSpellID() returns a constant for SPELL_* but there is no constant listed for the unique abilities in nwscript. Am I missing it somewhere?
#2
Posté 10 décembre 2011 - 05:45
#3
Posté 10 décembre 2011 - 06:08
#4
Posté 10 décembre 2011 - 06:35
If the charge is used pre-script, you could track the remaining charges in a variable on the item and compare them with GetItemCharges.
If the charge is taken after the script runs, you could make a custom function and pass in the caster info and such... then delay command 0.01. Run your custom stuff inside of the function, and the charge should be used by the time the function runs.
Hopefully, it takes the charge first. That would be easier.
I can't think of any other good way of doing this.
#5
Posté 10 décembre 2011 - 06:41
if(!GetLocalInt("RemCharges", oItem))
{
SetLocalInt(oItem, "RemCharges", GetItemCharges(oItem));
}
//Add this to the item script
if(GetItemCharges(oItem) != GetLocalInt(oItem, "RemCharges"))
{
SetLocalInt(oItem, "RemCharges", GetItemCharges(oItem));
//Perform your targeted code here
}
else
{
//Place your self only code here
}
#6
Posté 10 décembre 2011 - 06:46
#7
Posté 10 décembre 2011 - 06:47
#8
Posté 10 décembre 2011 - 06:57
Good luck with it.
#9
Posté 10 décembre 2011 - 06:58
DragonTayl wrote...
Heh, and you replied before I'd actually gotten back to you. Thanks for the active involvement. I do think this will work.
Another solution is instead of using unique power self only, use "manipulate portal stone" this script also sets a local integer.
A second alternative is to change the base script which calls activate item nw_s3_actitem01 to the following:
void main()
{
object oItem = GetSpellCastItem();
object oTarget = GetSpellTargetObject();
location lLocal = GetSpellTargetLocation();
//Add this line
SetLocalInt(oItem, "SpellID", GetSpellID());
SignalEvent(GetModule(), EventActivateItem(oItem, lLocal, oTarget));
}
#10
Posté 10 décembre 2011 - 07:06
DragonTayl wrote...
If a device has both Cast Spell: Unique Power (self and targetted), is there a way to tell (for example, in the OnActivated script) which power is being used? Whether the player chose the targetted version or the self-only version? ...
...So I'm not sure, during the activate script, how to know if they chose the self-only or the targetted version. GetSpellID() returns a constant for SPELL_* but there is no constant listed for the unique abilities in nwscript. Am I missing it somewhere?
Yes, Each Unique Power Type will have a unique Spell ID. The Spell ID is simply the Line number in spells.2da that defines the power. You can either look them up in spells.2da or just run a quick test script on your item and have it report back the SpellID being used.
#include "x2_inc_switches"
void main()
{
object oPC;
object oItem;
int nEvent = GetUserDefinedItemEventNumber();
if ( nEvent != X2_ITEM_EVENT_ACTIVATE) return;
SpeakString( "Spell ID = "+ IntToString(GetSpellId()));
}
Edit: Whizard solution may work better for you. When using the standard Item events the script is running on the module. in order for the GetSpellID function to work the Function has to be running on the Object that cast the spell.
Modifié par Lightfoot8, 10 décembre 2011 - 07:17 .
#11
Posté 10 décembre 2011 - 07:23
The Spell Id is lost on the event call, you will need to pass it by local variable.Lightfoot8 wrote...
DragonTayl wrote...
If a device has both Cast Spell: Unique Power (self and targetted), is there a way to tell (for example, in the OnActivated script) which power is being used? Whether the player chose the targetted version or the self-only version? ...
...So I'm not sure, during the activate script, how to know if they chose the self-only or the targetted version. GetSpellID() returns a constant for SPELL_* but there is no constant listed for the unique abilities in nwscript. Am I missing it somewhere?
Yes, Each Unique Power Type will have a unique Spell ID. The Spell ID is simply the Line number in spells.2da that defines the power. You can either look them up in spells.2da or just run a quick test script on your item and have it report back the SpellID being used.
#include "x2_inc_switches"
void main()
{
object oPC;
object oItem;
int nEvent = GetUserDefinedItemEventNumber();
if ( nEvent != X2_ITEM_EVENT_ACTIVATE) return;
SpeakString( "Spell ID = "+ IntToString(GetSpellId()));
}
#12
Posté 10 décembre 2011 - 07:27
Modifié par Lightfoot8, 10 décembre 2011 - 07:27 .
#13
Posté 10 décembre 2011 - 07:32
Lightfoot8 wrote...
Note the edit I added to my post. It is not lost, the script just need to be running on the object that used the Item. I Did note that your solution would be better.
Once it goes to the module event, I don't think even AssignCommand() can give the Spell ID, so in that sense it is lost, as Spell ID is not something that is stored for later reference.
EDIT: It looks like you are right, so long as there is no DelayCommand() you can add to the script
AssignCommand(GetItemActivator(), DoSpellIDCheck());
and then define DoSpellIDCheck() to pass the activate item spell as a local variable.
Modifié par WhiZard, 10 décembre 2011 - 07:38 .
#14
Posté 10 décembre 2011 - 07:47
Modifié par Lightfoot8, 10 décembre 2011 - 07:47 .
#15
Posté 10 décembre 2011 - 03:58
By the way, if someone is interested in the future:
Spell IDs are:
Unique Power Targetted (386)
Unique Power Self Only (413)
Modifié par DragonTayl, 10 décembre 2011 - 04:08 .





Retour en haut






