Author Topic: tagbased problems  (Read 1928 times)

Legacy_Cursed_Eclipse

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
tagbased problems
« on: May 12, 2012, 09:04:26 am »


               Hi

In my pw i have  items (tagabased) that once worn,give a little boost to the new characters.

The problem are that when the character lv up, or when dies and then respwan,the effect provided by this items goes away, even if it is still worn.

how can I fix this issue?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
tagbased problems
« Reply #1 on: May 12, 2012, 11:00:24 am »


               You will need to make sure that in your tagbased script that you put the effect inside an assign command to the item so that it will be considered the effect creator.

Example:

#include "x2_inc_switches"
void main()
{
    int iEvent = GetUserDefinedItemEventNumber();
    if (iEvent == X2_ITEM_EVENT_EQUIP)
    {
        object oPC = GetPCItemLastEquippedBy();
        object oItem = GetPCItemLastEquipped();
        AssignCommand(oItem, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectDeaf()), oPC));
    }
    if (iEvent == X2_ITEM_EVENT_UNEQUIP)
    {
        object oPC = GetPCItemLastUnequippedBy();
        object oItem = GetPCItemLastUnequipped();
        effect eEffect = GetFirstEffect(oPC);
        while (GetIsEffectValid(eEffect))
        {
            if (GetEffectCreator(eEffect) == oItem)
            RemoveEffect(oPC, eEffect);
            eEffect = GetNextEffect(oPC);
        }
    }
}

Your Level up and your OnDeath scripts are removing effects from players. You need to alter these scripts to ignore the effects created by these items. Or you could alter your level up and respawn scripts to re-add the effects if a certain item is equpped.
               
               

               


                     Modifié par GhostOfGod, 12 mai 2012 - 11:01 .
                     
                  


            

Legacy_Cursed_Eclipse

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
tagbased problems
« Reply #2 on: May 12, 2012, 12:05:07 pm »


               

GhostOfGod wrote...

You will need to make sure that in your tagbased script that you put the effect inside an assign command to the item so that it will be considered the effect creator.

Example:

#include "x2_inc_switches"
void main()
{
    int iEvent = GetUserDefinedItemEventNumber();
    if (iEvent == X2_ITEM_EVENT_EQUIP)
    {
        object oPC = GetPCItemLastEquippedBy();
        object oItem = GetPCItemLastEquipped();
        AssignCommand(oItem, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectDeaf()), oPC));
    }
    if (iEvent == X2_ITEM_EVENT_UNEQUIP)
    {
        object oPC = GetPCItemLastUnequippedBy();
        object oItem = GetPCItemLastUnequipped();
        effect eEffect = GetFirstEffect(oPC);
        while (GetIsEffectValid(eEffect))
        {
            if (GetEffectCreator(eEffect) == oItem)
            RemoveEffect(oPC, eEffect);
            eEffect = GetNextEffect(oPC);
        }
    }
}

Your Level up and your OnDeath scripts are removing effects from players. You need to alter these scripts to ignore the effects created by these items. Or you could alter your level up and respawn scripts to re-add the effects if a certain item is equpped.


thx a lot.

even if i have applied the effect in another way

#include "x2_inc_switches"
void main()
{
  object oPC = GetPCItemLastEquippedBy(); 
  object oMod = GetModule();
  int nEvent = GetUserDefinedItemEventNumber();
  int nSpeed = 30;
  if(GetLevelByclass(class_TYPE_MONK, oPC)>=6)// ._.
  {
  nSpeed-= 25;
  }
  if (nEvent == X2_ITEM_EVENT_EQUIP)
      {
      effect eEffect = EffectMovementSpeedIncrease(nSpeed);
      //eEffect = SupernaturalEffect(eEffect);
AssignCommand(GetObjectByTag("tagbb") ,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(eEffect), oPC));
      return;
      }
cut...



but I find your solution much simpler:

object oItem = GetPCItemLastEquipped();
AssignCommand(oItem, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectDeaf()), oPC));




  Now I guess I'll have to enter somenthing like this on Lv Up/respwan:



object oItem = GetPCItemLastEquipped();

object oPC = GetPCLevellingUp();
effect eSpeed = GetFirstEffect(oPC);//<- pc  Lv_UP

 while (GetIsEffectValid(eSpeed))//eSpeed
    {
    if (GetEffectType(eSpeed) == EFFECT_TYPE_MOVEMENT_SPEED_INCREASE))
        {
        if(GetEffectCreator(eSpeed)) != oItem)
                 {
                 //do stuff
                 }
               }
          }


I did well?

EDIT
               
               

               


                     Modifié par Cursed_Eclipse, 12 mai 2012 - 11:51 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
tagbased problems
« Reply #3 on: May 12, 2012, 02:38:42 pm »


               Brilliant GOG.. '<img'>
               
               

               


                     Modifié par _Guile, 12 mai 2012 - 01:38 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
tagbased problems
« Reply #4 on: May 13, 2012, 08:23:35 am »


               

Cursed_Eclipse wrote...
even if i have applied the effect in another way

#include "x2_inc_switches"
void main()
{
  object oPC = GetPCItemLastEquippedBy(); 
  object oMod = GetModule();
  int nEvent = GetUserDefinedItemEventNumber();
  int nSpeed = 30;
  if(GetLevelByclass(class_TYPE_MONK, oPC)>=6)// ._.
  {
  nSpeed-= 25;
  }
  if (nEvent == X2_ITEM_EVENT_EQUIP)
      {
      effect eEffect = EffectMovementSpeedIncrease(nSpeed);
      //eEffect = SupernaturalEffect(eEffect);
AssignCommand(GetObjectByTag("tagbb") ,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(eEffect), oPC));
      return;
      }
cut...


If you wanted to use a placeable object/npc you could do that to. You just need to make sure you don't declare the effect outside the "AssignCommand" function or in this case the module would be considered the effect creator (which would also be fine unless the module is creating some other effects that you don't want removed). If you keep the actual effect inside the "AssignCommand" then who/whatever you assign the command to will be the "creator".


Now I guess I'll have to enter somenthing like this on Lv Up/respwan:

object oItem = GetPCItemLastEquipped();
object oPC = GetPCLevellingUp();
effect eSpeed = GetFirstEffect(oPC);//<- pc  Lv_UP

 while (GetIsEffectValid(eSpeed))//eSpeed
    {
    if (GetEffectType(eSpeed) == EFFECT_TYPE_MOVEMENT_SPEED_INCREASE))
        {
        if(GetEffectCreator(eSpeed)) != oItem)
                 {
                 //do stuff
                 }
               }
          }


Yep. But you would need to find the item specifically equipped in whatever slot since the last equipped item at the point of death might no longer be the same item that created the effect.
               
               

               


                     Modifié par GhostOfGod, 13 mai 2012 - 07:30 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
tagbased problems
« Reply #5 on: May 14, 2012, 10:50:54 pm »


               

GhostOfGod wrote...
AssignCommand(oItem, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectDeaf()), oPC));


Something doesn't seem right about this.  GetEffectCreator() gets the creator of the effect, not the applier.  In order to make this work one should have to do something like this.

void ApplyDeaf(object oTarget)
{
//This is where the effect is created
effect eDeaf = SupernaturalEffect(EffectDeaf());
//This is where the effect is applied
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eDeaf, oTarget);
}

void main()
{
object oItem =GetItemActivated();
object oPC = GetItemActivator();
AssignCommand(oItem, ApplyDeaf(oPC));
}
               
               

               


                     Modifié par WhiZard, 14 mai 2012 - 10:06 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
tagbased problems
« Reply #6 on: May 14, 2012, 11:28:51 pm »


               Both work out the same way.     In ghost's assignment the effect is not created untill after it is assigned, Therefore the Item will still be the creator, not the object the script is running on.

At least that is what my memory says, without testing.  
The same reason you would normaly create the effect before assigning and pass it as a Var  to allow the object running the script to be the creator.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
tagbased problems
« Reply #7 on: May 15, 2012, 04:06:42 am »


               

Lightfoot8 wrote...

Both work out the same way.     In ghost's assignment the effect is not created untill after it is assigned, Therefore the Item will still be the creator, not the object the script is running on.

At least that is what my memory says, without testing.  
The same reason you would normaly create the effect before assigning and pass it as a Var  to allow the object running the script to be the creator.


You are partially correct.  This would work if the effect was defined in the assign command, but it isn't.  SupernaturalEffect() does not create a new effect, it merely updates the effect's listing.  If you applied an effect and then used SupernaturalEffect() all instances of that effect on creatures  would return supernatural by GetEffectSubtype() even if they are not supernatural.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
tagbased problems
« Reply #8 on: May 15, 2012, 04:28:30 am »


               ooops,  Sorry I skimmed over it to fast.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
tagbased problems
« Reply #9 on: May 15, 2012, 04:37:41 am »


               Have you tested it WhiZard? I've used this method quite a bit and so far it seems to work fine with "GetEffectCreator". I use it for things like partially cursed items. Ones that you can still unequip but while equipped have some negative effect like blindness or deafness, etc.
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
tagbased problems
« Reply #10 on: May 15, 2012, 06:00:01 am »


               

GhostOfGod wrote...

Have you tested it WhiZard? I've used this method quite a bit and so far it seems to work fine with "GetEffectCreator". I use it for things like partially cursed items. Ones that you can still unequip but while equipped have some negative effect like blindness or deafness, etc.


Yes, I tested it.

This works
AssignCommand(...,ApplyEffectToObject(...,..., SupernaturalEffect(EffectDazed())));

This does not
effect eDaze = EffectDazed();
AssignCommand(...,ApplyEffectToObject(....,..., SupernaturalEffect(eDaze)));
               
               

               


                     Modifié par WhiZard, 15 mai 2012 - 05:02 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
tagbased problems
« Reply #11 on: May 15, 2012, 06:09:36 am »


               ?? But your first example that works is the way I did it also. I used "EffectDeaf()" in the example. Now I'm confused.
               
               

               


                     Modifié par GhostOfGod, 15 mai 2012 - 05:11 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
tagbased problems
« Reply #12 on: May 15, 2012, 06:16:13 am »


               ... Okay, I'm the one misreading and I even have it quoted, to show the number of times I misread.  Your method works carry on...

apologies to you and Lightfoot
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
tagbased problems
« Reply #13 on: May 15, 2012, 06:18:51 am »


               Haha. No worries. I just thought I was doing something wrong all the sudden. And besides, half the time I misread my own posts.'<img'>
               
               

               


                     Modifié par GhostOfGod, 15 mai 2012 - 05:19 .
                     
                  


            

Legacy_Cursed_Eclipse

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
tagbased problems
« Reply #14 on: May 15, 2012, 06:56:24 am »


               after reading what you wrote i modified my tagbased


#include "x2_inc_switches"
void main()
{
  object oPC = GetPCItemLastEquippedBy();
  object oItem = GetPCItemLastEquipped();
  int nEvent = GetUserDefinedItemEventNumber();
  int nSpeed = 30;
  if(GetLevelByclass(class_TYPE_MONK, oPC)>=6)// ._.
  {
  nSpeed-= 25;
  }
  if (nEvent == X2_ITEM_EVENT_EQUIP)
      {
AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,
SupernaturalEffect(EffectMovementSpeedIncrease(nSpeed)), oPC));
      return;
      }
      else if (nEvent == X2_ITEM_EVENT_UNEQUIP)
      {

effect Effect = EffectMovementSpeedIncrease(nSpeed);     
effect eEffect = GetFirstEffect(oPC);

           while (GetIsEffectValid(eEffect))
            {
             if(GetEffectCreator(eEffect) == oItem)
              {
               if (GetEffectType(eEffect) == EFFECT_TYPE_MOVEMENT_SPEED_INCREASE)
                 {
                  RemoveEffect(oPC, eEffect);
                  eEffect = GetNextEffect(oPC);
                 }
              }
           }
       }

}


I have not tested yet.



 
are still very confused about how to act,anyway i put this code On  Lv UP

-cut-

    object oPC = GetPCLevellingUp();
    if (!GetIsPC(oPC)) return;
    if(IsInConversation(oPC)== TRUE)return;
    //object oPC = GetPCItemLastEquippedBy();
    object oItem = GetPCItemLastEquipped();


-cut-

   if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_EQUIP);
        object oBra = GetItemInSlot(INVENTORY_SLOT_ARMS, oPC);
        //object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC);
        //object oWeap = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);

if(GetTag(oBra) == "1_brac_speed")
{
//effect eEffect = EffectMovementSpeedIncrease(30);
AssignCommand(oItem, ApplyEffectToObject(DURATION_TYPE_PERMANENT, SupernaturalEffect(EffectMovementSpeedIncrease(30)), oPC));
}
 if (nRet == X2_EXECUTE_SCRIPT_END)
     {
     return;
     }
  }


in this way the effect remains.
But i'm not sure this is the right way to re-apply the effects.



The problem is that I am experiencing other errors ':unsure:'
               
               

               


                     Modifié par Cursed_Eclipse, 15 mai 2012 - 06:05 .