Block Player Buttons

Please post any questions about developing your plugin here. Please use the search function before posting!
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Block Player Buttons

Postby decompile » Sat Sep 24, 2016 1:48 pm

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
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Block Player Buttons

Postby Ayuto » Sat Sep 24, 2016 2:48 pm

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
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Block Player Buttons

Postby canibozz » Wed Apr 11, 2018 8:51 am

Hello,

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
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Block Player Buttons

Postby decompile » Wed Apr 11, 2018 9:13 am

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.

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?
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Block Player Buttons

Postby canibozz » Wed Apr 11, 2018 10:04 am

Hey decompile,

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
decompile
Senior Member
Posts: 416
Joined: Sat Oct 10, 2015 10:37 am
Location: Germany
Contact:

Re: Block Player Buttons

Postby decompile » Wed Apr 11, 2018 10:39 am

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)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Block Player Buttons

Postby satoon101 » Wed Apr 11, 2018 11:06 am

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.
Image
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Block Player Buttons

Postby canibozz » Wed Apr 11, 2018 11:11 am

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)


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)
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Block Player Buttons

Postby Ayuto » Wed Apr 11, 2018 4:50 pm

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)
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Block Player Buttons

Postby satoon101 » Wed Apr 11, 2018 5:15 pm

Also, I just realized that we store that property in our entity data already:
https://github.com/Source-Python-Dev-Te ... pon.ini#L9
Image
canibozz
Member
Posts: 32
Joined: Wed Apr 11, 2018 7:55 am

Re: Block Player Buttons

Postby canibozz » Thu Apr 12, 2018 9:55 am

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 31 guests