Block Player Buttons
Block Player Buttons
Hey Guys,
I can remember that I saw a post on this forums how to block player buttons with OnPlayerRunCmd but I couldnt find the thread again (Dunno, search function gives me nothing, or im just giving wrong keywords).
So im just asking again how can I block player buttons again.
Thanks
I can remember that I saw a post on this forums how to block player buttons with OnPlayerRunCmd but I couldnt find the thread again (Dunno, search function gives me nothing, or im just giving wrong keywords).
So im just asking again how can I block player buttons again.
Thanks
Re: Block Player Buttons
Syntax: Select all
from listeners import OnPlayerRunCommand
from players.constants import PlayerButtons
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
# Never allow ducking
user_cmd.buttons &= ~PlayerButtons.DUCK
Re: Block Player Buttons
Hello,
this is an old topic but i recently struggled while working with this.
Iam using
This is working but not perfectly.
The player is still be able to zoom for 1ms until my script blocks it and unzooms.
Is there a way to prehook that function to block it before it gets fired by the client?
Cheers,
CANi
Tags: noscope, block zooming, unscoped, attack2
this is an old topic but i recently struggled while working with this.
Iam using
Syntax: Select all
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
user_cmd.buttons &= ~PlayerButtons.ATTACK2
This is working but not perfectly.
The player is still be able to zoom for 1ms until my script blocks it and unzooms.
Is there a way to prehook that function to block it before it gets fired by the client?
Cheers,
CANi
Tags: noscope, block zooming, unscoped, attack2
Re: Block Player Buttons
Hey,
I can remember when checking players net properties, that theres m_flNextSecondaryAttack.
So you could literally replace the prevent buttons more to sending m_flNextSecondaryAttack + 0.1 secs which would lead to an endless loop of never being able to press button attack 2.
Maybe something like this?
I can remember when checking players net properties, that theres m_flNextSecondaryAttack.
So you could literally replace the prevent buttons more to sending m_flNextSecondaryAttack + 0.1 secs which would lead to an endless loop of never being able to press button attack 2.
Syntax: Select all
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
next_secondary_attack = player.get_property_float('m_flNextSecondaryAttack')
player.set_property_float('m_flNextSecondaryAttack', next_secondary_attack + 0.1)
Maybe something like this?
Re: Block Player Buttons
Hey decompile,
thanks for your answer.
Sadly the entity type player doesn't has the property 'm_flNextSecondaryAttack'.
I tried:
instead but this isn't working.
Cheers,
CANi
thanks for your answer.
Sadly the entity type player doesn't has the property 'm_flNextSecondaryAttack'.
I tried:
Syntax: Select all
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
next_secondary_attack = player.get_key_value_float('m_flNextSecondaryAttack')
player.set_key_value_float('m_flNextSecondaryAttack', next_secondary_attack + 0.1)
instead but this isn't working.
Cheers,
CANi
Re: Block Player Buttons
I'm not able to check it right now, but you can find the m_flNextSecondaryAttack via:
Syntax: Select all
for x in entity.properties:
print(x)
Re: Block Player Buttons
That property likely belongs to the weapon, not the player. Also, which game is this for? If the game is CS:S, CS:GO, or TF2 (and likely other games, as well), the full property name is LocalActiveWeaponData.m_flNextSecondaryAttack.
Re: Block Player Buttons
Here the fully working code for me: (CSGO)
I reworked the command. I thought theres a slightly better way & if you got bots on the server it was very CPU heavy.
Syntax: Select all
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
primaryWeapon = player.primary
if primaryWeapon is not None:
next_secondary_attack = primaryWeapon.get_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack')
if isinstance(next_secondary_attack, float):
primaryWeapon.set_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack', next_secondary_attack + 0.1)
I reworked the command. I thought theres a slightly better way & if you got bots on the server it was very CPU heavy.
Syntax: Select all
sniperWeapons = ['weapon_ssg08', 'weapon_sg556', 'weapon_aug', 'weapon_awp', 'weapon_g3sg1', 'weapon_scar20']
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
if player.playerinfo.is_dead():
return
if player.is_bot():
return
if player.get_active_weapon() is None:
return
if player.get_active_weapon().weapon_name in sniperWeapons:
next_secondary_attack = player.get_active_weapon().get_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack')
player.get_active_weapon().set_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack', next_secondary_attack + 0.1)
Re: Block Player Buttons
canibozz wrote:Here the fully working code for me: (CSGO)Syntax: Select all
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
primaryWeapon = player.primary
if primaryWeapon is not None:
next_secondary_attack = primaryWeapon.get_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack')
if isinstance(next_secondary_attack, float):
primaryWeapon.set_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack', next_secondary_attack + 0.1)
get_property_float() always returns a float. So, the isinstance check is redundant. I would also rather use the OnTick listener or something else that fires less often.
canibozz wrote:I reworked the command. I thought theres a slightly better way & if you got bots on the server it was very CPU heavy.Syntax: Select all
sniperWeapons = ['weapon_ssg08', 'weapon_sg556', 'weapon_aug', 'weapon_awp', 'weapon_g3sg1', 'weapon_scar20']
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
if player.playerinfo.is_dead():
return
if player.is_bot():
return
if player.get_active_weapon() is None:
return
if player.get_active_weapon().weapon_name in sniperWeapons:
next_secondary_attack = player.get_active_weapon().get_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack')
player.get_active_weapon().set_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack', next_secondary_attack + 0.1)
This could be improved a little bit more.
Syntax: Select all
sniperWeapons = [
'weapon_ssg08',
'weapon_sg556',
'weapon_aug',
'weapon_awp',
'weapon_g3sg1',
'weapon_scar20']
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
if player.is_dead():
return
if player.is_bot():
return
weapon = player.get_active_weapon() # Or just player.active_weapon
if weapon is None:
return
if weapon.weapon_name not in sniperWeapons:
return
next_secondary_attack = weapon.get_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack')
weapon.set_property_float('LocalActiveWeaponData.m_flNextSecondaryAttack', next_secondary_attack + 0.1)
Re: Block Player Buttons
Also, I just realized that we store that property in our entity data already:
https://github.com/Source-Python-Dev-Te ... pon.ini#L9
https://github.com/Source-Python-Dev-Te ... pon.ini#L9
Re: Block Player Buttons
Ayuto wrote:This could be improved a little bit more.
satoon101 wrote:Also, I just realized that we store that property in our entity data already:
https://github.com/Source-Python-Dev-Te ... pon.ini#L9
Improved it further:
Syntax: Select all
zoomWeaponsArr = ['weapon_ssg08', 'weapon_sg556', 'weapon_aug', 'weapon_awp', 'weapon_g3sg1', 'weapon_scar20']
@OnPlayerRunCommand
def on_player_run_command(player, user_cmd):
if player.playerinfo.is_dead():
return
if player.is_bot():
return
weapon = player.active_weapon
if weapon is None:
return
if weapon.weapon_name not in zoomWeaponsArr:
return
weapon.next_secondary_fire_attack = weapon.next_secondary_fire_attack + 0.1
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 73 guests