Hello.
I'm looking for a way to "scan" for nearby enemies in ZScript.
What I mean is that I want to get all monsters within a certain radius and return pointers to them, so I can check their classes and states.
My current idea is to use LineTrace, but it will have troubles with height differences. (Scanning on stairs and such)
I was also looking in the GZDoom's ZScript files, to see how CheckRange did it, but I haven't been able to find anything aside a native function.
I'm still new to ZScript, so I wanted to ask here in case anyone knows how to do it.
Thank you.
While I am here, I wanted to ask something about LineTrace.
Is using many LineTraces going to impact performance a lot?
I haven't noticed anything yet, unlike when I was originally using LineAttack for checks, which spawned a lot of puffs.
Scan for nearby enemies in ZScript
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Re: Scan for nearby enemies in ZScript
Use a BlockThingsIterator.
Code: Select all
double maxDistance = 512;
for (let i = BlockThingsIterator.Create(self, maxDistance); i.Next();)
{
Actor other = i.thing;
if (other == self)
{
continue;
}
double distance = Distance3D(other);
if(distance > maxDistance)
{
continue;
}
if(other.bISMONSTER == false)
{
continue;
}
console.printf(String.Format("%s (%f)",other.GetClassName(),distance));
}
Last edited by Cherno on Mon Jun 29, 2020 11:35 am, edited 2 times in total.
Re: Scan for nearby enemies in ZScript
Thank you Cherno!
This seems to be working how I wanted!
This seems to be working how I wanted!
Re: Scan for nearby enemies in ZScript
Note that you have to include the distance check, since the BlockThingsIterator's radius parameter is only used to get the blockmaps blocks to check within that radius; Actor that are farther away than this radius will also be found, so they need to be weeded out with a seperate check versus the actual distance between the calling actor (player, in this case) and the found actor.