Esempio n. 1
0
def on_player_disconnect(game_event):
    """Cancel all pending delays for the disconnecting player."""
    player = PlayerEntity.from_userid(game_event['userid'])

    delay_manager.cancel(f'respawn_{player.userid}')
    delay_manager.cancel(f'protect_{player.userid}')

    player.clear_data(keep_inventories=True)
Esempio n. 2
0
def on_weapon_fire_on_empty(game_event):
    """Refill the player's ammo, if the player's active weapon's clip is about to be empty."""
    if cvar_enable_infinite_ammo.get_int() > 0:
        player = PlayerEntity.from_userid(game_event['userid'])

        # Refill only valid weapons
        if weapon_manager.by_name(
                player.active_weapon.weapon_name) is not None:

            # Refill only if this is the last round
            if player.active_weapon.clip == 1:
                player.refill_ammo(1)
Esempio n. 3
0
def on_player_death(game_event):
    """Handle attacker rewards & respawn the victim."""
    # Get the attacker's userid
    userid_attacker = game_event['attacker']

    # Handle attacker rewards, if the attacker's userid is valid
    if userid_attacker:
        attacker = PlayerEntity.from_userid(userid_attacker)

        # Handle headshot reward
        if cvar_refill_clip_on_headshot.get_int(
        ) > 0 and game_event['headshot']:

            # Get the weapon's data
            weapon_data = weapon_manager.by_name(
                attacker.active_weapon.weapon_name)

            # Refill the weapon's clip
            attacker.refill_clip(weapon_data)

            # Restore the weapon's ammo
            attacker.active_weapon.ammo = weapon_data.maxammo

        # Give a High Explosive grenade, if it was a HE grenade kill
        if cvar_equip_hegrenade.get_int(
        ) == 2 and game_event['weapon'] == 'hegrenade':
            attacker.give_weapon('weapon_hegrenade')

        # Restore the attacker's health if it was a knife kill
        if cvar_restore_health_on_knife_kill.get_int(
        ) > 0 and game_event['weapon'].startswith('knife'):
            attacker.health = 100

    # Get a PlayerEntity instance for the victim
    victim = PlayerEntity.from_userid(game_event['userid'])

    # Respawn the victim after the configured respawn delay
    delay_manager(f'respawn_{victim.userid}',
                  abs(cvar_respawn_delay.get_float()), PlayerEntity.respawn,
                  (victim.index, ))
Esempio n. 4
0
def on_weapon_reload(game_event):
    """Refill the player's ammo."""
    if cvar_enable_infinite_ammo.get_int() > 0:
        player = PlayerEntity.from_userid(game_event['userid'])
        player.refill_ammo()
Esempio n. 5
0
def on_hegrenade_detonate(game_event):
    """Equip the player with another High Explosive grenade if configured that way."""
    if cvar_equip_hegrenade.get_int() == 3:
        player = PlayerEntity.from_userid(game_event['userid'])
        player.give_weapon('weapon_hegrenade')
Esempio n. 6
0
def on_player_spawn(game_event):
    """Prepare the player for battle if they are alive and on a team."""
    player = PlayerEntity.from_userid(game_event['userid'])

    if not player.dead and player.team > 1:
        prepare_player(player)