Author Topic: spawn on enter  (Read 288 times)

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
spawn on enter
« on: June 07, 2013, 07:21:00 pm »


                I was hoping I could get some help with this script.

Basically what it’s supposed to do is spawn a creature on
enter but also check to see if its already spawned if it is don’t spawn again. But
for whatever reason it does not work but complies just fine. When I enter their is nothing spawned

 

void main()

{

 object
A,oPC=GetEnteringObject();

 

    if (!GetIsPC(oPC))

        return;

 

 

    if
(GetIsObjectValid(GetObjectByTag("bandit")))

        return;

 

   
CreateObject(OBJECT_TYPE_CREATURE,"bandit",GetLocation(GetWaypointByTag("SP_001")));

 

 

    if
(GetIsObjectValid(GetObjectByTag("corruptguard")))

        return;

 

   
CreateObject(OBJECT_TYPE_CREATURE,"corruptguard",GetLocation(GetWaypointByTag("SP_002")));

 

 

 

 

}
               
               

               
            

Legacy_The Amethyst Dragon

  • Hero Member
  • *****
  • Posts: 2981
  • Karma: +0/-0
spawn on enter
« Reply #1 on: June 07, 2013, 08:51:41 pm »


               This should work for you, as long as the creature tags and blueprint resrefs match up to what's in the script.  If "bandit" and "corruptguard" are not the blueprint resref of the creatures, they won't spawn in.


// Checks for 1st creature (bandit) in same area as PC, if not present, spawn one in.
// Checks for 2nd creature (corrupt guard) in same area as PC, if not present, spawn one in.

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

if (!GetIsPC(oPC)) { return; }   // Do nothing if not a PC entering trigger/area

object oArea = GetArea(oPC);

object oCreature1 = GetNearestObjectByTag("bandit", oPC);
if (GetIsObjectValid(oCreature1) == TRUE && GetArea(oCreature1) == oArea) { } // do nothing
else
   {
   object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "bandit", GetLocation(GetNearestObjectByTag("SP_001")));
   }

object oCreature2 = GetNearestObjectByTag("corruptguard", oPC);
if (GetIsObjectValid(oCreature2) == TRUE && GetArea(oCreature2) == oArea) { } // do nothing
else
   {
   object oSpawns = CreateObject(OBJECT_TYPE_CREATURE, "corruptguard", GetLocation(GetNearestObjectByTag("SP_002")));
   }
}

Your previous code was checking the entire module for an object tagged "bandit", and if one was found anywhere, it stopped the script from doing anything else.

It then did the same thing when checking for a "corruptguard".

Also, sometimes scripts work better if the object that is being spawned is defined in the script, rather than just running the CreateObject.

I also changed the search for a waypoint to a nearest object, to better have a chance for spawning in the right place if you happen to have the same waypoint tag elsewhere in the module.
               
               

               


                     Modifié par The Amethyst Dragon, 07 juin 2013 - 07:57 .
                     
                  


            

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
spawn on enter
« Reply #2 on: June 07, 2013, 10:13:10 pm »


               I appreciate you help but still having a problem now every time I enter the area it spawns a new creature. It’s like the check is not working I have no idea how to fix this.
               
               

               
            

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
spawn on enter
« Reply #3 on: June 07, 2013, 10:20:26 pm »


               Never mind stupid me, just checked to make sure tags were the same. That was the problem. Thanks for all your help.