[CS:S] Forcing players fire weapon when they are secondaries

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 310
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[CS:S] Forcing players fire weapon when they are secondaries

Postby cssbestrpg » Mon Aug 21, 2023 5:36 pm

Hi, i have got an issue with OnPlayerRunCommand, when i try to force player fire his weapon secondary, but it only fires it once and doesn't work anymore. Its suppose to keep firing the weapon, but if i change code to fire only primaries it works fine without any issues, so do you have any clue why it won't work properly on secondarys?

Here is the code:

Syntax: Select all

from players.constants import PlayerButtons
from filters.weapons import WeaponClassIter
from listeners import OnPlayerRunCommand

secondaries = [weapon.name for weapon in WeaponClassIter(is_filters='pistol')]

@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
if player.dead:
return
if player.is_bot():
return

weapon = player.get_active_weapon()
if weapon is None:
return

classname = weapon.classname
if classname in secondaries:
user_cmd.buttons |= PlayerButtons.ATTACK
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Forcing players fire weapon when they are secondaries

Postby L'In20Cible » Tue Aug 22, 2023 4:50 am

It does not work because pistols are not automatic so the attack button must be released before it can shoot again.

Syntax: Select all

if user_cmd.buttons & PlayerButtons.ATTACK:
user_cmd.buttons &= ~PlayerButtons.ATTACK
else:
user_cmd.buttons |= PlayerButtons.ATTACK

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 3 guests