Author Topic: UserDefined OnDisturbed Script Not Firing  (Read 540 times)

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« on: March 25, 2011, 06:50:10 am »


               Hi all,

I've spent some time looking at this code and can't for the life of me figure out why it won't trigger. Here's some background: I have a script that creates an "I Am Disturbed Token" on a NPC when the right conditions are met. The idea is once this item was created in the inventory, the user defined
disturbed script section would fire with my code. The problem is this
isn't happening.

I already double checked with the DM Client and needless to say that one Token (and ONLY one) IS getting created in my creature's inventory. I have altered my onspawn code to allow user defined disturbed events to fire this script in the OnUserDefined tab.

Here is the code:

#include "nw_i0_plot"

const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
    int nUser = GetUserDefinedEventNumber();
    int iRan = d3();                                                                    \\\\ Ignore this, it just determines my NPC's reaction
    object oNPC = OBJECT_SELF;
    object oPC = GetLocalObject(GetModule(), "o_magicuser");

    else if(nUser == EVENT_DISTURBED) // DISTURBED
    {
        // This event triggers when the NPC loses his I Am Disturbed Token. It
        // creates another one in their inventory (so they can get disturbed again),
        // and causes the reaction.

        if (HasItem(oNPC, "iamdisturbedtoke"))
        {
            DestroyObject(GetItemPossessedBy(oNPC, "iamdisturbedtoke"));
            iRan = d3();

            // Depending on iRan, oNPC will say something different
            if (iRan == 1)
            {
                AssignCommand(oNPC, ActionSpeakString("Magicker!", TALKVOLUME_SHOUT));
            }
            else if (iRan == 2)
            {
                AssignCommand(oNPC, ActionSpeakString("Help! Magic user!", TALKVOLUME_SHOUT));
            }
            else
            {
                AssignCommand(oNPC, ActionSpeakString("Wizard! Wizard!", TALKVOLUME_SHOUT));
            }

            // This part causes oNPC to flee from oPC
            AssignCommand(oNPC, ActionMoveAwayFromObject(oPC, TRUE));
            DelayCommand(60.0, SetLocalInt(oNPC, "int_sawmagicuser", FALSE));
            }
        }
}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #1 on: March 25, 2011, 08:11:02 am »


               Hmm...Well this script doesn't even compile. You started with an "else if" instead of just an "if".

#include "nw_i0_plot"

const int EVENT_USER_DEFINED_PRESPAWN = 1510;
const int EVENT_USER_DEFINED_POSTSPAWN = 1511;
void main()
{
    int nUser = GetUserDefinedEventNumber();
   
    int iRan = d3();  \\\\ Ignore this, it just determines my NPC's reaction
    object oNPC = OBJECT_SELF;
    object oPC = GetLocalObject(GetModule(), "o_magicuser");

    else if(nUser == EVENT_DISTURBED) // DISTURBED
    {
        // This event triggers when the NPC loses his I Am Disturbed Token. It



Did this compile for you? Is there any of this script missing?
               
               

               


                     Modifié par GhostOfGod, 25 mars 2011 - 08:11 .
                     
                  


            

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #2 on: March 25, 2011, 03:32:42 pm »


               Sorry, I should have mentioned that I cut out parts and and pasted from the default OnUserDefined script (x2_def_userdef). The actual script is much longer (starting with a whole other section for behaviour on perceive), but I didn't want to post a script with a whole bunch of sections that have nothing to do with my problem. Again, my bad, '<img'>!
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #3 on: March 25, 2011, 07:29:24 pm »


               You said your NPCs do receive the item as they are suppose to cant you use the onacquire to fire the pattern you want?
               
               

               
            

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #4 on: March 25, 2011, 08:05:24 pm »


               That's a much better idea than what I was trying to do...thanks Baragg!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #5 on: March 25, 2011, 09:01:44 pm »


               My guess Is that it was not working because you never set the SpawnInCondition :  

SetSpawnInCondition(NW_FLAG_DISTURBED_EVENT)

In your onSpawn script or it is commented out.  Without it being set the UserDefined Event will never fire from the Disturbed Event.

However If you are always creating the Object in the creatures inventory and he is never picking it up or having a DM place it in his inventory.  You are jumping through to many hoops to get where you are going.  

Again if the item is always being created in the inventory by a script.  All you need to do is directly signal the User Defined Event from the script instead of creating the Item. .  

SignalEvent(oCreature, EventUserDefined(EVENT_DISTURBED));
               
               

               
            

Legacy_Ralthis

  • Jr. Member
  • **
  • Posts: 90
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #6 on: March 26, 2011, 10:47:36 pm »


               Ahh, that would be much better. Thank you Lightfoot. It's my first time trying to use UserDefined scripting, so any advice is good advice. Baragg, I tried your method, and it works like a charm!
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
UserDefined OnDisturbed Script Not Firing
« Reply #7 on: March 27, 2011, 03:26:03 am »


               Trust me when I say, Lightfoot is waaaaay better at this than I, but I do have a moment every once and again.