Author Topic: Port items fireing when someone sells items or crafts  (Read 470 times)

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« on: January 07, 2012, 06:08:38 am »


               Ello everyone,
Ive got port items on small misc tokens that naturally ports a player to a specific waypoint upon use.  The problem is however when someone sells an item to a npc store or uses the servers craft system to change the look of their armor/weapon it refires the pin. Id like to know what is causing this so i can fix it. The item uses a tag based script to fire a conversation, which is as follows:


void main()
{
object oPC =  GetItemActivator();

if(GetIsPC(oPC))
    {
    AssignCommand (oPC, ActionStartConversation ( GetItemActivator(), "qualpinconv", TRUE, FALSE));
    }
    else
    {
    }
}

Then the convo uses this script to port the pc. I use this script in a capturable keep system ive got in, in case it looks a little confusing.

void main()
{
object oPC = GetPCSpeaker();
object oQual = GetObjectByTag("Qual_keep_defender");
object oQual2 = GetObjectByTag("Qual_keep_owner");

int iFlag1State;
int iFlag2State;
int iFlag3State;
int iFlag4State;

iFlag1State = GetLocalInt(GetModule(), "qkeep_flag1");
iFlag2State = GetLocalInt(GetModule(), "qkeep_flag2");
iFlag3State = GetLocalInt(GetModule(), "qkeep_flag3");
iFlag4State = GetLocalInt(GetModule(), "qkeep_flag4");
    {
    if ((iFlag1State == 1) && (iFlag2State == 1) && (iFlag3State == 1) && (iFlag4State == 1))
    if (iFlag1State == 1)
    if (iFlag2State == 1)
    if (iFlag3State == 1)
    if (iFlag4State == 1)
        {
        AssignCommand(oPC, ActionJumpToObject(oQual));
        }
    else
        {
        AssignCommand(oPC, ActionJumpToObject(oQual2));
        }
    ClearAllActions();
    }
}

If anyone needs any further info please let me know, and thanks in advance
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #1 on: January 07, 2012, 06:16:26 am »


               Likely you just need to put a check in to make sure that the script only runs on the OnActivate event.  OnAcquire and OnUnaquire also fire tag events.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #2 on: January 07, 2012, 06:23:34 am »


               You have to keep in mind that TBS (Tag Based Scripts)  Fire for more events then just OnActivate, They also fire for... Well lets just look at the constant list form X2_inc_switches for the list.

// X2_ITEM_EVENT_ACTIVATE
// X2_ITEM_EVENT_EQUIP
// X2_ITEM_EVENT_UNEQUIP
// X2_ITEM_EVENT_ONHITCAST
// X2_ITEM_EVENT_ACQUIRE
// X2_ITEM_EVENT_UNACQUIRE
// X2_ITEM_EVENT_SPELLCAST_AT

So basicly you want to make sure that the script only runs when it is actvated and not on any of the other events.

first place   #include "x2_inc_switches 

at the top of the script before the void main.  

Then add

If (GetUserDefinedItemEventNumber() !=  X2_ITEM_EVENT_ACTIVATE ) return;

as the first line of your script.  
               
               

               
            

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #3 on: January 07, 2012, 06:53:32 am »


               Ok thank you very much for the quick responses. Ill try your suggestion Lightfoot and letcha know in a few mins if it takes care of it. Thanks too for the explanation, it was really bugging me lol.

*EDIT: Ive done as suggested however the script continues to fire once ive sold something. Perhaps im doing it wrong? Not likely, considering your instructions were not that hard lol
               
               

               


                     Modifié par NightbladeCH, 07 janvier 2012 - 07:23 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #4 on: January 07, 2012, 12:51:43 pm »


               If they aren't overly long, could you post your mods OnAquire and OnUnaquire scripts?  It sounds like they're calling the tag script based on a check of the last item used.
               
               

               
            

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #5 on: January 07, 2012, 03:54:07 pm »


               They are rather long, is there an easier way to post em?

*EDIT:Ive enabled tag based scripting, so there is no seperate script in either of those or even onactivate that is calling these items.*
               
               

               


                     Modifié par NightbladeCH, 07 janvier 2012 - 04:04 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #6 on: January 07, 2012, 04:22:38 pm »


               Use pastebin
and then give us the link to the paste.

and you should show us the tag based script too.
               
               

               


                     Modifié par henesua, 07 janvier 2012 - 04:23 .
                     
                  


            

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #7 on: January 07, 2012, 04:52:21 pm »


               Ok, heres the mods Onaquire, Onactivate, and Unaquire. The other two scripts for the item are posted above
               
               

               


                     Modifié par NightbladeCH, 07 janvier 2012 - 04:53 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #8 on: January 07, 2012, 05:03:38 pm »


               It sounds to me like you have a module that was made before TBS, That someone added TBS to.  if that is the case this single script misfiring my not be your only problem.  combining the two systems is something that need the be done carefully.    

The old system compaired the tag of the item to a given tag then either handled the code in the module event or ran a script to handle what happens.   So you probable have a bunch of lines like.  

if (sTag == "DiceBag")  ExcuteScript(oPC, "DiceBag");


The new system simply takes the tag and runs a script by the name of the tag if it exsists, after setting a local (switch) on the module so that the script knows what event was fired. (TBS) 


 in order to help the things that really need to be known is the history of the module,   and the ratio of Tagbased scripts vs Non TagBasedscripts for items.   Hopefully This is the first TBS that you are adding.   
               
               

               
            

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #9 on: January 07, 2012, 05:17:55 pm »


               Id say the ratio is about even, the only tbs items that I have in are the ones that are used for porting players to their keeps. The scripts are pretty much all the same, and there are about 5 or 6 different ones currently. The ones in 'Onactivate' are the only non tbs ones in. The server was a project from before cep 2.1 i believe, and ive take then task of updating it and reworking all new areas and what not

Most of the scripts that are not tbs are the ones from before my coming, there are a few exceptions however. A few items wont seem to fire without them being added in the way you had mentioned before
               
               

               


                     Modifié par NightbladeCH, 07 janvier 2012 - 05:21 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #10 on: January 07, 2012, 05:32:16 pm »


               line 27 in unaquire

Change it to

SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
               
               

               


                     Modifié par Lightfoot8, 07 janvier 2012 - 05:32 .
                     
                  


            

Legacy_NightbladeCH

  • Jr. Member
  • **
  • Posts: 78
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #11 on: January 07, 2012, 06:14:52 pm »


               woot, that fixed it thanks a ton, that was really annoying
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Port items fireing when someone sells items or crafts
« Reply #12 on: January 08, 2012, 03:37:58 am »


                 You're also getting the wrong item in the unaquire, which is what I'd thought was happening.

  Unaquire events should use:
 
object oItem = GetModuleItemLost();
(and if needed)
object PC     =  GetModuleItemLostBy()

  You have these OnActivated item checks in place in it:

object oItem = GetItemActivated();
object oActivator = GetItemActivator();
location lTarget = GetItemActivatedTargetLocation();
object oTarget = GetItemActivatedTarget();