Author Topic: Activate Item without selecting target  (Read 1124 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« on: August 27, 2011, 05:08:25 pm »


               How do you create an item with a special activation script that does not require the player to select a target? Is there a specific power you need to select OR does this depend upon the type of item?
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Activate Item without selecting target
« Reply #1 on: August 27, 2011, 05:16:36 pm »


               Cast Spell: Unique Power Self Only does that.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #2 on: August 27, 2011, 05:22:55 pm »


               thanks

And why isn't that next to activate item?
               
               

               


                     Modifié par henesua, 27 août 2011 - 04:24 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Activate Item without selecting target
« Reply #3 on: August 27, 2011, 08:13:21 pm »


               

henesua wrote...

thanks

And why isn't that next to activate item?



Because the toolset sorts its list..
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #4 on: August 27, 2011, 10:04:14 pm »


               no, what I mean is - since this is essentially the same as activate item why wasn't it named similarly? In otherwords what is the purpose of Unique Power when you have activate item? Do they fire different events? It doesn't seem to be the case. And they seem to launch the same tag based script.
               
               

               
            

Legacy_Roddish

  • Jr. Member
  • **
  • Posts: 82
  • Karma: +0/-0
Activate Item without selecting target
« Reply #5 on: August 28, 2011, 10:32:14 am »


               I always thought it was pretty self explanatory. the Unique Power allows the game to know not to fire a preexisting spell but to handle as if it had.
activate item is not just for unique power you see, you might have a regular item, on which every time it is activated, a counter is incremented, and on the 256th use say, something happens. but the item had a bogstandard power.

i guess what i'm trying to say (quite inexpertly i might add) is that the to are not mutually exclusive, and the different monikers are there because they are different things alltogether.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #6 on: August 28, 2011, 06:36:36 pm »


               That would make sense if Unique Power and Activate Item had different user event integers. But I don't believe they do. I can't see how I can differentiate between them. Does anyone know how to differentiate in a script between which one was used?

On the other hand they do give a different text string to the player.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Activate Item without selecting target
« Reply #7 on: August 28, 2011, 07:29:43 pm »


               

henesua wrote...

... Does anyone know how to differentiate in a script between which one was used?

  


That is not hard. 

int Spell = GetSpellId();

where
ACTIVATE_ITEM =368
ACTIVATE_ITEM_SELF= 413
ACTIVATE_ITEM_L       = 697
ACTIVATE_ITEM_T       = 759


Keep in mind that the unique powers are still a spell(Per the engine)  that all run the same inpact script: NW_S3_ActItem01 .  All the script does is change the spell into a module signaled event.   
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #8 on: August 28, 2011, 09:24:05 pm »


               

Lightfoot8 wrote...

int Spell = GetSpellId();

where
ACTIVATE_ITEM =368
ACTIVATE_ITEM_SELF= 413
ACTIVATE_ITEM_L       = 697
ACTIVATE_ITEM_T       = 759


Interesting, I was unaware of that because I have not tackled custom spells yet. For my item activation scripts I have been using the following:


 int nEvent =GetUserDefinedItemEventNumber();
 if (nEvent ==X2_ITEM_EVENT_ACTIVATE)
            // do stuff


So using your method I guess that I will be able to differentiate between types of activation as follows:

"Spell" on Item                                        Integer
Activate Item                                            368
Activate Item [Long Range]                   697
Activate Item [Touch]                              759
Unique Power                                         368
Unique Power Self Only                        415

But that integer is the spell ID and NOT a User Defined Event Number
               
               

               


                     Modifié par henesua, 28 août 2011 - 08:25 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Activate Item without selecting target
« Reply #9 on: August 28, 2011, 09:38:53 pm »


               Correct,  But i would still put that inside of your other check.

int nEvent =GetUserDefinedItemEventNumber();
if (nEvent ==X2_ITEM_EVENT_ACTIVATE)
           // do stuff
Just for the reasion that I do not know when if ever the spell ID gets cleared.   I would hate to see a PC pick up an item and it fire its activate spell event just because someone just used a unique power somwhere.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #10 on: August 28, 2011, 09:44:45 pm »


                Lightfoot

I tried to distinguish between the activation types using the method you described but it did not work. Item activation in my mod triggers a tag based script.

To test this out I wrote a script associated with an object that had all the methods of activation and both of the two unique powers. Here it is:


#include "x2_inc_switches"
void main()
{
    int nEvent =GetUserDefinedItemEventNumber();

 if (nEvent ==X2_ITEM_EVENT_ACTIVATE) 
{
    object oPC          = GetItemActivator();
    object oItem        = GetItemActivated();
    object oTarget      = GetItemActivatedTarget();
    int nAct            = GetSpellId();
    SendMessageToPC(oPC, "Activating "+GetName(oItem));
    SendMessageToPC(oPC, "Targeting "+GetName(oTarget));
    SendMessageToPC(oPC, "ID of Activation "+IntToString(nAct));

 }
}

For every type of activation I got a -1 for the spell ID. I suppose that the activation script does not qualify as a "spell script", and so there is no spell id.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Activate Item without selecting target
« Reply #11 on: August 28, 2011, 10:21:08 pm »


               SpellID can only be retrieved in the initial script run when the "spell" is cast.  You'll have to insert the ID as a variable either on the item or the user in the activation script before the module event is triggered if you want to use it later.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Activate Item without selecting target
« Reply #12 on: August 28, 2011, 10:26:12 pm »


               OK so Ill admit it,  I forgot forgot that the event is running on the module and not the PC. *Hangs head low*  and with how many times I have reminded others of that I should not have forgotten.   

If this is really something you want to do, you can modify the NW_S3_ActItem01 script to the following. 

void main()
{
    object oItem = GetSpellCastItem();
    object oTarget = GetSpellTargetObject();
    location lLocal = GetSpellTargetLocation();
    SetLocalInt(oItem,"LAST_SPELL_CAST",GetSpellId());
   
    SignalEvent(GetModule(), EventActivateItem(oItem, lLocal, oTarget));


then you can use the following.

#include "x2_inc_switches"
void main()
{
    int nEvent =GetUserDefinedItemEventNumber();
 
if (nEvent ==X2_ITEM_EVENT_ACTIVATE)
{
    object oPC          = GetItemActivator();
    object oItem        = GetItemActivated();
    object oTarget      = GetItemActivatedTarget();
    int nAct            = GetLocalInt(oItem,"LAST_SPELL_CAST");
    SendMessageToPC(oPC, "Activating "+GetName(oItem));
    SendMessageToPC(oPC, "Targeting "+GetName(oTarget));
    SendMessageToPC(oPC, "ID of Activation "+IntToString(nAct));

 }
}


Or however you wish to do it.  I ma sure you get the Idea.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Activate Item without selecting target
« Reply #13 on: August 28, 2011, 10:27:27 pm »


               I see Failed bard beat me to the responce.
EDIT: just a note here.  The reason it was not working is that the GetSpellId function has to be running on the PC.  So if you did not want to do it by modifying the inpact script you could alway just make sure that the script was running on the activator of the item.   Or even wrap the event up as a command and assign it to the PC. 

Here is an example of the last option.

#include "x2_inc_switches"
void ItemAct()
{
    object oPC          = GetItemActivator();
    object oItem        = GetItemActivated();
    object oTarget      = GetItemActivatedTarget();
    int nAct            = GetSpellId();
    SendMessageToPC(oPC, "Activating "+GetName(oItem));
    SendMessageToPC(oPC, "Targeting "+GetName(oTarget));
    SendMessageToPC(oPC, "ID of Activation "+IntToString(nAct));
}
void main()
{
    int nEvent =GetUserDefinedItemEventNumber();
 if (nEvent ==X2_ITEM_EVENT_ACTIVATE)
 {
  AssignCommand(GetItemActivator(),ItemAct());
 }
}


               
               

               


                     Modifié par Lightfoot8, 28 août 2011 - 10:04 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Activate Item without selecting target
« Reply #14 on: August 28, 2011, 11:59:04 pm »


               Thanks! Good stuff.