Detect stuck player

Please post any questions about developing your plugin here. Please use the search function before posting!
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Detect stuck player

Postby DJiSer » Sun Jan 11, 2015 11:30 pm

Is it possible to check if a player is stuck in a wall/outside map?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jan 12, 2015 12:18 am

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)
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Mon Jan 12, 2015 5:34 pm

It's always return "False"
arawra
Senior Member
Posts: 190
Joined: Fri Jun 21, 2013 6:51 am

Postby arawra » Mon Jan 12, 2015 9:07 pm

Is your player actually stuck when you run it? Thats the only time it will return true.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Mon Jan 12, 2015 9:49 pm

I tested yesterday in no-clip mode and it was returning True whenever I was in a wall/outside the map.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Postby satoon101 » Tue Jan 13, 2015 12:07 am

Which game is this for? What map are you testing with? Please provide a set of coordinates on the map which are not returning correctly.
Image
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Tue Jan 13, 2015 6:28 am

CS:GO de_dust2
Then i use no-clip - return True.
Set location with get_view_coordinates, always False.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Jan 13, 2015 7:48 am

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()
DJiSer
Junior Member
Posts: 20
Joined: Sat May 10, 2014 2:44 pm

Postby DJiSer » Tue Jan 13, 2015 9:21 am

User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Tue Jan 13, 2015 10:55 am

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 47 guests