Last active
July 14, 2018 03:24
-
-
Save vinci6k/3c54ab66bc6cf13a060299c07997e9bc to your computer and use it in GitHub Desktop.
Adding a crosshair to unscoped snipers in CSGO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#fake_crosshair_example.py | |
from events import Event | |
from colors import Color | |
from memory import make_object | |
from entities.hooks import EntityCondition, EntityPreHook | |
from players.entity import Player | |
from players.helpers import index_from_userid | |
from weapons.entity import Weapon | |
from messages import HudMsg | |
# Weapons which will have the fake crosshair. | |
snipers = ['weapon_ssg08', 'weapon_awp', 'weapon_g3sg1', 'weapon_scar20'] | |
# Crosshair settings | |
crosshair_color = Color(0, 255, 0) | |
crosshair_shape = '+' | |
crosshair = HudMsg( | |
message=crosshair_shape, | |
x=-1, | |
y=-1, | |
color1=crosshair_color, | |
hold_time=300, | |
channel=1) | |
# Empty HudMsg used for overriding / removing the previous one. | |
remove_crosshair = HudMsg(message=' ', hold_time=0.1, channel=1) | |
@EntityPreHook(EntityCondition.is_player, 'weapon_switch') | |
def pre_weapon_switch(stack_data): | |
player = make_object(Player, stack_data[0]) | |
weapon = make_object(Weapon, stack_data[1]) | |
# Did the player change to a sniper? | |
if weapon.classname in snipers: | |
# Give him the fake crosshair. | |
crosshair.send(player.index) | |
else: | |
# If not, give him the empty HudMsg. | |
remove_crosshair.send(player.index) | |
@Event('weapon_zoom') | |
def weapon_zoom(event): | |
player = Player.from_userid(event['userid']) | |
scoped = player.get_property_bool('m_bIsScoped') | |
# Is the player scoped / zoomed in? | |
if scoped: | |
remove_crosshair.send(player.index) | |
else: | |
crosshair.send(player.index) | |
@Event('player_death') | |
def player_death(event): | |
remove_crosshair.send(index_from_userid(event['userid'])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment