Author Topic: Help with Removing Modify Attacks..  (Read 1018 times)

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #15 on: April 29, 2013, 11:26:42 pm »


               //
// (NOTE: This is a template script, save it under a new name FIRST)
////////////////////////////////////////////////////////////////////////////////
// Created by:   The Krit
// Created on:   04-03-2010
// Modified by:  Genisys / Guile
// Modified on:  04-30-2011
///////////////////////////////////////////////////////////////////////////////

// This is intended to be a starting point for writing an item's tag-based script.
// Copy this to a script whose name is the tag of the item in question.
// Edit the event handlers (scroll down to find them) as desired.
// -----------------------------------------------------------------------------
//Required Include (DO NOT TOUCH!)
#include "x2_inc_switches"
//------------------------------------------------------------------------------

   // Delcare ALL Common Integers / Floats / Strings
   // NOTE: These can be used anywhere in any of the Prototypes
   // By declaring at the top of the script they do not need to be delcared anywhere else!
   int nInt, i, nGold, nXP, nclass, nCon; // nCon = nConstant
   float fDelay, fTime;
   string sName, sTag, sMsg, sResref;
   //Add more if needed!

// -----------------------------------------------------------------------------
// Event handlers
// -----------------------------------------------------------------------------
// This second part is where you add your desired functionality. Each event
// has its own function with relavant information passed as parameters.
// -----------------------------------------------------------------------------


// -----------------------------------------------------------------------------
// oItem was acquired (by a PC or an NPC).
// Run by the module.
void OnAcquire(object oItem, object oAcquiredBy, object oTakenFrom, int nStackSize)
{
   // Enter code to execute when this event happens
}


// -----------------------------------------------------------------------------
// oItem was activated ("activate item" or "unique power").
// Run by the module.
void OnActivate(object oItem, object oActTarget, location lActTarget, object oActivator)
{
   // Enter code to execute when this event happens
}


// -----------------------------------------------------------------------------
// oItem was equipped by a PC.
// Run by the module.
void OnEquip(object oItem, object oEquippedBy)
{
 object oWay = GetWaypointByTag("ec_caster_way");
 object oEC =  GetNearestObjectByTag("eff_caster", oWay);

 effect eMas = EffectModifyAttacks(1);
 eMas = SupernaturalEffect(eMas);
 effect eVis = EffectVisualEffect(VFX_DUR_IOUNSTONE_YELLOW);

 if(oWay == OBJECT_INVALID)
 {
  FloatingTextStringOnCreature("ERROR, notify DMs that the waypoint for this item is missing!", oEquippedBy, TRUE);
  return;
 }
 if(oEC == OBJECT_INVALID)
 {
  oEC = CreateObject(OBJECT_TYPE_PLACEABLE, "eff_caster", GetLocation(oWay), FALSE);
 }



 AssignCommand(oEC, ApplyEffectToObject(
 DURATION_TYPE_PERMANENT, eMas, oEquippedBy));

 AssignCommand(oEC, ApplyEffectToObject(
 DURATION_TYPE_PERMANENT, eVis, oEquippedBy));
}


// -----------------------------------------------------------------------------
// oItem is a weapon that just hit a target, or it is the armor of someone who
// was just hit by someone else's weapon.
// Run by the caster.
void OnHit(object oItem, object oHitTarget, object oCaster)
{
   // Enter code to execute when this event happens
}


// -----------------------------------------------------------------------------
// Someone cast a spell at oItem.

// Run by the caster.
int OnSpellCast(object oItem, int nSpell, object oCaster)
{
  // Enter code to execute when this event happens

  return FALSE; //Necessary return (Do this !)
}


// -----------------------------------------------------------------------------
// oItem was unacquired/lost (by a PC or NPC).
// Run by the module.
void OnUnacquire(object oItem, object oLostBy)
{
   // Enter code to execute when this event happens
}


// -----------------------------------------------------------------------------
// oItem was unequipped by a PC.
// Run by the module.
void OnUnequip(object oItem, object oUnequippedBy)
{
  //Remove Speed Increase
  object oPC = oUnequippedBy;
  effect e = GetFirstEffect(oPC);
  string sTag;
  while(GetIsEffectValid(e))
  {
   sTag = GetTag(GetEffectCreator(e)) ;
   if(sTag  == "eff_caster")
   {
    FloatingTextStringOnCreature("Effect Removed!", oPC, FALSE);
    RemoveEffect(oPC, e);
   }
   e = GetNextEffect(oPC);
  }

}


//////////////////////////////////////////////////////////////////////////////
// ##### WARNINING:: DON'T TOUCH ANYTHING BELOW THIS LINE!!! #### ///////////
////////////////////////////////////////////////////////////////////////////

// The main function.
void main()
{
   int nEvent = GetUserDefinedItemEventNumber();

   // Spells might continue to their spell scripts. All other events are
   // completely handled by this script.
   if ( nEvent != X2_ITEM_EVENT_SPELLCAST_AT )
       SetExecutedScriptReturnValue();

   // Determine which event triggered this script's execution.
   switch ( nEvent )
   {
       // Item was acquired.
       case X2_ITEM_EVENT_ACQUIRE:
               OnAcquire(GetModuleItemAcquired(), GetModuleItemAcquiredBy(),
                         GetModuleItemAcquiredFrom(), GetModuleItemAcquiredStackSize());
               break;

       // Item was activated ("activate item" or "unique power").
       case X2_ITEM_EVENT_ACTIVATE:
               OnActivate(GetItemActivated(), GetItemActivatedTarget(),
                          GetItemActivatedTargetLocation(), GetItemActivator());
               break;

       // Item was equipped by a PC.
       case X2_ITEM_EVENT_EQUIP:
               OnEquip(GetPCItemLastEquipped(), GetPCItemLastEquippedBy());
               break;

       // Item is a weapon that just hit a target, or it is the armor of someone
       // who was just hit.
       case X2_ITEM_EVENT_ONHITCAST:
               OnHit(GetSpellCastItem(), GetSpellTargetObject(), OBJECT_SELF);
               break;

       // A PC (or certain NPCs) cast a spell at the item.
       case X2_ITEM_EVENT_SPELLCAST_AT:
               if ( OnSpellCast(GetSpellTargetObject(), GetSpellId(), OBJECT_SELF) )
                   SetExecutedScriptReturnValue();
               break;

       // Item was unacquired.
       case X2_ITEM_EVENT_UNACQUIRE:
               OnUnacquire(GetModuleItemLost(), GetModuleItemLostBy());
               break;

       // Item was unequipped by a PC.
       case X2_ITEM_EVENT_UNEQUIP:
               OnUnequip(GetPCItemLastUnequipped(), GetPCItemLastUnequippedBy());
               break;
   }
}
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #16 on: April 30, 2013, 12:21:08 am »


               Without having read your script, I can tell you that what was suggested will work, if done properly, and that the most likely problem is that you're only AssignCommanding the application of the effect, rather than its declaration, which is what GetEffectCreator looks for. You need to ensure that the object you want to be the creator is the one calling the function, main or otherwise, that creates the effect. The ApplyEffect is totally irrelevant - it's all about the declaration, that is,
effect eSomething = blah;

Funky
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #17 on: April 30, 2013, 05:15:37 pm »


               Just for consistency I would define oEquippedBy as oPC, as you did in the unequipped portion.
Make sure the object eff_creator actually exists, in the toolset.
It appears the effect creator was done correctly.
AssignCommand(oEC, ApplyEffectToObject(
DURATION_TYPE_PERMANENT, eMas, oEquippedBy));

So how do you know it is not removing it?  Becasue the visual effect is still active, since the modify attacks would
be diificult to detect?  Perhaps better to link those effects and apply them together.  As it stands you have two seperate effects applied by the same object, though that should not matter if the script is working properly.  The script should loop through all extant effects created by eff_creator and remove them accordingly. Btw I would remove the reference to speed as it is irrelevant, perhaps just change it to effect.
               
               

               


                     Modifié par ffbj, 30 avril 2013 - 04:23 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #18 on: April 30, 2013, 06:06:08 pm »


               Thanks Funky, that did it, I executed a script on the placeable object, by setting a local object of the PC on the PO, (Placeable Object), then the Tag Based script properly removed it because it properly found the Effect Creator...


This really helped me a lot, I suppose I will have to make some more use of this. =)
(Going to make a good system with this)


Thanks again Funky! ':wizard:'
               
               

               


                     Modifié par _Guile, 30 avril 2013 - 05:24 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #19 on: April 30, 2013, 06:53:01 pm »


               Made this for fun =)
/////////////////////////////////////////////////////////////////////////

// eff_caster_exc
////////////////////////////////////////////////
// Created By: Genisys / Guile
// Created On: 2/10/2013
////////////////////////////////////////////////////////////////////////////////
/*
  This script is executed on a spawned in object used to apply an effect to
  the PC, this way we can through scripting remove any effect applied to the
  PC without removing other effects by accident!

  This is ONLY For Permanent Effects/Feats, as there is no need for temporary!
*/
////////////////////////////////////////////////////////////////////////////////

//Main Script
void main()
{
// The Placeable Object that was spawned in for this effect!
object oMe = OBJECT_SELF;

// The PC we saved on the placeable Object...
object oPC = GetLocalObject(oMe, "PC_2_B_EFFECTED");

int nEffect = GetLocalInt(oMe, "EFFECT_NUM");
int Parm1 = GetLocalInt(oMe, "PARAMETER_1");
int Parm2 = GetLocalInt(oMe, "PARAMETER_2");
int Parm3 = GetLocalInt(oMe, "PARAMETER_3");

int nVFX = GetLocalInt(oMe, "VFX_NUMBER");
float fDur = GetLocalFloat(oMe, "FLOAT_DURATION");

effect eEff, eVis;

switch(nEffect)
{
 case 0: // Modify Attacks
 {
   eEff = EffectModifyAttacks(Parm1);
 } break;

 case 1: // Improved AC
 {
   eEff = EffectACIncrease(Parm1, Parm2, AC_VS_DAMAGE_TYPE_ALL);
 } break;
 case 2: // Improved AB
 {
   eEff = EffectAttackIncrease(Parm1, ATTACK_BONUS_MISC);
 } break;
 case 3: // Improved SR
 {
   eEff = EffectSpellResistanceIncrease(Parm1);
 } break;
 case 4: // Concealment
 {
   eEff = EffectConcealment(Parm1, MISS_CHANCE_TYPE_NORMAL);
 } break;
 case 5: // Regeneration / 3 Second or More
 {
   if(fDur < 3.0)
   { fDur = 3.0; } // Minimum is ever 3 seconds! (Or 2 X per round)
   eEff = EffectRegenerate(Parm1, fDur);
 } break;
 case 6: // Skill Bonus
 {
   eEff = EffectSkillIncrease(Parm1, Parm2);
 } break;
 case 7: // EffectDamageShield
 {
   eEff = EffectDamageShield(Parm1, Parm2, Parm3);
 } break;
 case 8: // Saving Throw Increase
 {
   eEff = EffectSavingThrowIncrease(Parm1, Parm2, Parm3);
 } break;
 case 9: // Temporary Hitpoints
 {
   eEff = EffectTemporaryHitpoints(Parm1);
 } break;
 case 10: // Padding..
 {

 } break;
 case 11: // Padding..
 {

 } break;
}

 //Apply the Effect
 eEff = SupernaturalEffect(eEff); // NOT Dispellable!
 ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEff, oPC, 0.0);

 //Apply the VFX if one exist...
 if(nVFX >= 1)
 {
  eVis = EffectVisualEffect(nVFX, FALSE);
  ApplyEffectToObject(DURATION_TYPE_PERMANENT, eVis, oPC, 0.0);
 }

//Main Script End
}
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #20 on: April 30, 2013, 06:59:19 pm »


               Any critique on the above script?   (note the date is off, doh!)
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #21 on: April 30, 2013, 08:36:26 pm »


               

ffbj wrote...

Just for consistency I would define oEquippedBy as oPC, as you did in the unequipped portion.
Make sure the object eff_creator actually exists, in the toolset.
It appears the effect creator was done correctly.
AssignCommand(oEC, ApplyEffectToObject(
DURATION_TYPE_PERMANENT, eMas, oEquippedBy));


The effect creator was not done properly.  The creator of an effect is the object running the script when the effect is declared.  Since eMas was declared on the main script means that eMas is not created by oEC.  If he instead put

AssignCommand(oEC, ApplyEffectToObject(
DURATION_TYPE_PERMANENT, EffectModifyAttacks(1), oEquippedBy));

then the effect would be declared within an assigned command and oEC would be the creator.
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #22 on: April 30, 2013, 09:09:20 pm »


               

WhiZard wrote...
AssignCommand(oEC, ApplyEffectToObject(
DURATION_TYPE_PERMANENT, EffectModifyAttacks(1), oEquippedBy));

then the effect would be declared within an assigned command and oEC would be the creator.


Your example is better than mine. It points out that it's not even really the declaration that matters, so much as it is the creation of the effect struct - you can have an effect creator without an explicit declaration, as in your example.

Funky
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #23 on: May 01, 2013, 02:35:24 pm »


               OK Thanks again for the help, I got the script working by setting the function within the ApplyCommand, function like you showed above Whizard, and it worked, thanks again!


AssignCommand(oEC, ApplyEffectToObject(
DURATION_TYPE_PERMANENT, EffectModifyAttacks(1), oEquippedBy));
               
               

               


                     Modifié par _Guile, 01 mai 2013 - 04:23 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Help with Removing Modify Attacks..
« Reply #24 on: May 01, 2013, 06:36:28 pm »


               Yeah, that is why I said it appeared correct. So all you do is not define eMas, and just put the effect within the creation line.  The script itself was a little Funky since it is not structured the way I do these type of scripts.