Page 1 of 1

A way to trigger +attack player command

Posted: Thu Aug 12, 2021 9:52 am
by khaimovmr
Hi, guys... struggling with a player grenade throw triggering on the server side.
Do somebody know is there a way to trigger the attack with player's active weapon?

Re: A way to trigger +attack player command

Posted: Thu Aug 12, 2021 10:06 am
by L'In20Cible

Syntax: Select all

def force_buttons(player, buttons, time=0.25):
"""Forces the given buttons on the given player for the given time."""
# Save the current forced buttons
forced_buttons = player.get_datamap_property_int('m_afButtonForced')

# Apply the given buttons
player.set_datamap_property_int('m_afButtonForced', forced_buttons|buttons)

# Restore the original buttons after the given time
player.delay(
time,
player.set_datamap_property_int,
('m_afButtonForced', forced_buttons)
)

from players.entity import Player
from players.constants import PlayerButtons

player = Player(1)
force_buttons(player, PlayerButtons.ATTACK)

Re: A way to trigger +attack player command

Posted: Thu Aug 12, 2021 11:02 am
by Ayuto
If that works, we should add that to the Player class. That's really cool!

Re: A way to trigger +attack player command

Posted: Thu Aug 12, 2021 11:40 pm
by L'In20Cible
Ayuto wrote:If that works, we should add that to the Player class. That's really cool!

Not sure if it work on all games, but it works on CS:S. Though, while it work for forcing a single attack, it will cause issues if the given time is greater than the next attack. Many buttons cannot be forced as well, such as movements, and others cause replication issues because that property isn't networked and only forced server-side causing a lot of flickering and whatnot due to client prediction.