Raised This Month: $32 Target: $400
 8% 

Checking entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
safetymoose
Senior Member
Join Date: Feb 2015
Old 02-11-2015 , 20:46   Checking entities
Reply With Quote #1

Hey guys i'm still a noob at coding so i was hoping someone could lend me a hand. I am trying to check for things that the player is aiming at.

Something like this:
PHP Code:
if(engfunc(EngFunc_PointContents,origin) == CONTENTS_SKY
    {  
       
client_print(idprint_chat"This is the sky")
    } 
So what i would like to do is check for entities where i'm pointing at certain maps. I already checked CONTENTS and it had water, lava, etc...

But for my case i need to check for a door and lets say... moving platforms...

So how could I perform a check like this for entities like func_door and func_train? And possibly other entities aswell?

Last edited by safetymoose; 02-11-2015 at 20:47.
safetymoose is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-12-2015 , 11:36   Re: Checking entities
Reply With Quote #2

get_user_aiming and check the returned index classname ?

PHP Code:
new TargetbodyEntClassName[20]
get_user_aiming(idTargetbody)
pev(Targetpev_classnameEntClassName)
if(
equal(EntClassName"func_door"))
{
    
//aiming at a func_door ent

__________________

Last edited by HamletEagle; 02-12-2015 at 12:47.
HamletEagle is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-15-2015 , 14:17   Re: Checking entities
Reply With Quote #3

Well, this should work

PHP Code:
stock boolIsAimingAtEnt(id, const EntClassName[])
{
    if(
EntClassName[0] == EOS || !is_user_alive(id))
    {
        return 
false
    
}
    
    new 
TargetBodyClassName[20]
    
get_user_aiming(idTargetBody)
    
pev(Targetpev_classnameClassName)
    if(
equal(ClassNameEntClassName))
    {
        return 
true
    
}  
    return 
false

And:
PHP Code:
if(IsAimingAtEnt(id"func_door"))
{

__________________
HamletEagle is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 02-20-2015 , 05:54   Re: Checking entities
Reply With Quote #4

sry i was gone for so long, i was out of town...

I ran into a little problem, i'm using an origin with 3 coordinates. So i need to make a check at that origin for the entities. Also how can i check if the entity at the origin is a player?

Something like:
PHP Code:
static Float:Origin[3]

//i'm using a stock that returns the coordinates of the origin

if (equal(entity at origin"func_door"))
{
// This is a door...
}

//How do i check if it's a player?
if (equal(entity at originPlayer))
{
// This is a player...


Last edited by safetymoose; 02-20-2015 at 06:15.
safetymoose is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Location: Siiiiiiiiuu
Old 02-20-2015 , 06:37   Re: Checking entities
Reply With Quote #5

Quote:
Originally Posted by safetymoose View Post
sry i was gone for so long, i was out of town...

I ran into a little problem, i'm using an origin with 3 coordinates. So i need to make a check at that origin for the entities. Also how can i check if the entity at the origin is a player?

Something like:
PHP Code:
static Float:Origin[3]

//i'm using a stock that returns the coordinates of the origin

if (equal(entity at origin"func_door"))
{
// This is a door...
}

//How do i check if it's a player?
if (equal(entity at originPlayer))
{
// This is a player...

you can use classname: "player"
Yet, i guess the most recommended is to check if the entity index is a player.
__________________
Jhob94 is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 02-20-2015 , 08:19   Re: Checking entities
Reply With Quote #6

ok, so i can just check for the classname "Player".

But i still need to make the check using the origin. I have to check the origin for entities, such as doors.
safetymoose is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-20-2015 , 11:50   Re: Checking entities
Reply With Quote #7

If you want know if an entity is player the best ideea is to check it's index. Checking by classname require also an !is_user_bot check, because bots have player class too(needed if you only want true players).

If I get what your request is, you want to check if at some origins is an ent with certain classname and you don't have it's index.

Didn't tested, but should work.
PHP Code:
stock EntAtOrigin(Float:Origin[3], const EntClassName[])
{
    static 
MaxEntities
    
new Float:EntOrigin[3], ClassName[20], i
    
new bool:SameOrigins true
    
    
if(!MaxEntities)
    {
        
MaxEntities global_get(glb_maxEntities)
    }
    for(new 
EntEnt MaxEntitiesEnt++)
    {
        if(
pev_valid(Ent))
        {
            
pev(Entpev_originEntOrigin)
            
            for(
03i++)
            {
                if(
Origin[i] != EntOrigin[i])
                {
                    
SameOrigins false
                
}
            }
            if(
SameOrigins)
            {
                
pev(Entpev_classnameClassName)
                if(
equal(ClassNameEntClassName))
                {
                    return 
true
                
}
            }
        }
    }
    return 
false

Also, your problem sounds like an XY one, you should explain us what you want to do so we can give you the best way. If you say that you use a stock to get the origin, this means that you get them from an index, if you have it's index simply do:
PHP Code:
new MaxPlayers
MaxPlayers 
get_maxplayers()
if(
<= index <= MaxPlayers)
{
    
//this entity is a player

__________________

Last edited by HamletEagle; 02-20-2015 at 11:52.
HamletEagle is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 02-24-2015 , 06:29   Re: Checking entities
Reply With Quote #8

Well, you were right, it was better to go with indexes then with an origin. I managed to get it working with indexes, and i'm very satisfied. Thank you HamletEagle

I just need 1 more thing.

PHP Code:
set_pev(entpev_ownerid
Is it possible to make this work with certain entities? I would like to prevent collision of this entity with other entitities(not all, just a few), so is it possible to make this?
PHP Code:
set_pev(entpev_owner"some classnames"

Last edited by safetymoose; 02-24-2015 at 07:33.
safetymoose is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-24-2015 , 12:05   Re: Checking entities
Reply With Quote #9

No, pev_owner expects an integer. You are right that an entity is not solid for it's owner, but you can't use it like you want to do. AFAIK an entity can have only one owner at a time, so you should search for another method.

Do you want to allow an ent to go through another ent or just block the touch(because if they touch something happen) ?

Try to: hook touch with engine(you can specify both toucher and touched classnames) and supercede the call. This should prevent them from colliding.
__________________

Last edited by HamletEagle; 02-24-2015 at 12:06.
HamletEagle is offline
safetymoose
Senior Member
Join Date: Feb 2015
Old 02-24-2015 , 15:10   Re: Checking entities
Reply With Quote #10

well here's what i tried and failed. Think you can correct it?

PHP Code:
// in plugin_init()
RegisterHam(Ham_Touch"ent""ent_touch")

//somewhere else
public ent_touchent ent2 )
{
    if( !
pev_valident2 ) )
        return 
HAM_IGNORED
    
static iclassname[31]
    
pev(ent2pev_classnameiclassnamecharsmax(iclassname))
    if( 
equaliclassname"1st classname") || equaliclassname"2nd classname") || equaliclassname"3rd classname") )
        {
        return 
HAM_SUPERCEDE
        
}
    return 
HAM_IGNORED

I also tried
PHP Code:
register_touch"ent""ent2""ent_touch"
Still doesnt work...

Last edited by safetymoose; 02-24-2015 at 15:27.
safetymoose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:25.


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