Page 1 of 1

[CS:S] Worldspawn touch problem

Posted: Sun Feb 14, 2021 6:46 pm
by Kami
Hey guys,

I'm trying to determine when you touch the ground. I tried multiple ways, including this:

Syntax: Select all

@EntityPreHook(EntityCondition.equals_entity_classname('player'), 'touch')
def Entity_StartTouch(args):
entity = make_object(Entity, args[1]) #this is player
try:
touching = make_object(Entity, args[0])
except:
return
if entity.classname == "worldspawn": print(entity.classname)
if touching.classname == "worldspawn": print(touching.classname)


The problem is, it does not work reliably. When I jump around it does not consistently work. I also tried start_touch, with even worse results.

Groundflag is not an option I can use, as my plugin involves beeing hit by flashes at the feet, which sometimes is counted as beeing on the ground for some reason.

My idea now would be to make a trace going down from your feet to check if the ground is away more then x units. The problem with this is that I'm not familiar with traces + their performance for such a check. I tried this code:

Syntax: Select all

@OnTick
def _tick():
for player in PlayerIter('alive'):
if not player.flags & PlayerStates.ONGROUND:

destination = Vector(player.origin[0],player.origin[1],player.origin[2]-1000)

# Get a new trace instance
trace = GameTrace()

# Trace from the player's feet to the destination
engine_trace.trace_ray(
# This matches the player's bounding box from his feets to
# the destination
Ray(player.origin, destination, player.mins, player.maxs),

# This collides with everything
ContentMasks.ALL,

# This ignore nothing but the player himself
TraceFilterSimple((player,)),

# The trace will contains the results
trace
)

# If the trace did hit, that means there was obstruction along the way
if trace.did_hit():
if trace.end_position.get_distance(player.origin) >= 0 and trace.end_position.get_distance(player.origin) <= 10:
# So the end of our trace becomes our destination
print('hit')


But this is not as reliable yet as I wished it would be, as the distance you last get can vary from 0 to 10 or even more units. Also this would not check for flashes below you yet I guess.

Any ideas for different ways how to consistently check for the ground?

Re: [CS:S] Worldspawn touch problem

Posted: Sun Feb 14, 2021 7:16 pm
by L'In20Cible

Re: [CS:S] Worldspawn touch problem

Posted: Sun Feb 14, 2021 7:19 pm
by Kami
Wouldnt that Return true for a flash hitting the feet?

Re: [CS:S] Worldspawn touch problem

Posted: Sun Feb 14, 2021 7:27 pm
by L'In20Cible
Kami wrote:Wouldnt that Return true for a flash hitting the feet?

If the ground entity isn't -1, then that's the handle of the entity the player is standing on. You can retrieve it that way and check whether it's a flashbang or not:

Syntax: Select all

entity = Entity.from_inthandle(player.ground_entity)

Re: [CS:S] Worldspawn touch problem

Posted: Sun Feb 14, 2021 7:29 pm
by L'In20Cible
Try something like this:

Syntax: Select all

from entities.entity import Entity
from entities.constants import WORLD_ENTITY_INDEX

def is_player_on_world(player):
try:
return Entity.from_inthandle(
player.ground_entity).index == WORLD_ENTITY_INDEX
except OverflowError:
return False

Re: [CS:S] Worldspawn touch problem

Posted: Mon Feb 15, 2021 9:07 pm
by Kami
Thank you very much, this works perfectly!