# =============================================================================
# >> IMPORTS
# =============================================================================
from colors import RED, YELLOW
from events import Event
from messages import HudMsg, SayText2
from players.entity import Player
# =============================================================================
# >> WEAPON CONFIG
# =============================================================================
weapon_dict = {
'rpg_missle':'RPG',
'combine_ball':'Combine Ball',
'smg1_grenade':'SMG Grenade',
'ar2':'AR2',
'crossbow_bolt':'Crossbow',
'physcannon':'Physcannon',
'pistol':'Pistol',
'shotgun':'Shotgun',
'smg1':'SMG',
'357':'357',
'crowbar':'a Crowbar',
'stunstick':'a Stunstick',
'slam':'a Slam',
'grenade_frag':'a Grenade'
}
HUD_MESSAGE = HudMsg(message='Attacker info:\nName: {name}\nHealth: {health}\nArmor: {armor}\nDistance: {distance}\nKDR: {kdr}', x=-1, y=0.3, color1=RED, color2=YELLOW, effect=0, fade_in=0.05, fade_out=1.5, hold_time=8, fx_time=1.0, channel=4)
WEAPON_MESSAGE = HudMsg(message='{killer} has killed {victim} with {name}', x=0.01, y=0.88, color1=RED, color2=YELLOW, effect=2, fade_in=0.05, fade_out=1.5, hold_time=8, fx_time=1.0, channel=4)
SUICIDE_HUD_MSG = HudMsg(message='{victim} has committed suicide', x=0.01, y=0.88, color1=RED, color2=YELLOW, effect=2, fade_in=0.05, fade_out=1.5, hold_time=8, fx_time=1.0, channel=4)
CHAT_MESSAGE_WEAPON = SayText2(message='{killer} has killed {victim} with {name}')
CHAT_MESSAGE_INFO = SayText2(message='Attacker info:\nName: {name}\nHealth: {health}\nArmor: {armor}\nDistance: {distance}\nKDR: {kdr}')
CHAT_SUICIDE_MSG = SayText2(message='{victim} has committed suicide')
# =============================================================================
# >> GAME EVENTS
# =============================================================================
@Event('player_death')
def player_death(game_event):
userid = game_event.get_int('userid')
attacker = game_event.get_int('attacker')
victim = Player.from_userid(userid)
try:
killer = Player.from_userid(attacker)
except ValueError:
return
if userid != attacker:
distance = round(killer.origin.get_distance(victim.origin), 2)
kdr = killer.kills / killer.deaths if killer.deaths != 0 else 0
HUD_MESSAGE.send(victim.index, name=killer.name, health=killer.health, armor=killer.armor, distance=distance, kdr=f'{kdr:.03f}')
CHAT_MESSAGE_INFO.send(victim.index, name=killer.name, health=killer.health, armor=killer.armor, distance=distance, kdr=f'{kdr:.03f}')
attacker_weapon = killer.get_active_weapon()
if attacker_weapon is None:
return
weapon_name = attacker_weapon.classname
name = ''
if userid == attacker:
CHAT_SUICIDE_MSG.send(killer.index, victim=victim.name)
SUICIDE_HUD_MSG.send(killer.index, victim=victim.name)
else:
weapon = game_event['weapon']
if weapon in weapon_dict:
name = weapon_dict[weapon]
elif weapon == "physics":
if weapon_name == "weapon_physcannon":
name = "Physcannon"
if not weapon_name == "weapon_physcannon":
name = "a Barrel"
else:
name = weapon
WEAPON_MESSAGE.send(killer.index, killer=killer.name, victim=victim.name, name=name)
CHAT_MESSAGE_WEAPON.send(killer.index, killer=killer.name, victim=victim.name, name=name)