Author Topic: Both Unique Powers  (Read 402 times)

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« on: December 10, 2011, 05:43:09 am »


               Greetings! Wow I've been away from this game for years, but full circle, I am back again. We'll see if it sticks this time. I think if you're a developer, it's in your blood and it may be impossible to be satisfied with someone else's MMO. 

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?
               
               

               
            

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« Reply #1 on: December 10, 2011, 05:45:53 am »


               Actually I guess I spent too much time trying to work out the functions and not realizing the logic. If they use the targetted version, it will only work if they chose an actual target or location. If they use the self-only version, there will be no target or location. So if there is a valid target or location, assume it was the targetted version, else assume it was the self-only?
               
               

               
            

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« Reply #2 on: December 10, 2011, 06:08:45 am »


               Drat. Unfortunately, it appears that Unique Power Self Only returns the caster as both the targetted object and the location. So you couldn't tell if the player was attempting to use a non-target spell or if they were using the target option but on themselves. Any ideas?
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Both Unique Powers
« Reply #3 on: December 10, 2011, 06:35:11 am »


               Do you know if the charge is taken away before or after the script runs?
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.
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Both Unique Powers
« Reply #4 on: December 10, 2011, 06:41:33 am »


               //Add this to OnAcquire
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
}
               
               

               
            

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« Reply #5 on: December 10, 2011, 06:46:51 am »


               Yay for midnight coding! Okay, after a quick test on your idea it DOES take the charge before the script. I think this may be a workable solution. I'm fried right now, but will try to implement. Thanks, that was a clever way to look at it.
               
               

               
            

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« Reply #6 on: December 10, 2011, 06:47:33 am »


               Heh, and you replied before I'd actually gotten back to you. Thanks for the active involvement. I do think this will work.
               
               

               
            

Legacy_wyldhunt1

  • Sr. Member
  • ****
  • Posts: 443
  • Karma: +0/-0
Both Unique Powers
« Reply #7 on: December 10, 2011, 06:57:25 am »


               Yay for voodoo programming. '<img'>

Good luck with it.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Both Unique Powers
« Reply #8 on: December 10, 2011, 06:58:23 am »


               

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));

}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Both Unique Powers
« Reply #9 on: December 10, 2011, 07:06:17 am »


               

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 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Both Unique Powers
« Reply #10 on: December 10, 2011, 07:23:05 am »


               

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()));
}

The Spell Id is lost on the event call, you will need to pass it by local variable.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Both Unique Powers
« Reply #11 on: December 10, 2011, 07:27:03 am »


               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.
               
               

               


                     Modifié par Lightfoot8, 10 décembre 2011 - 07:27 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Both Unique Powers
« Reply #12 on: December 10, 2011, 07:32:15 am »


               

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 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Both Unique Powers
« Reply #13 on: December 10, 2011, 07:47:05 am »


               Yea, I normally just placed a DoOnce code at the top of the script to rerun the script on the Object instead of the module. That way you get access to all of the accessor functions.
               
               

               


                     Modifié par Lightfoot8, 10 décembre 2011 - 07:47 .
                     
                  


            

Legacy_DragonTayl

  • Newbie
  • *
  • Posts: 40
  • Karma: +0/-0
Both Unique Powers
« Reply #14 on: December 10, 2011, 03:58:02 pm »


               Wow. All kinds of great solutions. Thanks!

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 .