Author Topic: How do you spawn an NPC in an area when some condition is satisfied?  (Read 465 times)

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0


               

Hi fellas. I'm trying to get an NPC to spawn in an area when the PC enters that area and some predefined integer variable reaches a certain value. I placed this script in the area's Properties --> Events --> OnEnter window:


 


if((GetLocalInt(GetPCSpeaker(), "violet99") == 3))

  {

    location angelaappearshere = GetLocation(OBJECT_SELF);

    CreateObject(OBJECT_TYPE_CREATURE, "Angela", angelaappearshere);

    SetLocalInt(GetPCSpeaker(), "violet99", 4);

  }

 

Here 'angelaappearshere' is the tag of a waypoint I placed in the area and 'Angela' is the NPC's tag. 'violet99' is an integer-type variable declared beforehand in the 'variables' section under Module Properties --> Advanced. What I'm trying to do is tell the game:

 

When my PC enters this area, check if the value of 'violet99' is 3. If yes, spawn the specified NPC at the waypoint specified. Then change the value of 'violet99' to 4, so that later when my PC leaves and then returns yet again no second copy of the NPC will be spawned.

 

The script compiled without any errors, but didn't work. '<img'> Why? What did I do wrong? How do I make it work? Any help will be appreciated. Thanks in advance!


               
               

               
            

Legacy_3RavensMore

  • Hero Member
  • *****
  • Posts: 1153
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #1 on: April 01, 2015, 06:52:06 pm »


               

The GetLocation(OBJECT_SELF) that you used actually tries to get the location of the area, and not the WP.


 


If the WP tag you want to use is "angelaappearshere" then you need:


 


location angelaappearshere = GetLocation(GetObjectByTag("angelaappearshere"));


               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #2 on: April 01, 2015, 07:12:03 pm »


               

This is the on enter event so GetEnteringObject()  instead of GetPCSpeker().  Also you might want to check that it is a PC



object oPC = GetEnteringObject();
if (GetIsPC(oPC)) {
          <your spawning conditional here>
}

               
               

               
            

Legacy_an ominous cow herd

  • Newbie
  • *
  • Posts: 24
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #3 on: April 01, 2015, 11:10:15 pm »


               One other thing... You said you put the violet99 variable on the module, but you are trying to get the value from the PC. To get the value from the module you need to do this:

if((GetLocalInt(GetModule(), "violet99") == 3))

Edit to add: make sure you do the same when you set the value to 4 later on.
               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #4 on: April 02, 2015, 12:04:23 am »


               

That's what I call teamwork '<img'>



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #5 on: April 02, 2015, 06:20:12 am »


               

Tried out the advice offered by all of you. This time it worked beautifully!


 


Thanks so much for the help, fellas. You all ROCK'<img'>



               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #6 on: April 02, 2015, 05:46:58 pm »


               

Though I use similar scripted encounters, more so from the OnEnter of a trigger than from the area itself, I find it helps to use GetNearest functions when the spawn is within the area where the script is triggered.


 


Instead of:


 


location angelaappearshere = GetLocation(GetObjectByTag("angelaappearshere"));


 


I'd suggest:


 


location angelaappearshere = GetLocation(GetNearestObjectByTag("angelaappearshere"));


 


While it doesn't really affect the outcome of the script you are using here, alternate versions that might be used across multiple areas will definately benefit.


 


Examples would be the random encounter system I use on my own PW or some of the "challenge enhancer" scripts I use. By "challenge enhancer" I mean trigger based scripts that spawn extra foes for large parties or higher level PCs exploring someplace normally not a challenge to them or even closing an area off to exploration, i.e., I have a low level dungeon that if a PC that is way over the challenge of the area enters, a placeable wall will appear blocking their progression. When they depart, my area cleaners will eat any spawns as well as remove the wall to reset the dungeon for those in the proper level ranges. Anyhow, using "GetNearest" helps streamline later things you might create and allow you to use them in multiple areas and not end up with a list of thousand of unique tags to keep track of.



               
               

               
            

Legacy_LostChangeling

  • Newbie
  • *
  • Posts: 49
  • Karma: +0/-0
How do you spawn an NPC in an area when some condition is satisfied?
« Reply #7 on: April 03, 2015, 05:34:21 pm »


               

Not sure about the GetNearest function, but for all you know it might come in handy for something else I might like to attempt in future. Thanks for sharing this!  '<img'>