Author Topic: Mod Item Activate  (Read 342 times)

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Mod Item Activate
« on: March 09, 2014, 01:56:37 pm »


               

Look, if you all wanted me to go away, you could just have said so. You didn't have to start a new forum.


 


Created an Item.


Gave it some properties. Inc Intell, Improved save, and Cast Spell Unique.


 


I placed this script in the Mod Activate Item.


 


void main()

{

 object oItem = GetItemActivated();


 object oArea = OBJECT_SELF;

 object oVictim = GetFirstObjectInArea(oArea);

 int nType = OBJECT_TYPE_CREATURE;

 effect eKill = EffectDeath(TRUE,TRUE);


 


while(GetIsObjectValid(oVictim))


{


 if(GetTag(oItem) == "HelmofUltima")

 {

   if(GetObjectType(oVictim) == nType)

   {

    ApplyEffectToObject(DURATION_TYPE_INSTANT,eKill,oVictim);

    GiveXPToCreature(GetFirstPC(),1000);

   }

  }

  oVictim = GetNextObjectInArea(oArea);


 }

}


 


It is my hope to kill every creature in the area.


Aint working.


What's up with that ?


 


Ed



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Mod Item Activate
« Reply #1 on: March 09, 2014, 02:26:35 pm »


               

I typed up an example of how to code what you wanted in your module's activation script. The key addiiton I made is tohe while loop that runs as long as there is a valid creature in the area. This might kill the user of the helmet too so I added a check which helps avoid them: 



&&  oVictim!=oActivator

Not sure as I have not tested this script so that part can be commented out.


 


I also included bioware's code for using tag based scripting. I placed that between comments about Bioware and from Bioware



void main()
{
    // DECLARE MAJOR VARIABLES
     object oItem       = GetItemActivated();
     object oActivator  = GetItemActivator();
     string sTag        = GetTag(oItem);

// Bioware Begin ----TAG BASED SCRIPTING----------------------------------------
     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
    SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);
    string sScript = GetUserDefinedItemEventScriptName(oItem);
    // ExecuteScript(sScript, OBJECT_SELF);

    int nRet =   ExecuteScriptAndReturnInt(sScript,OBJECT_SELF);
    if (nRet == X2_EXECUTE_SCRIPT_END) { return; }
// End Bioware -----------------------------------------------------------------


    // specific items not yet using tag based scripting
    if(sTag == "HelmofUltima")
    {
        object oArea = GetArea(oActivator);
        effect eKill = EffectDeath(TRUE,TRUE);

        object oVictim = GetFirstObjectInArea(oArea);
        while(oVictim!=OBJECT_INVALID)
        {
            if(     GetObjectType(oVictim)==OBJECT_TYPE_CREATURE
                &&  oVictim!=oActivator
              )
            {
                ApplyEffectToObject(DURATION_TYPE_INSTANT,eKill,oVictim);
                GiveXPToCreature(oActivator,1000);
            }

            oVictim = GetNextObjectInArea(oArea);
        }
    }
}


               
               

               
            

Legacy_Ed Venture

  • Full Member
  • ***
  • Posts: 200
  • Karma: +0/-0
Mod Item Activate
« Reply #2 on: March 11, 2014, 02:09:53 am »


               

 henesua,


Thank you. Worked just fine. Had to add the,  &&  oVictim!=oActivator. Lvl 40 Rouge, went down like a sack of spuds. I'm very happy that these forums are continuing. The help you and others give is valuable to us noobs. Thank you again.


 


I have included my complete script, for anyone who wishes to see.


 


Saved under a new ref.


 


//::///////////////////////////////////////////////

//:: Example XP2 OnActivate Script Script

//:: x2_mod_def_act

//:: © 2003 Bioware Corp.

//:://////////////////////////////////////////////

/*

    Put into: OnItemActivate Event


*/

//:://////////////////////////////////////////////

//:: Created By: Georg Zoeller

//:: Created On: 2003-07-16

//:://////////////////////////////////////////////


#include "x2_inc_switches"

void main()

{

 object oItem = GetItemActivated();

 //////////Added Variables, Ed/////////////////////////////////////////////////

 object oUser = GetItemActivator();

 object oArea = GetArea(oUser);

 object oVictim = GetFirstObjectInArea(oArea);

 string sTag = GetTag(oItem);

 int nType = OBJECT_TYPE_CREATURE;

 effect eKill = EffectDeath(TRUE,TRUE);


  // * Generic Item Script Execution Code

  // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,

  // * it will execute a script that has the same name as the item's tag

  // * inside this script you can manage scripts for all events by checking against

  // * GetUserDefinedItemEventNumber(). See x2_it_example.nss

 if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)

 {

  SetUserDefinedItemEventNumber(X2_ITEM_EVENT_ACTIVATE);

  int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);

  if (nRet == X2_EXECUTE_SCRIPT_END)

  {

   return;

  }


 }

 ////////Ed Modifications Begin Here///////////////////////////////////////////

 if(sTag == "HelmofUltima")

 {

  while(GetIsObjectValid(oVictim))

  {

   if(GetObjectType(oVictim) == nType &&  oVictim!=oUser)

   {

    ApplyEffectToObject(DURATION_TYPE_INSTANT,eKill,oVictim);

    GiveXPToCreature(GetFirstPC(),1000);

   }

  oVictim = GetNextObjectInArea(oArea);

  }

 }

}



 



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Mod Item Activate
« Reply #3 on: March 12, 2014, 05:53:00 am »


               

You should switch your code for my own.


 


One of the reasons is that in your code you are unnecessarily declaring a few variables outside of the scope of your helmet's block of code.


 


oVictim, oArea, nType, eKill … all of that is special to the magic helmet stuff and thus should only be in the section of code special to the helmet.


 


By including them at the top of the script they are declared every time someone activates an item, but going unused in the majority of cases.