Skip to content

Pass index instead Player object in the listeners #284

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ Called when the button state of a player changed.
from listeners import OnButtonStateChanged

@OnButtonStateChanged
def on_button_state_changed(player, old_buttons, new_buttons):
def on_button_state_changed(index, old_buttons, new_buttons):
pass

.. seealso::
Expand All @@ -358,7 +358,7 @@ Called when a player runs a command.
from listeners import OnPlayerRunCommand

@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
def on_player_run_command(index, user_cmd):
pass


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,11 @@ def get_button_combination_status(old_buttons, new_buttons, combination):
.. code:: python

@OnButtonStateChanged
def on_buttons_state_changed(player, old_buttons, new_buttons):
def on_buttons_state_changed(index, old_buttons, new_buttons):
status = get_button_combination_status(old_buttons, new_buttons,
PlayerButtons.ATTACK|PlayerButtons.JUMP)

player = Player(index)

if status == ButtonStatus.PRESSED:
SayText2(
'{} is jumping and attacking.'.format(player.name)).send()
Expand Down
6 changes: 2 additions & 4 deletions src/core/sp_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ bool PrePlayerRunCommand(HookType_t hook_type, CHook* pHook)
if (!run_command_manager->GetCount() && !button_state_manager->GetCount())
return false;

static object Player = import("players.entity").attr("Player");

CBaseEntity* pEntity = pHook->GetArgument<CBaseEntity*>(0);
unsigned int index;
Expand All @@ -190,8 +189,7 @@ bool PrePlayerRunCommand(HookType_t hook_type, CHook* pHook)
CUserCmd* pCmd = pHook->GetArgument<CUserCmd*>(1);
#endif

object player = Player(index);
CALL_LISTENERS(OnPlayerRunCommand, player, ptr(pCmd));
CALL_LISTENERS(OnPlayerRunCommand, index, ptr(pCmd));

if (button_state_manager->GetCount())
{
Expand All @@ -201,7 +199,7 @@ bool PrePlayerRunCommand(HookType_t hook_type, CHook* pHook)
int buttons = pWrapper->GetDatamapPropertyByOffset<int>(offset);
if (buttons != pCmd->buttons)
{
CALL_LISTENERS(OnButtonStateChanged, player, buttons, pCmd->buttons);
CALL_LISTENERS(OnButtonStateChanged, index, buttons, pCmd->buttons);
}
}

Expand Down