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

Add onExplosion event #3130

Merged
merged 1 commit into from
Jul 29, 2023

Conversation

botder
Copy link
Member

@botder botder commented Jul 25, 2023

This pull request adds the onExplosion event to the server-side and it can be cancelled. The event callback receives the absolute coordinates of the explosion, the explosion type, and the explosion origin (like a vehicle), if there is one.

I haven't tested this event in a two-or-more player scenario yet, but it worked locally for me.

@botder botder added the enhancement New feature or request label Jul 25, 2023
Comment on lines +2729 to 2733
for (auto iter = m_pPlayerManager->IterBegin(); iter != m_pPlayerManager->IterEnd(); ++iter)
{
CPlayer* player = *iter;

CVector cameraPosition;
player->GetCamera()->GetPosition(cameraPosition);

// Is this players camera close enough to send?
if (IsPointNearPoint3D(explosionPosition, cameraPosition, MAX_EXPLOSION_SYNC_DISTANCE))
{
sendList.push_back(player);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest extract method here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that logic reused somewhere?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability and self-documenting.

@sbx320
Copy link
Member

sbx320 commented Jul 29, 2023

Wouldn't this cause a desync for the player causing the explosion if cancelled (since it will have already happened on the source client)?

@botder
Copy link
Member Author

botder commented Jul 29, 2023

Wouldn't this cause a desync for the player causing the explosion if cancelled (since it will have already happened on the source client)?

The client waits for the server packet to actually create the explosion.

@sbx320 sbx320 force-pushed the feature/on-explosion-event branch from 2c33c27 to f6f63d0 Compare July 29, 2023 11:14
@sbx320 sbx320 merged commit 9edffc4 into multitheftauto:master Jul 29, 2023
6 checks passed
@botder
Copy link
Member Author

botder commented Jul 29, 2023

Well, this was too quick, I wanted to add the event to createExplosion function on serverside. I forgot to mention this.

@botder botder added this to the 1.6.1 milestone Jul 29, 2023
@botder
Copy link
Member Author

botder commented Jul 29, 2023

Also, the origin element was not done right: it uses the closest player to an explosion, which is not the expected value in this event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants