Detect stuck player
Posted: Sun Jan 11, 2015 11:30 pm
Is it possible to check if a player is stuck in a wall/outside map?
Syntax: Select all
# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python
# Engines
from engines.trace import engine_trace
from engines.trace import MASK_SOLID
# Players
from players.helpers import playerinfo_from_index
# ============================================================================
# >> HELPER FUNCTIONS
# ============================================================================
def is_player_stuck(player_index):
'''Return whether or not the given player is stuck in solid.'''
# Get the player's origin...
# To be more accurate, you should get the world space center of the player
# entity: (m_vecMins + m_vecMaxs) / 2
origin = playerinfo_from_index(player_index).get_abs_origin()
# Return whether or not the given player is stuck...
return bool(engine_trace.get_point_contents(origin)[0] & MASK_SOLID)
Syntax: Select all
# ============================================================================
# >> IMPORTS
# ============================================================================
# Source.Python
# Engines
from engines.trace import ContentMasks
from engines.trace import engine_trace
from engines.trace import GameTrace
from engines.trace import Ray
from engines.trace import TraceFilterSimple
# Filters
from filters.players import PlayerIter
# Players
from players.helpers import playerinfo_from_index
# ============================================================================
# >> HELPER FUNCTIONS
# ============================================================================
def is_player_stuck(player_index):
'''Return whether or not the given player is stuck in solid.'''
# Get the player's PlayerInfo instance...
player_info = playerinfo_from_index(player_index)
# Get the player's origin...
origin = player_info.get_abs_origin()
# Get a Ray object based on the player physic box...
ray = Ray(origin, origin, player_info.get_player_mins(),
player_info.get_player_maxs())
# Get a new GameTrace instance...
trace = GameTrace()
# Do the trace...
engine_trace.trace_ray(ray, ContentMasks.PLAYER_SOLID, TraceFilterSimple(
PlayerIter()), trace)
# Return whether or not the trace did hit...
return trace.did_hit()
Syntax: Select all
# ============================================================================
# >> IMPORTS
# ============================================================================
# Python Imports
# Random
from random import randint
# Source.Python Imports
# Core
from core import PLATFORM
# Events
from events import Event
# Math
from mathlib import QAngle
# Memory
from memory import Argument
from memory import Convention
from memory import Return
# Players
from players.helpers import pointer_from_userid
# ============================================================================
# >> GLOBAL VARIABLES
# ============================================================================
# Virtual offset for Teleport in the CBaseEntity's dispatch table...
# NOTE: For CS:GO it should be 113 and 114...
TELEPORT_OFFSET = 108 if PLATFORM == 'windows' else 109
# ============================================================================
# >> GAME EVENTS
# ============================================================================
@Event
def player_jump(game_event):
'''Fired every time a player jumps.'''
# Get the Pointer instance of the player...
player_pointer = pointer_from_userid(game_event.get_int('userid'))
# Get the Teleport function in the player's dispatch table...
teleport_function = player_pointer.make_virtual_function(
TELEPORT_OFFSET, Convention.THISCALL,
# void CBaseEntity::Teleport(const Vector *, const QAngle *,
# const Vector *)
(Argument.POINTER, Argument.POINTER, Argument.POINTER,
Argument.POINTER),
Return.VOID)
# Randomize the player's angles...
teleport_function(player_pointer, None, QAngle(randint(-90, 90),
randint(-90, 90), randint(-90, 90)), None)