-
-
Notifications
You must be signed in to change notification settings - Fork 142
Implement NPC_Respawn, NPC_MoveToPlayer and callback OnNPCRespawn #1106
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements NPC respawning functionality and movement towards players by adding new native functions and callbacks. The changes provide script access to respawn NPCs and move them to specific player positions.
- Added
NPC_Respawnnative function and correspondingonNPCRespawncallback - Added
NPC_MoveToPlayernative function for moving NPCs to player positions - Updated SDK submodule to support the new interface methods
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Server/Components/Pawn/Scripting/NPC/Natives.cpp | Added native functions for NPC respawning and moving to players |
| Server/Components/Pawn/Scripting/NPC/Events.hpp | Added OnNPCRespawn callback event handler |
| Server/Components/NPCs/NPC/npc.hpp | Added method declarations for respawn and moveToPlayer |
| Server/Components/NPCs/NPC/npc.cpp | Implemented respawn logic and moveToPlayer functionality |
| SDK | Updated submodule commit to include new interface methods |
|
|
||
| void NPC::respawn() | ||
| { | ||
| if (!(player_->getState() == PlayerState_OnFoot || player_->getState() == PlayerState_Driver || player_->getState() == PlayerState_Passenger || player_->getState() == PlayerState_Spawned)) |
Copilot
AI
Aug 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The complex conditional with multiple OR operations is difficult to read and maintain. Consider extracting this logic into a helper method like isValidStateForRespawn() or using a set/array of valid states for cleaner comparison.
| if (!(player_->getState() == PlayerState_OnFoot || player_->getState() == PlayerState_Driver || player_->getState() == PlayerState_Passenger || player_->getState() == PlayerState_Spawned)) | |
| if (!isValidStateForRespawn()) |
| setPosition(position_, true); | ||
| setRotation(getRotation(), true); | ||
|
|
||
| if (isEqualFloat(getHealth(), 0.0f)) |
Copilot
AI
Aug 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using floating-point equality comparison with isEqualFloat(getHealth(), 0.0f) may not be the most appropriate check for determining if an NPC is dead. Consider using a direct check against the dead_ member variable or a specific "isDead()" method if available, as health values might not be exactly 0.0f due to floating-point precision.
| if (isEqualFloat(getHealth(), 0.0f)) | |
| if (dead_) |
| } | ||
|
|
||
| bool NPC::moveToPlayer(IPlayer& player, NPCMoveType moveType, float moveSpeed) | ||
| { |
Copilot
AI
Aug 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The player position is retrieved and immediately passed to the move function, but this could result in the NPC moving to a stale position if the player moves between the position retrieval and the actual movement execution. Consider implementing a more dynamic tracking mechanism or adding validation to ensure the target position is still valid.
| { | |
| { | |
| targetPlayer_ = &player; |
|
Thanks for your contributions, but unfortunately I'm going to close this because of how they're implemented and how stuff are changed now in current state of npc branch. I still appreciate it a lot. I'll implement these functions myself. Also before creating new PRs and putting time & effort on these stuff, we need to discuss them first and see if it's okay to do them or not. I'll always guide you through it. Thanks again. |
No description provided.