[CS:S] Scope Detecting

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

[CS:S] Scope Detecting

Postby cssbestrpg » Fri Apr 26, 2024 8:30 pm

hi, i am trying to detect if player scoped weapon, but it gives an error

Syntax: Select all

from filters.players import PlayerIter
from listeners.tick import Repeat

def load():
laser_aiming.start(1)

def unload():
laser_aiming.stop()

alive_players = PlayerIter(['alive', 'human'])

@Repeat
def laser_aiming():
for player in alive_players:
weapon = player.get_active_weapon()
if weapon is None:
return
classname = weapon.classname.split('_')[1]
if classname not in ['awp','scout']:
continue
scoped = player.get_property_bool('m_bIsScoped')
if scoped == True:
continue


Code: Select all

[2024-04-26 23:27:31]:
[Source.Python]
[2024-04-26 23:27:31]:
[SP] Caught an Exception:
[2024-04-26 23:27:31]: Traceback (most recent call last):
[2024-04-26 23:27:31]: File "../addons/source-python/packages/source-python/listeners/tick.py", line 79, in _tick
[2024-04-26 23:27:31]: self.pop(0).execute()
[2024-04-26 23:27:31]: File "../addons/source-python/packages/source-python/listeners/tick.py", line 160, in execute
[2024-04-26 23:27:31]: return self.callback(*self.args, **self.kwargs)
[2024-04-26 23:27:31]: File "../addons/source-python/packages/source-python/listeners/tick.py", line 607, in _execute
[2024-04-26 23:27:31]: self.callback(*self.args, **self.kwargs)
[2024-04-26 23:27:31]: File "../addons/source-python/plugins/crosshair/crosshair.py", line 21, in laser_aiming
[2024-04-26 23:27:31]: scoped = player.get_property_bool('m_bIsScoped')
[2024-04-26 23:27:31]: ValueError: Unable to find property 'm_bIsScoped'.
Lyam
Junior Member
Posts: 1
Joined: Thu May 30, 2024 4:52 am

Re: [CS:S] Scope Detecting

Postby Lyam » Thu May 30, 2024 5:02 am

Hello,

First, make sure that all your dependencies are correctly loaded and that your variables are well defined. A little tip: check that alive_players is always up to date in each tick, otherwise you risk having obsolete reference problems.
cssbestrpg
Senior Member
Posts: 290
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [CS:S] Scope Detecting

Postby cssbestrpg » Thu May 30, 2024 11:27 am

Hello, that alive_players i defined always loop alive human players, it always loop there alive human players only
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

Re: [CS:S] Scope Detecting

Postby satoon101 » Thu May 30, 2024 10:42 pm

Are you sure m_bIsScoped exists?

CS:S Datamaps
CS:S Server Classes

* Edit: looks like it exists for CS:GO:

CS:GO Server Classes

But it doesn't exist in CS:S, so you'll have to find another way.
Image
User avatar
Kami
Global Moderator
Posts: 264
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Scope Detecting

Postby Kami » Sun Jun 02, 2024 5:57 pm

For CS:S you could try and check the FOV (m_iFOV) on the player, as that changes depending on scope level.
cssbestrpg
Senior Member
Posts: 290
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

Re: [CS:S] Scope Detecting

Postby cssbestrpg » Sun Jun 02, 2024 6:21 pm

I was actually thinking using weapon_zoom event for it, using a custom player class to check pressed scope status and use weapon_switch hook for reset scope status, i haven't touch this code a while due to being busy on working other stuff, but thanks for replies:)
User avatar
L'In20Cible
Project Leader
Posts: 1534
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Scope Detecting

Postby L'In20Cible » Sun Jun 02, 2024 9:03 pm

Syntax: Select all

from enum import IntEnum
from players.entity import Player
from filters.weapons import WeaponClassIter

snipers = {weapon.name for weapon in WeaponClassIter('sniper')}

class WeaponMode(IntEnum):
PRIMARY = 0
SECONDARY = 1
MAX = 2

class MyPlayer(Player):
caching = True

def is_currently_zoomed(self):
weapon = self.active_weapon
if weapon is None or weapon.classname not in snipers:
return False
return weapon.get_property_int('m_weaponMode') == WeaponMode.SECONDARY

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 15 guests