Author Topic: Effects  (Read 707 times)

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Effects
« Reply #30 on: September 08, 2013, 10:06:45 am »


               That's where it can get a little tricky. If you have more than one item that can summon a horse then you might want some other object in your mod create the haste effect when people summon/mount a horse. You could also use an area or the mod itself but then you run into problems with removing the wrong effects if the mod was assigned to create other effects. Either way you need to either "get" the item used or "get" the object in mod used to create the effect.

Let's say you have more than one mounting item and want to use an in game object to be the creator of your mounted haste effect. This could be anything from a fence post to an NPC. I usually use some small object in an inaccessable DM area or what not. So instead of the example script I posted above (which has the activated item create the effect) you would do something more like so (which uses an in game object as the effect creator):

#include "zep_inc_phenos"
#include "x2_inc_switches"
void main()
{
       int nEvent = GetUserDefinedItemEventNumber();
       if (nEvent != X2_ITEM_EVENT_ACTIVATE) return;

       effect eEffect;
       object oPC = GetItemActivator();
       object oEffectCreator = GetObjectByTag("HORSE_HASTE");
       int nMount = nCEP_PH_HORSE_BLACK;
       int iMounted = GetLocalInt(oPC, "Mounted");

       if (iMounted == 0)
        {
              zep_Mount(oPC, OBJECT_INVALID, nMount);
              SetLocalInt(oPC, "Mounted", 1);
              AssignCommand(oEffectCreator, ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectHaste(),oPC));
        }

       else
        {
              zep_Dismount(oPC);
              SetLocalInt(oPC, "Mounted", 0);
              eEffect = GetFirstEffect(oPC);
              while (GetIsEffectValid(eEffect))
                {
                     if (GetEffectCreator(eEffect)==oEffectCreator)
                     RemoveEffect(oPC, eEffect);
                     eEffect = GetNextEffect(oPC);
                }
        }
}

Then you could force dismount and remove the effect like so:

void main()
{

    object oPC = GetEnteringObject();

    if (!GetIsPC(oPC)) return;

    if (GetLocalInt(oPC, "Mounted")== 1)
    {
         object oEffectCreator = GetObjectByTag("HORSE_HASTE");
                //force dismount//
         zep_Dismount(oPC);
                 SetLocalInt(oPC, "Mounted", 0);
         effect eEffect = GetFirstEffect(oPC);
         while (GetIsEffectValid(eEffect))
        {
            if (GetEffectCreator(eEffect)==oEffectCreator)
            RemoveEffect(oPC, eEffect);
            eEffect = GetNextEffect(oPC);
         }
        }
}


Now if you just want to force dismount and remove the effect based on the item that was activated then you have to get the specific item (you could also do a loop to check againts multiple items to see of any of them are the creator of the haste effect). So you could do something like so:

void main()
{

    object oPC = GetEnteringObject();

    if (!GetIsPC(oPC)) return;

    if (GetLocalInt(oPC, "Mounted")== 1)
    {
         object oItem = GetItemPossessedBy(oPC, "Tag of item");
                //force dismount//
         zep_Dismount(oPC);
                 SetLocalInt(oPC, "Mounted", 0);
         effect eEffect = GetFirstEffect(oPC);
         while (GetIsEffectValid(eEffect))
        {
            if (GetEffectCreator(eEffect)==oItem)
            RemoveEffect(oPC, eEffect);
            eEffect = GetNextEffect(oPC);
         }
        }
}

Hope this helps.
P.S. I typed all the script here in the reply so there could be some mistypes or what not. I haven't tried compiling or anything.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Effects
« Reply #31 on: September 11, 2013, 06:15:59 pm »


               Everything compiled so will test this .
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Effects
« Reply #32 on: September 12, 2013, 03:27:45 am »


               You can also just remove in mount transversal which  is the standard hb check for mounted-ness.  Or rather the condition of being mounted, and then simply remove it (haste).
The reason this approach might be preferable is that it is a blanket removal of haste by whatever method..mass haste, item..whatever.  So it removes the possibility of a mounted PC being hasted, which to my way of thinking is not necessarily a bad thing.
               
               

               


                     Modifié par ffbj, 12 septembre 2013 - 02:46 .