Skip to content

Added LookForEnemiesEx() for returning all enemies in an area.#2753

Merged
madame-rachelle merged 4 commits into
ZDoom:masterfrom
inkoalawetrust:lookforenemies-ex
Oct 14, 2024
Merged

Added LookForEnemiesEx() for returning all enemies in an area.#2753
madame-rachelle merged 4 commits into
ZDoom:masterfrom
inkoalawetrust:lookforenemies-ex

Conversation

@inkoalawetrust

Copy link
Copy Markdown
Contributor

This is a ZScript function that behaves more or less like LookForEnemies(), and optionally like LookForPlayers() too, and returns an array of pointers to every valid enemy it found in range (By passing an array by reference). Useful for custom look functions, such as for adding additional checks like a monster that only attacks flying enemies, or that can track multiple targets.

Below is an example mod with a test actor called EnemySearch, when spawned in, it will use the function to find every enemy in the area, print their name, and spawn a hovering plasma ball over their heads. When spawned as a friend with summonfriend, it will instead only do those two things with flying monsters.

LookForEnemiesEx.zip

This function allows for ZScript code to get an array with all enemies of the caller found in range. Using similar sight logic as functions like LookForEnemies().
This parameter allows the function to also find players around it.
@inkoalawetrust

Copy link
Copy Markdown
Contributor Author

Also added a X_WRITE_NIL VM abort in case someone passes a null array to the function.

Prevent crashes by passing a null array by reference.
@madame-rachelle madame-rachelle merged commit aff8b8c into ZDoom:master Oct 14, 2024
madame-rachelle pushed a commit that referenced this pull request Oct 14, 2024
* Compartmentalized the LookForEnemiesInBlock checks

* Added LookForEnemiesEx().

This function allows for ZScript code to get an array with all enemies of the caller found in range. Using similar sight logic as functions like LookForEnemies().

* Added noPlayers parameter to LookForEnemiesEx().

This parameter allows the function to also find players around it.

* Added VM abort to LookForEnemiesEx().

Prevent crashes by passing a null array by reference.
tiltshiftfocus pushed a commit to tiltshiftfocus/gzdoom that referenced this pull request Oct 21, 2024
…#2753)

* Compartmentalized the LookForEnemiesInBlock checks

* Added LookForEnemiesEx().

This function allows for ZScript code to get an array with all enemies of the caller found in range. Using similar sight logic as functions like LookForEnemies().

* Added noPlayers parameter to LookForEnemiesEx().

This parameter allows the function to also find players around it.

* Added VM abort to LookForEnemiesEx().

Prevent crashes by passing a null array by reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants