# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python
# Colors
from colors import ORANGE
from colors import WHITE
# Commands
from commands.say import SayCommand
# Config
from config.manager import ConfigManager
# Core
from core import SOURCE_ENGINE
# Engines
from engines.server import queue_command_string
# Entities
from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
# Events
from events import Event
# Menus
from menus import SimpleMenu
from menus import SimpleOption
# Messages
from messages import SayText2
# Players
from players.dictionary import PlayerDictionary
from players.entity import Player
# Plugins
from plugins.manager import plugin_manager
# ============================================================================
# >> GLOBAL VARIABLES
# ============================================================================
info = plugin_manager.get_plugin_info(__name__)
FADED_WHITE = WHITE.with_alpha(100)
# =============================================================================
# >> MESSAGE COLORS
# =============================================================================
MESSAGE_COLOR_WHITE = '\x01' if SOURCE_ENGINE == 'csgo' else WHITE
MESSAGE_COLOR_ORANGE = '\x10' if SOURCE_ENGINE == 'csgo' else ORANGE
# ============================================================================
# >> CONFIGURATION
# ============================================================================
with ConfigManager(info.name, 'trikz_') as config:
enable_ghost = config.cvar(
'enable_ghost', default=0, description='Enable/disable ghosting option.',
)
enable_flash = config.cvar(
'enable_flash', default=0, description='Enable/disable unlimited flashbangs.',
)
unlimited_health = config.cvar(
'unlimited_health', default=0, description='Enable/disable unlimited health.',
)
auto_respawn = config.cvar(
'auto_respawn', default=0, description='Enable/disable auto-respawning on death.',
)
# ============================================================================
# >> PREPARE CONVARS
# ============================================================================
queue_command_string(
'mp_friendlyfire 0;'
'sv_gravity 800;'
'sv_airaccelerate 250;'
'mp_limitteams 0;'
'mp_enableboost 1;'
)
# ============================================================================
# >> CLASSES
# ============================================================================
class TrikzPlayer(Player):
""""""
def __init__(self, index):
super().__init__(index)
self.flash = False
self.ghost = False
self.reset_player()
def reset_player(self):
self.first_checkpoint = (None, None)
self.second_checkpoint = (None, None)
def set_ghost(self):
self.color, self.noblock = (FADED_WHITE, True) if self.ghost else (WHITE, False)
if self.ghost:
self.tell('You are a ghost again.')
else:
self.tell('You are mortal.')
def tell(self, message):
SayText2(
f'{MESSAGE_COLOR_ORANGE}[{MESSAGE_COLOR_WHITE}{info.verbose_name}{MESSAGE_COLOR_ORANGE}] '
f'{MESSAGE_COLOR_WHITE}{message}'
).send(self.index)
player_dict = PlayerDictionary(factory=TrikzPlayer)
# ============================================================================
# >> GAME EVENTS
# ============================================================================
@Event('player_spawn')
def _player_spawn(game_event):
player = player_dict.from_userid(game_event['userid'])
if bool(enable_ghost):
player.set_ghost()
@Event('player_death')
def _player_death(game_event):
if bool(auto_respawn):
player = player_dict.from_userid(game_event['userid'])
player.spawn()
player.tell('You have been respawned.')
@Event('weapon_fire')
def _weapon_fire(game_event):
if game_event['weapon'] != 'flashbang':
return
player = player_dict.from_userid(game_event['userid'])
if bool(enable_flash) and player.flash:
player.give_named_item('weapon_flashbang')
player.tell('You have received a flashbang grenade.')
# ============================================================================
# >> ENTITY PRE-HOOKS
# ============================================================================
@EntityPreHook(EntityCondition.is_bot_player, 'blind')
@EntityPreHook(EntityCondition.is_human_player, 'blind')
def _pre_blind(stack_data):
return False
@EntityPreHook(EntityCondition.is_bot_player, 'deafen')
@EntityPreHook(EntityCondition.is_human_player, 'deafen')
def _pre_blind(stack_data):
return False
@EntityPreHook(EntityCondition.is_bot_player, 'on_take_damage')
@EntityPreHook(EntityCondition.is_human_player, 'on_take_damage')
def _pre_take_damage(stack_data):
if bool(unlimited_health):
return False
# ============================================================================
# >> SAY COMMANDS
# ============================================================================
@SayCommand('!trikz')
def _send_menu(command, index, team_only):
main_menu.send(index)
@SayCommand('!switch')
def _switch_ghost(command, index, team_only):
if not bool(enable_ghost):
player = player_dict[index]
player.ghost ^= True
player.set_ghost()
# ============================================================================
# >> CHECKPOINTS MENU CALLBACKS
# ============================================================================
def _save_checkpoint(player, attr):
if player.ground_entity != -1:
setattr(player, attr, (player.origin, player.view_angle))
player.tell(f"Your {attr.replace('_', ' ')} has been saved.")
else:
player.tell('You must be standing on the ground!')
def _option_save_first_checkpoint_selected(player):
_save_checkpoint(player, 'first_checkpoint')
def _option_save_second_checkpoint_selected(player):
_save_checkpoint(player, 'second_checkpoint')
def _move_to_checkpoint(player, attr):
vector, angles = getattr(player, attr)
if vector is not None and angles is not None:
player.origin = vector
player.view_angle = angles
player.tell(f"You have been moved back to your {attr.replace('_', ' ')}.")
else:
player.tell(f"You have not saved your {attr.replace('_', ' ')}.")
def _option_move_to_first_checkpoint_selected(player):
_move_to_checkpoint(player, 'first_checkpoint')
def _option_move_to_second_checkpoint_selected(player):
_move_to_checkpoint(player, 'second_checkpoint')
def _checkpoints_menu_callback(menu, index, option):
player = player_dict[index]
option.value(player)
menu.send(index)
# ============================================================================
# >> CHECKPOINTS MENU DECLARATION
# ============================================================================
checkpoints_menu = SimpleMenu(select_callback=_checkpoints_menu_callback)
checkpoints_menu.append('Trikz Checkpoints Menu')
checkpoints_menu.append('-' * 20)
checkpoints_menu.append(SimpleOption(1, 'Save 1st checkpoint', _option_save_first_checkpoint_selected))
checkpoints_menu.append(SimpleOption(2, 'Back to 1st checkpoint', _option_move_to_first_checkpoint_selected))
checkpoints_menu.append(' ')
checkpoints_menu.append(SimpleOption(3, 'Save 2nd checkpoint', _option_save_second_checkpoint_selected))
checkpoints_menu.append(SimpleOption(4, 'Back to 2nd checkpoint', _option_move_to_second_checkpoint_selected))
checkpoints_menu.append('-' * 20)
checkpoints_menu.append(f"{'9' if SOURCE_ENGINE == 'csgo' else '0'}. Close")
@checkpoints_menu.register_close_callback
def _on_close_checkpoints_menu(menu, index):
main_menu.send(index)
# ============================================================================
# >> MAIN MENU CALLBACKS
# ============================================================================
def _option_flashbang_selected(player):
if not bool(enable_flash):
return
if not player.flash:
return
if player.get_projectile_ammo('flashbang') < 2:
player.give_named_item('weapon_flashbang')
player.tell('You have received a flashbang grenade.')
def _option_auto_flash_selected(player):
if bool(enable_flash):
player.flash ^= True
player.tell(f"Auto-Flash turned {'on' if player.flash else 'off'}.")
def _option_ghost_selected(player):
if bool(enable_ghost):
player.ghost ^= True
player.set_ghost()
def _option_checkpoints_menu_selected(player):
checkpoints_menu.send(player.index)
def _option_respawn_selected(player):
if player.dead:
player.spawn()
def _main_menu_callback(menu, index, option):
player = player_dict[index]
option.value(player)
menu.send(player.index)
# ============================================================================
# >> MAIN MENU DECLARATION
# ============================================================================
main_menu = SimpleMenu(select_callback=_main_menu_callback)
main_menu.append('Trikz Settings Menu')
main_menu.append('-' * 20)
main_menu.append(SimpleOption(1, 'Give Flash (1)', _option_flashbang_selected))
main_menu.append(SimpleOption(2, 'Toggle Auto-Flash', _option_auto_flash_selected))
main_menu.append(SimpleOption(3, 'Toggle Blocking', _option_ghost_selected))
main_menu.append(SimpleOption(4, 'Checkpoints Menu', _option_checkpoints_menu_selected))
main_menu.append(SimpleOption(5, 'Respawn', _option_respawn_selected))
main_menu.append('-' * 20)
main_menu.append(f"{'9' if SOURCE_ENGINE == 'csgo' else '0'}. Close")