AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Check if the player is over the entity and it's touching it (https://forums.alliedmods.net/showthread.php?t=242657)

!Morte 06-22-2014 14:54

Check if the player is over the entity and it's touching it
 
I have an entity with a box model, the objetive is everybody have a certain time to get on the entity or they will die.

I have something like this to check if the player is over the entity:

PHP Code:

new FloatiOrigin]
entity_get_vectoridEV_VEC_originiOrigin )

if( 
iOrigin] >= 140.0 )
{
         
client_printidprint_chat"You're over the entity" )


When the player is over the box, his Z origin is > 140.0.

Now the problem is if i just jump away from de box, my Z origin still being > 140.0.

I want to know how i can check if the player is touching the entity without have to use register_touch or any fuction which is called a many often, because i try with this:

PHP Code:

 register_touchMy_Entity"player""function" )

public function( 
entid )
{
           if( !
pev_validid ) )
                   return;

           
g_Touchingid ] = true


And i know that is bad as hell because register_touch it's called a lot of time per second

.Dare Devil. 06-22-2014 15:07

Re: Check if the player is over the entity and it's touching it
 
try it

PHP Code:

// if you dont like the fakemeta, replace it with engine...
// returns 1 if ent2 is above ent1 
stock is_touchingent1ent2 )
{
    static 
Float:mins1[3], Float:mins2[3], Float:mins[3]
    static 
Float:maxs1[3], Float:maxs2[3], Float:maxs[3]    
    static 
Float:o1[3], Float:o2[3]
    static 
aFloat:d[3]
    
pevent1pev_minsmins1 )
    
pevent2pev_minsmins2 )
    
pevent1pev_maxsmaxs1 )
    
pevent2pev_maxsmaxs2 )
    
pevent1pev_origino1 )
    
pevent2pev_origino2 )
    for( 
03a++ )
    {
        
d[a] = o1[a] - o2[a]
        
mins[a] = mins1[a] + mins2[a]
        
maxs[a] = maxs1[a] + maxs2[a]
        if( (
d[a] < 0.0 && mins[a] < d[a]) || ( d[a] > 0.0 || maxs[a] > d[a] ) ) return 0
    
}
    return 
1


edit ( since misunderstood the op )
PHP Code:

// if you dont like the fakemeta, replace it with engine...
// returns 1 if is touching ( also returns 1 when entity is inside of another entity )
// ( in your case ent2 will be id or player  )
stock is_touching_from_aboveent1ent2 )
{
    static 
Float:mins1[3], Float:mins2[3], Float:mins[3]
    static 
Float:maxs1[3], Float:maxs2[3], Float:maxs[3]    
    static 
Float:o1[3], Float:o2[3]
    static 
aFloat:d[3]
    
pevent1pev_minsmins1 )
    
pevent2pev_minsmins2 )
    
pevent1pev_maxsmaxs1 )
    
pevent2pev_maxsmaxs2 )
    
pevent1pev_origino1 )
    
pevent2pev_origino2 )
    
mins1[2] = maxs1[2]
    
maxs1[2] += 1.0
    
for( 03a++ )
    {
        
d[a] = o1[a] - o2[a]
        
mins[a] = mins1[a] + mins2[a]
        
maxs[a] = maxs1[a] + maxs2[a]
        if( (
d[a] < 0.0 && mins[a] < d[a]) || ( d[a] > 0.0 || maxs[a] > d[a] ) ) return 0
    
}
    return 
1



klippy 06-22-2014 16:38

Re: Check if the player is over the entity and it's touching it
 
PHP Code:

pev(idpev_groundentity); 

on player think maybe? pev_groundentity tells on which entity are you standing on right now.


All times are GMT -4. The time now is 12:31.

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