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

added new hook, handler and dispatcher for any damage events happening #120

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mgaertne
Copy link
Contributor

I hooked into G_Damage and forwarded that towards python, so that python plugins now can self.add_hook("damage", self.handle_damage) in its own function. The plugin function gets

  • target player (the player receiving the damage)
  • attacker (optional player, that caused the damage, might be None for environmental damage inflicted)
  • damage (amount of damage the target might receive)
  • dflags (bitfield of damage flags, i.e. DAMAGE_NO_PROTECTION or DAMAGE_NO_TEAM_PROTECTION)
  • mod (means of death, indicating where this damage might be coming from)

The events can't be stopped, and are delivered regardless of whether the target actually gets health/armor reduced, i.e. from rocket jumps with DAMAGE_NO_PROTECTION not set, or team damage in the DAMAGE_NO_TEAM_PROTECTION case. You can detect harmful team shots by this. Plugins would need to filter the events they are interested in on their own.

mgaertne added 9 commits May 25, 2023 19:23
better filter potential players by the entity_id in range(0, 64) (MAX_PLAYERS = 64 in ql source). Otherwise you will get dmg events from stuff like crushers, lava, trigger_hurt trying to be converted into a player that obviously does not exist.
Copy link
Collaborator

@em92 em92 left a comment

Choose a reason for hiding this comment

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

Hi, Markus!
Please also take a look to this #124
That issue is the main reason, why I don't want to merge this PR.

hooks.c Outdated
return;
}

target_id = target->client->ps.clientNum;
Copy link
Collaborator

Choose a reason for hiding this comment

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

if target->client is spectating, ps.clientNum is the player who is being spectated.

hooks.c Outdated
target_id = target->client->ps.clientNum;

if (attacker && attacker->client) {
attacker_id = attacker->client->ps.clientNum;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here

Comment on lines 436 to 437
target_player = minqlx.Player(target_id) if target_id in range(0, 64) else None
inflictor_player = minqlx.Player(attacker_id) if attacker_id is not None and attacker_id in range(0, 64) else None
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no need check validity of target_id and attacker_id. My_G_Damage is expected to pass valid ids

python_embed.c Outdated
Comment on lines 124 to 127
{"is_chatting", "Whether the player is currently chatting."},
{"is_frozen", "Whether the player is frozen(freezetag)."},
{NULL}
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is from other PR

python_embed.c Outdated
Comment on lines 765 to 766
PyStructSequence_SetItem(state, 12, PyBool_FromLong(g_entities[client_id].client->ps.eFlags & EF_TALK != 0));
PyStructSequence_SetItem(state, 13, PyBool_FromLong(g_entities[client_id].client->ps.pm_type == 4));
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is from other PR

python_embed.c Outdated
Comment on lines 1508 to 1513
#if PY_VERSION_HEX < ((3 << 24) | (7 << 16))
char *entity_classname = NULL, *item_classname = NULL;
#else
const char *entity_classname = NULL, *item_classname = NULL;
#endif
gentity_t* ent;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is already merged

python_embed.c Outdated
Comment on lines 1934 to 1936
#if PY_VERSION_HEX < ((3 << 24) | (7 << 16))
PyEval_InitThreads();
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is already merged

@em92 em92 marked this pull request as draft August 13, 2023 05:56
@mgaertne mgaertne marked this pull request as ready for review August 13, 2023 19:37
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