Author Topic: GetNearestWaypointByTag(...) ?  (Read 358 times)

Legacy_Greyjoy

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« on: August 03, 2011, 09:38:09 am »


               Hello

I'm working on a siege/defend system which works pretty well but I am having issues when using it around different areas.  See, the scripts take two waypoints into account, "Attackers" and "Defenders" (their tags).  But when using waypoints with the same tags across the module the scripts seems to take the latest created waypoints not the ones in the current active fighting area.  Thus I get some strange behavior when NPCs are spawning in some other area than the one I intended.

I tried to use GetNearestObjectByTag(...), thought it would work on Waypoints since both functions (GetWaypointByTag(...)) return an object, ie in my case a Waypoint. 

How can I solve this issue?  Do I need to have a unique tag on my Waypoints (which I prefer not to have) or can I somehow grab the Waypoints with the given tags that are currently in the active area?

Thanks in advance!
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #1 on: August 03, 2011, 10:04:49 am »


               GetFirstObjectInArea()
or just
GetArea()

might be what you are looking for/example script from the lexicon:

void main()

{

     // Loop all objects in us, an area

     object oArea = OBJECT_SELF;

     object oObject = GetFirstObjectInArea(oArea);

     while(GetIsObjectValid(oObject))

     {
          // Destroy any objects tagged "DESTROY"
          if(GetTag(oObject) == "DESTROY")

          {

                DestroyObject(oObject);

          }

         oObject = GetNextObjectInArea(oArea);

     }

}
               
               

               


                     Modifié par Morbane, 03 août 2011 - 09:08 .
                     
                  


            

Legacy_Greyjoy

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #2 on: August 03, 2011, 10:19:56 am »


               Yep, I solved it by working with that function slightly modified.  Here it is:


object GetObjectByTagInArea(string sTag = "Attackers", object oArea = OBJECT_SELF)
{
    object oObject = GetFirstObjectInArea(oArea);

    while (GetIsObjectValid(oObject))
    {
        if ( GetTag(oObject) == sTag )
        {
            return oObject;
        }

        oObject = GetNextObjectInArea();
    }

    return OBJECT_INVALID;
}
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #3 on: August 03, 2011, 10:33:29 am »


               Actually GetNearestObjectByTag does work with Waypoints. And it is a more efficient function. Just tested it.

This was my test script just in case you were wondering. Stuck it in the OnUsed event of an object:

void main()
{
    object oPC = GetLastUsedBy();
    object oWP = GetNearestObjectByTag("TEST_WP", OBJECT_SELF, 1);
    if (GetIsObjectValid(oWP))
    SendMessageToPC(oPC, "Test waypoint found.");
}
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #4 on: August 03, 2011, 11:25:46 am »


               

GhostOfGod wrote...

Actually GetNearestObjectByTag does work with Waypoints. And it is a more efficient function. Just tested it.


Yup it sure does. That function will get any object, pretty much if you can paint it down in an area then it is an "object."
               
               

               
            

Legacy_Greyjoy

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #5 on: August 03, 2011, 01:53:23 pm »


               Hells, I tried that but it didn't work for me.  Maybe I missed to rebuild the module.  It would really help a lot.  I'll give it a go.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #6 on: August 03, 2011, 11:27:42 pm »


               

Greyjoy wrote...

Hells, I tried that but it didn't work for me. Maybe I missed to rebuild the module. It would really help a lot. I'll give it a go.


Not sure if this is the way you tried to do it (I'm taking this inference from the function you posted) but you need to have a reference point for something to be closest to (some point of origin). That point can not be the area itself - or the module for that matter. Typically you can just use the PC as the origin point and get the closest waypoint to them. If you only have a single WP of the tag it will get the one in the same area as the PC (so this way you can reuse the same waypoint tag in different areas).
               
               

               
            

Legacy_Greyjoy

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #7 on: August 04, 2011, 01:34:15 pm »


               Yeah, I had the second parameter of the GetNearestObjectByTag(...) function blank, ie OBJECT_SELF which, in a sense I call it, could return OBJECT_INVALID.  I'll look into it.
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #8 on: August 04, 2011, 02:01:07 pm »


               OBJECT_SELF is never invalid...ever. It always refers to the object whose event the script is running on behalf of. For example, if you put a script in a module event, it refers to the module when that script runs. Put it on an area event and OBJECT_SELF is the area. Whatever object you put the script in, that's what OBJECT_SELF will refer to in that script when it runs. But it could be referring to something that has no valid location like an area or the module. Therefore you cannot determine what is closest to it since it has no location, and the GetNearest function fails. This is true of all GetNearest functions. You have to use a reference object that has a valid location to test distances against. Also, since it is impossible to test how far things are from each other when they exist in different areas, all GetNearest functions always look only at objects that are in the same area as the reference object passed into the function.
               
               

               


                     Modifié par Axe_Murderer, 04 août 2011 - 01:05 .
                     
                  


            

Legacy_Greyjoy

  • Newbie
  • *
  • Posts: 18
  • Karma: +0/-0
GetNearestWaypointByTag(...) ?
« Reply #9 on: August 05, 2011, 12:49:48 pm »


               Thank you Axe_Murderer that clears up a lot.  I was using the area in question since the area is handling the scripts when the PC enters.  I used the PC as reference instead and it works!