Aller au contenu

Photo

GetNearestWaypointByTag(...) ?


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
Greyjoy

Greyjoy
  • Members
  • 9 messages
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!

#2
Morbane

Morbane
  • Members
  • 1 883 messages
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 .


#3
Greyjoy

Greyjoy
  • Members
  • 9 messages
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;
}

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.");
}

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

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."

#6
Greyjoy

Greyjoy
  • Members
  • 9 messages
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.

#7
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

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).

#8
Greyjoy

Greyjoy
  • Members
  • 9 messages
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.

#9
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
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 .


#10
Greyjoy

Greyjoy
  • Members
  • 9 messages
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!