Detect stuck player
Detect stuck player
Is it possible to check if a player is stuck in a wall/outside map?
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
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)
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
CS:GO de_dust2
Then i use no-clip - return True.
Set location with get_view_coordinates, always False.
Then i use no-clip - return True.
Set location with get_view_coordinates, always False.
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
That's because the tested point is the base location of the player entity (which is located at his feet). The following works fine for me:
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()
- L'In20Cible
- Project Leader
- Posts: 1534
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
EventScripts way of setting a player's angle is a bit tricky as in fact, it does turn cheats on, force the given player to execute "setang" with the given parameters and then reset previous cheats state. Your best bet, is to call CBaseEntity::Teleport.
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)
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 1 guest