[CS:S] Worldspawn touch problem

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

[CS:S] Worldspawn touch problem

Postby Kami » Sun Feb 14, 2021 6:46 pm

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?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Worldspawn touch problem

Postby L'In20Cible » Sun Feb 14, 2021 7:16 pm

User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Worldspawn touch problem

Postby Kami » Sun Feb 14, 2021 7:19 pm

Wouldnt that Return true for a flash hitting the feet?
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Worldspawn touch problem

Postby L'In20Cible » Sun Feb 14, 2021 7:27 pm

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)
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: [CS:S] Worldspawn touch problem

Postby L'In20Cible » Sun Feb 14, 2021 7:29 pm

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
User avatar
Kami
Global Moderator
Posts: 263
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: [CS:S] Worldspawn touch problem

Postby Kami » Mon Feb 15, 2021 9:07 pm

Thank you very much, this works perfectly!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 34 guests