Getting visible things, setting targets - ZScript monster AI

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

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!)
Post Reply
matimba
Posts: 1
Joined: Fri Oct 11, 2024 5:14 am

Getting visible things, setting targets - ZScript monster AI

Post by matimba »

Hello all,

I recently extracted my self-made doom levels from the 90s and got them to run with the help of Slade. So I started to create new levels - but this time, I would like to enhance the monsters AI with ZScript, something that wasn't possible back in the days. I managed to add a zscript with a new zombieman with increased speed and read a lot about zscript, DECORATE and ACS. But I still can't tell if what I want to do is even within the scope of ZScript, so here comes my question.

What I want to do: I would like to create a monster that has other monsters as default (and only) target. For example, a zombieman that will attack an imp as soon as he sees him. Ideally I would like the monster AI to be able to choose if there are multiple enemies.
So far I managed to add a different target to my enhanced zombieman via self.target=<Actor>, but that would only be a specific actor that I would need to identify first.
So is there something similar to LookForMonsters(), but instead of returning a bool, it returns an array of all visible things a monster can see, so that I can process it in zscript and make a decision which thing should be set as new target?

As mentioned above, I read the wiki and this forum up and down and could not find anything in that direction - is it possible?
Thanks for any help!
User avatar
inkoalawetrust
Posts: 88
Joined: Mon Aug 26, 2019 9:18 pm
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Getting visible things, setting targets - ZScript monster AI

Post by inkoalawetrust »

What the actual fuck? What kinda fucking coincidence is this? You asked for a function like LookForEnemies() that returns an array of all valid enemies 3 days after I wrote a function that does exactly that, and then 3 days after THAT, it was merged to GZDoom.

Uh, anyway, yes, you happened to ask that question just as I added a function to GZDoom that does exactly that. You just need to pass an array into it by reference, like this:

Code: Select all

Array <Actor> Enemies;
If (LookForEnemiesEx(Enemies,-1,False,True,Null))
{
	for (int i = 0; i < enemies.Size(); i++)
	{
		Let Enemy = enemies[i];
		//My epic checks
	}
}
Then you just iterate over the array, you SHOULD also be able to use ForEach(), but when I tried it, it didn't work. Keep in mind that it's only in GZDoom devbuilds for the time being though.


As for making a zombieman attack an Imp as soon as he sees him, that depends on what you're asking, if the Zombieman is hostile and you want him to attack a friendly Imp immediately, there's a +SEEFRIENDLYMONSTERS flag that I made a PR for like a year or two ago.
Post Reply

Return to “Scripting”