Author Topic: Where do I put a Unique Power (OnHit) script?  (Read 571 times)

Legacy_Michael_Patty

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« on: August 31, 2010, 03:59:19 pm »


               Sorry if this has been covered somewhere before (though I certainly couldn't find it).

I have a weapon with a unique power (OnHit). I understand from other posts that I need to use tag-based scripting to make it work, and I even cobbled some script together from the wonderful examples people have posted here. But what STUMPS me is where to put the script???

If anyone could help me in this, I would be eternally grateful!

Michael:O
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #1 on: August 31, 2010, 04:05:27 pm »


               name the script the same as the tag for the item.  That is it.  you do not put it anywhere.   As long as tag based scripting is turned on it will run that script for all item based scripts  events, So make sure you have a check in your script for the event that is being ran.
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #2 on: August 31, 2010, 04:05:42 pm »


               You must make a script with the same name as the (tagname) of the item which the OnHit Property...

Here is a template script, you want to add code for the effects of the OnHit in the OnHit event part..
(This script can be used for all Tagbased Events - simply add code where it belongs for that event)

//Script Name:  
////////////////////////////////////////////      
//(save this script as your item's tagname)
///////////////////////////////////////////
// Created By: Genisys (Guile)
// Created On: 7/13/10
////////////////////////////////////////////////////////////////////////
// (TABASED ITEM SCRIPT TEMPLATE)
////////////////////////////////////////////////////////////////////////
/*
This template is used for ALL events which
happen for an item which has the same
tagname as the name of this script.

Every event below will fire when the event
happens, ie. If the player activates the item
the X2_ITEM_EVENT_ACTIVATE: script code will run.

*/
/////////////////////////////////////////////////////////
#include "x2_inc_switches"

//Main Script
void main()
{

   //All Major Variables Declared (Commonly used variables as well)

   int nEvent = GetUserDefinedItemEventNumber();  //Which event triggered this
   object oPC;                                   //The player character using the item
   object oItem;                                //The item being used
   object oSpellOrigin;                        //The origin of the spell
   object oSpellTarget;                       //The target of the spell
   int iSpell;                               //The Spell ID number
   object oTarget;     //Define oTarget below
   object oObject;     //Define oObject below
   int nInt;           //A commonly used intergal (Must be defined)
   int nLvl;           //Commonly used intergal for levels  (ie. GetHitDice(oTarget); etc.)
   string sTag;        //Used to define a tagname of something
   string sResref;     //Used to define a resref name of something
   string sMsg;        //Used to define a message
   effect eEffect;     //Used to define an effect to be applied to an object or location
   effect eVis;        //Used to define a visual effect to be applied to an object or location
   location lTarget;   //The Target Location of the PC ONLY! (USE - Getlocation(oPC)'<img'>
   location lway;      //The Target location for the Activated Item's Target only! (See below)

////////////////////////////////////////////////////////////////////////////////////////////////
 //Set the return value for the item event script
 // * X2_EXECUTE_SCRIPT_CONTINUE - continue calling script after executed script is done
 // * X2_EXECUTE_SCRIPT_END - end calling script after executed script is done
 int nResult = X2_EXECUTE_SCRIPT_END;
///////////////////////////////////////////////////////////////////////////////////////////////

   //Deterimine which event has fired for the item...
   switch (nEvent)
   {

////////////////////////////////////////////////////////////////////////////
///////The Item has the property:  On-Hit Cast Spell: Unique Power/////////

     case X2_ITEM_EVENT_ONHITCAST:
     {
      // * This code runs when the item has the 'OnHitCastSpell: Unique power' property
      // * and it hits a target(if it is a weapon) or is being hit (if it is a piece of armor)
      // * Note that this event fires for non PC creatures as well.

      oItem  =  GetSpellCastItem();      // The item triggering this spellscript
      oPC = OBJECT_SELF;                 // The player triggering it
      oSpellOrigin = OBJECT_SELF ;      // Where the spell came from
      oSpellTarget = GetSpellTargetObject(); // What the spell is aimed at

      //Your code goes here

     } break;

///////////////////////////////////////////////////////////////////////////
/////////////Cast Spell: Unique Power /or/ Activate Item//////////////////

    //I seperated this cause it's more commonly used..
    case X2_ITEM_EVENT_ACTIVATE:
    {
    // * This code runs when the Unique Power property of the item is used
    // * or the item is activated. Note that this event fires for PCs only.

    oPC   = GetItemActivator();        // The player who activated the item
    oItem = GetItemActivated();         // The item that was activated
    oTarget = GetItemActivatedTarget();   //The target of the item's power
    lway = GetItemActivatedTargetLocation(); //To get the location of the target!


      //Your code goes here

    } break;

///////////////////////////////////////////////////////////////////////////
///////////When the User Equips this item////////////////////////////////

     case X2_ITEM_EVENT_EQUIP:
     {
     // * This code runs when the item is equipped
     // * Note that this event fires for PCs only

     oPC = GetPCItemLastEquippedBy(); // The player who equipped the item
     oItem = GetPCItemLastEquipped(); // The item that was equipped

     //Your code goes here

     } break;

////////////////////////////////////////////////////////////////////////////
/////////////When the User Unequips this item//////////////////////////////

    case X2_ITEM_EVENT_UNEQUIP:
    {
    // * This code runs when the item is unequipped
    // * Note that this event fires for PCs only

    oPC    = GetPCItemLastUnequippedBy();// The player who unequipped the item
    oItem  = GetPCItemLastUnequipped(); // The item that was unequipped

    //Your code goes here

    } break;

////////////////////////////////////////////////////////////////////////////
////////////Everytime ANYONE Acquires this item////////////////////////////

    case X2_ITEM_EVENT_ACQUIRE:
    {
    // * This code runs when the item is acquired
    // * Note that this event fires for PCs only

    oPC = GetModuleItemAcquiredBy();  // The player who acquired the item
    oItem  = GetModuleItemAcquired(); // The item that was acquired

    //Your code goes here

    } break;

////////////////////////////////////////////////////////////////////////////
//////////Everytime ANYONE Loses this item/////////////////////////////////

   case X2_ITEM_EVENT_UNACQUIRE:
   {
   // * This code runs when the item is unacquired
   // * Note that this event fires for PCs only

   oPC = GetModuleItemLostBy();  // The player who dropped the item
   oItem  = GetModuleItemLost(); // The item that was dropped

   //Your code goes here

   } break;

////////////////////////////////////////////////////////////////////////////
/////Everytime ANYONE Cast a spell at this item////////////////////////////

   case X2_ITEM_EVENT_SPELLCAST_AT:
   {
   //* This code runs when a PC or DM casts a spell from one of the
   //* standard spellbooks on the item

   oPC = OBJECT_SELF;              // The player who cast the spell
   oItem  = GetSpellTargetObject();// The item targeted by the spell
   iSpell = GetSpellId();          // The id of the spell that was cast
                                   // See the list of SPELL_* constants

   //Your code goes here

   //Change the following line from X2_EXECUTE_SCRIPT_CONTINUE to
   //X2_EXECUTE_SCRIPT_END if you want to prevent the spell that was
   //cast on the item from taking effect
   nResult = X2_EXECUTE_SCRIPT_CONTINUE;
   } break;

   }

   //Pass the return value back to the calling script
   SetExecutedScriptReturnValue(nResult);
}
               
               

               


                     Modifié par Genisys, 31 août 2010 - 03:10 .
                     
                  


            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #3 on: August 31, 2010, 04:07:43 pm »


               NOTE: You MUST declare all variables where variables are declared, you cannot declare them where the functions are written, or the script will kick out an error on you...
               
               

               
            

Legacy_Michael_Patty

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #4 on: August 31, 2010, 04:34:16 pm »


               You guys are absolutely great. Once again you come to my rescue. If you were here (and I knew you were old enough), I'd buy you a round.  '<img'>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #5 on: August 31, 2010, 09:51:57 pm »


               

Genisys wrote...

NOTE: You MUST declare all variables where variables are declared, you cannot declare them where the functions are written, or the script will kick out an error on you...

 
This is almost a correct statment.  It is however false. 
You can not declair a var in a case statment if it is a single statment. 
You can however declair a var in a case statment if it is a compound statment.

Example 1:  this will give a compiler error.

  #include "x2_inc_switches"
void main()
{
    int nEvent = GetUserDefinedItemEventNumber();
    switch (nEvent)
    {
        case X2_ITEM_EVENT_ACTIVATE:            
        int nNumber =5;
        break;
    }
}
  



Example this will not.  Even though it is only a single statment. the {} will cause the compiler to treat it as a compunnd statment.

   #include "x2_inc_switches"
void main()
{
    int nEvent = GetUserDefinedItemEventNumber();
    switch (nEvent)
    {
        case X2_ITEM_EVENT_ACTIVATE:
        {
            int nNumber =5;
        }
        break;
    }
}
  


               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #6 on: August 31, 2010, 10:19:06 pm »


               Now that Lightfoot8 was most enlightening, thank you for the clarifcation, and thank you for being polite about it too.. '<img'>



               
               

               
            

Legacy_ehye_khandee

  • Hero Member
  • *****
  • Posts: 1415
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #7 on: August 31, 2010, 11:09:33 pm »


               

Genisys wrote...


You must make a script with the same name as the (tagname) of the item which the OnHit Property...



GAAAAH! There is no such thing as a 'tagname'. There are TAGs and there are Names, but no such thing as a 'tagname'. Proper use of the terms are essential to prevent you from confusing the masses.

*stops banging head against the desktop*

I feel better now.

':devil:'
               
               

               
            

Legacy_Michael_Patty

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Where do I put a Unique Power (OnHit) script?
« Reply #8 on: September 01, 2010, 03:59:44 pm »


               object oAngryUser = GetUserByTag("ehye_khandee");

int nAnger = GetAnger(oAngryUser);

if(nAnger >= 5)

   {SetAnger(oAngryUser,nAnger - 3);}  // Take it down a notch and chill... '<img'>