Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CustomSpawnRequest2 with arbitrary user data inserted into NpcData #306

Merged

Conversation

ryo0ka
Copy link
Contributor

@ryo0ka ryo0ka commented Jan 30, 2025

Changes

Added a new parameter string context to MESApi.CustomSpawnRequest(), which is inserted into NpcData.Context of spawned NPC grids.

Background

I wasn't able to reliably track each spawn request's corresponding grid when I spawn a single spawn group multiple times simultaneously in close proximity. I guess that kind of usage wasn't expected. This PR would allow me to retrieve an identifier of each spawn request upon a callback of RegisterSuccessfulSpawnAction() or a modded block's init function.

For an added value, the string data can carry around XML which may be useful to pass arbitrary data to grids.

Implementation notes

For backward compatibility, I didn't get to change the signature of CustomSpawnRequest() but added an override, with a single parameter args, which is of new type CustomSpawnRequestArgs. Internally, API will pass around a string -> object dictionary that is converted to/from this class.

This approach also allows you to safely add other parameters to the function in future updates.

Tests conducted prior to PR

  • ran new CustomSpawnRequest() with context data and confirmed working as expected.
  • ran the original CustomSpawnRequest() and confirmed that the behavior hasn't changed.
  • ran general MES spawner via /MES.SSCS and natural spawns and confirmed the behavior hasn't changed.

@CptArthur CptArthur merged commit 25902d3 into MeridiusIX:master Feb 1, 2025
@ryo0ka ryo0ka deleted the feat/custom-spawn-request-context branch February 2, 2025 21:40
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