Author Topic: on enter check  (Read 304 times)

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
on enter check
« on: April 26, 2013, 07:00:30 pm »


                I’m looking for help is there any to check on an on enter
event to see if a creature has spawned already and if so don’t run the script that
spawns the creature until killed. I hope that makes sense. Any help on this
would be wonderful
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
on enter check
« Reply #1 on: April 26, 2013, 08:01:52 pm »


               if( GetObjectbytag("unique tag of creature",0) != OBJECT_INVALID) return;

...
               
               

               
            

Legacy_Surek

  • Full Member
  • ***
  • Posts: 169
  • Karma: +0/-0
on enter check
« Reply #2 on: April 26, 2013, 10:50:36 pm »


               thank you for your help but now i'm getting an error
that says invalid declaration type.
I'm lost i don't know what i'm doing but if anyone can help me out many thanks

void main()
{
object A;
object B;
object oPC=GetEnteringObject();
if (!GetIsPC(oPC)) return;
}
if( GetObjectbytag("morella",0) != OBJECT_INVALID) return;   ERROR occurs here
int nRand= Random(2);
nRand++;
switch (nRand)
{
case 1: A = GetWaypointByTag("morella_01");
       B = CreateObject(OBJECT_TYPE_CREATURE,"morella",GetLocation(A));
break;

case 2: A = GetWaypointByTag("morella_02");
       B = CreateObject(OBJECT_TYPE_CREATURE,"morella",GetLocation(A));
break;

case 3:
break;

case 4: //What happens on 4
break;

case 5: //What happens on 5
break;
}
}
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
on enter check
« Reply #3 on: April 26, 2013, 11:52:49 pm »


               You have extra brackets in there. I recoded it to be simpler and cleaner.


void main() {

    object oWay, oPC=GetEnteringObject();

    if (!GetIsPC(oPC))
        return;

    if( GetObjectbytag("morella",0) != OBJECT_INVALID)
        return;


    switch (Random(2)) {
    case 0:
        oWay = GetWaypointByTag("morella_01");
        CreateObject(OBJECT_TYPE_CREATURE,"morella",GetLocation(oWay));
    break;

    case 1:
        oWay = GetWaypointByTag("morella_02");
        CreateObject(OBJECT_TYPE_CREATURE,"morella",GetLocation(oWay));
    break;
    }
}

My inclination is to get rid of oWay altogether and just stick the GetWaypoint in the GetLocation, but I want to make sure you understand what's going on here. A few notes:

Random(X) returns a number between 0 (zero) and X-1. In this case, 0 or 1. Random(5) would be 0-4, Random(30) would be 0-29. Get used to beginning a count with zero, as this is VERY commonly done in coding.

CreateObject doesn't need a B = in front of it. You can declare an object for it if you're going to do something else to that object, but this code isn't doing that, so it's useless clutter.

Please feel free to ask any questions you might have - learning to code can be frustrating, but it can also be immensely fun and rewarding.

Funky
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
on enter check
« Reply #4 on: April 26, 2013, 11:57:54 pm »


               Here's an even shorter version of that same script, for giggles. I also changed your object validity check to a better method, though I'm not going to dwell on the details.


void main() {
    if (!GetIsPC(GetEnteringObject()))
        return;

    if (GetIsObjectValid(GetObjectbytag("morella",0)))
        return;

    CreateObject(OBJECT_TYPE_CREATURE,"morella",GetLocation(GetWaypointByTag("morella_0"+IntToString(d2()))));
}

[Edit] The create line overflowed the post window - sigh @ Bioboards. Make sure to get it all the way to the semicolon if you copy/paste it.

Funky
               
               

               


                     Modifié par FunkySwerve, 26 avril 2013 - 11:00 .