AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved for now]Player in duct (? (https://forums.alliedmods.net/showthread.php?t=243021)

NikKOo31 06-28-2014 13:04

[Solved for now]Player in duct (?
 
Which is the best way to detect if a player is inside a duct (ventilations)?

Once he is inside there's no need to duck so checking player's buttons in inefficient. I was thinking in force player to stand up and check if he could/couldn't, but I'm not sure how to proceed :/

It's for hns to avoid planting lasermines inside ducts ._.

Any help will be appreciated ^_^

Flick3rR 06-28-2014 13:52

Re: Player in duct (?
 
By hooking Ham_Duck. (Not sure if this is it's right name. AFAIK this ham is called in the time, while the user is ducking. So you can set protection from these mines in the function of this ham.

r0ck 06-28-2014 14:04

Re: Player in duct (?
 
Quote:

Originally Posted by Flick3rR (Post 2158837)
By hooking Ham_Duck. (Not sure if this is it's right name. AFAIK this ham is called in the time, while the user is ducking. So you can set protection from these mines in the function of this ham.

Its Ham_Player_Duck but i don't agree with you...
It will detect duck when the player presses duck key and not detect when hes in vent ( duck without pressing the key)

So i would suggest to try getting flags for ducking

Youfunction() if(pev(id, pev_flags) & FL_DUCKIN) // hes ducking

I'm sure it detects player size and not the key so it will work inside vents

HamletEagle 06-28-2014 14:07

Re: Player in duct (?
 
Quote:

Originally Posted by r0ck (Post 2158842)
Its Ham_Player_Duck but i don't agree with you...
It will detect duck when the player presses duck key and not detect when hes in vent ( duck without pressing the key)

So i would suggest to try getting flags for ducking

Youfunction() if(pev(id, pev_flags) & FL_DUCKIN) // hes ducking

I'm sure it detects player size and not the key so it will work inside vents

Yes,then just check if he is not pressing a key to duck. This should be enough.

r0ck 06-28-2014 14:11

Re: Player in duct (?
 
Quote:

Originally Posted by HamletEagle (Post 2158845)
Yes,then just check if he is not pressing a key to duck. This should be enough.

Players will then hold duck while planting .... well :bee:

Nextra 06-28-2014 22:45

Re: Player in duct (?
 
You can quite easily check if a player is in a spot where they can not stand up using a EngFunc_TraceHull call. Simply get the origin and add some amount to the z axis (going upwards) and use that as the trace target. If TR_AllSolid is false and TR_flFraction is smaller than 1.0 the player is in a space where they can not stand up. You maybe have to play around a little with how far you need to move up to accurately detect this.

hornet 06-28-2014 22:50

Re: Player in duct (?
 
A simple trace_hull() call should suffice.

NikKOo31 06-29-2014 12:57

Re: Player in duct (?
 
These are my 2 options .-.

PHP Code:

stock bool:player_in_duct(id)
{
    new 
Float:origin[3]
    
pev(idpev_originorigin)
    
origin[2] += 10.0

    engfunc
(EngFunc_TraceHulloriginoriginIGNORE_MONSTERSpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANid)

    new 
Float:fFraction
    get_tr2
(0TR_flFractionfFraction)

    if (!
get_tr2(0TR_AllSolid) && fFraction 1.0)
        return 
true

    
return false


PHP Code:

stock bool:player_in_duct2(id)
{
        const 
IN_SOLID_AREA    = (1<<TR_StartSolid)
    new 
Float:origin[3]
    
pev(idpev_originorigin)
    
origin[2] += 10.0

    
if(!(trace_hull(originpev(idpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMANid) & IN_SOLID_AREA)) 
        return 
true

    
return false


I'm not sure of trace_hull, I've never used it. I stole some Connor's code :grrr:

Will be testing later :)

NikKOo31 06-30-2014 15:44

Re: Player in duct (?
 
4 Attachment(s)
Bumping ^ Here are the results

https://forums.alliedmods.net/attach...1&d=1404156929

https://forums.alliedmods.net/attach...1&d=1404156929

https://forums.alliedmods.net/attach...1&d=1404156929

https://forums.alliedmods.net/attach...1&d=1404156929

TR_AllSolid turns to true inside ventilations & turns false outside.
TR_flFraction always in 1.0 no matter where I am.

In other words, I wasn't able to accurate detect if a player is inside ducts :/

This is my current stock

PHP Code:

stock bool:player_in_duct(id, &solid, &Float:fraction)
{
    static 
tr
    
static Float:origin[3]
    
pev(idpev_originorigin)
    
origin[2] += get_pcvar_float(cvar)
    
engfunc(EngFunc_TraceHulloriginorigin0HULL_HEADidtr)
    
solid get_tr2(trTR_AllSolid)
    
get_tr2(trTR_flFractionfraction)
    if(!
solid && fraction 1.0)
        return 
true
    
    
return false


I tested many distances with the cvar.. With 25-30 I got TR_AllSolid to change
Any help? :c

meTaLiCroSS 07-01-2014 01:25

Re: Player in duct (?
 
It's obvious.

PHP Code:

engfunc(EngFunc_TraceHulloriginorigin0HULL_HEADidtr

You're starting the trace from "origin" to "origin", distance = 0 units, fraction would be always 1.0 lol


All times are GMT -4. The time now is 21:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.