Author Topic: PW Repeated Random Script Firing  (Read 512 times)

Legacy_Tyes

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
PW Repeated Random Script Firing
« on: October 16, 2010, 07:06:24 pm »


               So I'm having a slight issue with my unique item activation scripts, due to the fact that on my new PW, the unique items are held by a number of players (such as an ooc room tool) which keeps activating randomly, if a player has used one before.

So for example, someone uses the ooc room tool, which teleports them to the ooc room, every so often it will jump them back into the room, even if they haven't used it.

The scripts currently look like this:


 #include "x2_inc_switches"void main(){ int nEvent =GetUserDefinedItemEventNumber();     if (!nEvent == X2_ITEM_EVENT_ACTIVATE)     return;
object oPC;
oPC = GetItemActivator();
object oTarget;location lTarget;oTarget = GetWaypointByTag("br_oocroom");
lTarget = GetLocation(oTarget);
if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;
AssignCommand(oPC, ClearAllActions());
AssignCommand(oPC, ActionJumpToLocation(lTarget));
}
Any help is very much appreciated, thanks.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #1 on: October 16, 2010, 07:19:24 pm »


               I reworked it a bit try this and see if it works better.

#include "x2_inc_switches"

void main()
{
 if (GetUserDefinedItemEventNumber() != X2_ITEM_EVENT_ACTIVATE) return;
 object oPC = GetItemActivator();
 location lTarget = GetLocation(GetWaypointByTag("br_oocroom"));

 if (GetAreaFromLocation(lTarget)==OBJECT_INVALID) return;

 AssignCommand(oPC, ClearAllActions(TRUE));
 AssignCommand(oPC, ActionJumpToLocation(lTarget));
}

               
               

               


                     Modifié par Baragg, 16 octobre 2010 - 06:19 .
                     
                  


            

Legacy_Dagesh

  • Jr. Member
  • **
  • Posts: 55
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #2 on: October 17, 2010, 01:47:29 am »


               As Baragg posted, this may be an issue:

!nEvent == X2_ITEM_EVENT_ACTIVATE



Change to:

nEvent != X2_ITEM_EVENT_ACTIVATE



Otherwise you'll probably fire other "X2_ITEM_EVENT_"s such as OnAcquire and other events like that.
               
               

               
            

Legacy_Tyes

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #3 on: October 18, 2010, 11:14:40 pm »


                Thanks for the help guys. Unfortunately I seem to still be getting an issue with the scripts.

Would the issue possibly be linked to the firing script?

Such as a script named br_flashstep firing off ac_br_flashstep if it's an activated script?

#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
switch (nEvent)
{
case X2_ITEM_EVENT_ACTIVATE:
ExecuteScript("ac_"+GetTag(GetItemActivated()),
OBJECT_SELF); break;
}
}

if not that, am I possibly getting the other script wrong?

#include "x2_inc_switches"
void main()
{
int nEvent =GetUserDefinedItemEventNumber();
if (nEvent != X2_ITEM_EVENT_ACTIVATE)
return;
object oActivator = GetItemActivator();
vector vVector = GetPosition(oActivator);
float fZ = GetFacing(oActivator);
location lWhere = GetItemActivatedTargetLocation();
vector vVectorb = GetPositionFromLocation(lWhere);
object oArea = GetArea(oActivator);
location lLocation = Location(oArea, vVectorb, fZ);
float oDistance = GetDistanceBetweenLocations (lWhere, lLocation);
effect eVis = EffectVisualEffect(VFX_IMP_PULSE_HOLY);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oActivator);
AssignCommand(oActivator, JumpToLocation(lLocation));
}
               
               

               


                     Modifié par Tyes, 18 octobre 2010 - 10:21 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #4 on: October 19, 2010, 12:41:15 am »


               My first guess is that your forgot to compile the script after making the edits - if you don't have autocompile with save turned on, that is. I'm a little surprised no one told you WHY your script was doing this.

The first two lines of your script:

int nEvent =GetUserDefinedItemEventNumber();    
 if (!nEvent == X2_ITEM_EVENT_ACTIVATE)     return;
The typical code would normally look as Baragg posted, but WHY? The point of this code is to abort the script execution for events other than item activation, but that isn't what your code does. Whoever altered it apparently thought that (!x == y) is logically identical to (x != y) - it isn't. != means 'does not equal', and will return TRUE if the two expressions it is comparing aren't identical, FALSE if they are identical - it's the exact opposite of ==, which returns TRUE if they expressions are identical, FALSE if they aren't.

! placed in front of an expression, however, changes it from TRUE to FALSE and vice versa - !TRUE means the same thing as FALSE, and !FALSE is TRUE.

The last piece of the puzzle is the value of the expression you're reversing with ! - it isn't intended to be used as a simple TRUE or FALSE value, but an int with multiple TRUE values (any value, positive or negative, that isn't 0, is TRUE, and 0 is FALSE). Here, the GetUserDefinedItemEventNumber returns this range of values (taken from the bioware include x2_inc_switches):
//------------------------------------------------------------------------------
// These constants define item messages that are routed to script files with
// the item tag's through the default XP2 module scripts.
//------------------------------------------------------------------------------
const int X2_ITEM_EVENT_ACTIVATE = 0;
const int X2_ITEM_EVENT_EQUIP = 1;
const int X2_ITEM_EVENT_UNEQUIP = 2;
const int X2_ITEM_EVENT_ONHITCAST = 3;
const int X2_ITEM_EVENT_ACQUIRE = 4;
const int X2_ITEM_EVENT_UNACQUIRE = 5;
const int X2_ITEM_EVENT_SPELLCAST_AT = 6;

What the normal function of this does is to return if the Event function returns anything but a 0, for Activate. What you're having it do with if (!nEvent == X2_ITEM_EVENT_ACTIVATE) is to take the value of nEvent, from 0-6, and flip the truth value. The net result is that it is firing on every event BUT activate. To see why, look what happens:

X2_ITEM_EVENT_ACTIVATE: 0 = FALSE, !0 = TRUE, !Event = TRUE, TRUE doesn't equal X2_ITEM_EVENT_ACTIVATE (which is 0, or FALSE), no fire

X2_ITEM_EVENT_EQUIP: 1 = TRUE, !1 = FALSE, !Event = FALSE, FALSE does equal X2_ITEM_EVENT_ACTIVATE (which is 0, or FALSE), script fires

The same happens with every other event whose const is greater than 0, as happens with EQUIP.

Normally, you'd be comparing event numbers to see if one equalled 0, the const for ACTIVATE, but instead you're simply checking to see if the event number is greater than 0. Whups.

Anyway, lmk if a compile doesn't solve it, now that you've made Baragg's edit.

Funky
               
               

               


                     Modifié par FunkySwerve, 18 octobre 2010 - 11:45 .
                     
                  


            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #5 on: October 19, 2010, 03:48:31 am »


               I wasn't really sure about that one line so I just keep my mouth shut as to it working or not the way it was written, and wrote it in a manner I was sure would work. I do appreciate yall clearing that up though. Learn something new every day if I just pay attention.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #6 on: October 19, 2010, 07:59:26 am »


               

Tyes wrote...

Such as a script named br_flashstep firing off ac_br_flashstep if it's an activated script?


Looks like you are using the 2 script Lilac's method. Just ignore the part about making that second generic script. Just name your main script, that you want fired when you active the item, the same as the tag of the item and put that check at the top that the others mentioned above.
               
               

               
            

Legacy_Tyes

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #7 on: October 25, 2010, 12:45:05 pm »


               Thanks for the help guys, the information was really good.



Unfortunately it turns out the scripts themselves are not the issue, I am using custom item scripts, as you obviously know from reading above, but I am also using DMFI 1.09 on the module, and the issue seems to be that whenever the custom item script is used by a person.. thereafter consequently whenever ANYONE on the server uses a DMFI item, such as the dicebag, or emote wand... it is firing the custom item script again.



I have the zep_on_activate2 script in my onactivate module event, as well as the oncliententer script being just the basic dmfi initialisation script, any help would be invaluable here as I'm beginning to tear my hair out... and I'm already bald.

Thanks in advance.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #8 on: October 25, 2010, 12:58:34 pm »


               Post the script.
               
               

               
            

Legacy_Tyes

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #9 on: October 25, 2010, 02:16:01 pm »


               Which script is it you'd like me to post?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
PW Repeated Random Script Firing
« Reply #10 on: October 25, 2010, 02:40:22 pm »


               Make sure you do not have anything in the zep_on_activate2 script that has anything to do with DMFI. IF you do remove it.

EDIT: Also if the tag of your Item starts with "DMFI" or "lan"  it will also cause this problem.  If it does change the tag of the item and the name of the script.
               
               

               


                     Modifié par Lightfoot8, 25 octobre 2010 - 03:55 .