Raised This Month: $ Target: $400
 0% 

Check if player is in radius of entity?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 05-31-2007 , 19:46   Re: Check if player is in radius of entity?
Reply With Quote #1

Here is the code I'm using that doesn't seem to work properly...

Code:
// Note that fOrigin1 and fOrigin2 are 2 different users current origins new entClass[32]; new playerNear, idNear; new Float:checkRadius = 75.0; new checkEnt = -1; while((checkEnt = find_ent_in_sphere(checkEnt, fOrigin1, checkRadius)) != 0) {     entity_get_string(checkEnt, EV_SZ_classname, entClass, 31);     if(containi(entClass, "item") || containi(entClass, "trigger") != -1)     {         playerNear = 1;     }     else     {         playerNear = 0;     } } checkEnt = -1; while((checkEnt = find_ent_in_sphere(checkEnt, fOrigin2, checkRadius)) != 0) {     entity_get_string(checkEnt, EV_SZ_classname, entClass, 31);     if(containi(entClass, "item") || containi(entClass, "trigger") != -1)     {         idNear = 1;     }     else     {         idNear = 0;     } } if(idNear == 1) {     // The player is near an item or trigger entity } else {     // The player isn't near an item or trigger entity } if(idNear == 1) {     // The player is near an item or trigger entity } else {     // The player isn't near an item or trigger entity }
hlstriker is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 05-31-2007 , 19:18   Re: Check if player is in radius of entity?
Reply With Quote #2

Found a nice .inc which is from OneEyed|teame06
In there you find much analogies (engine - fakemeta)
If you are interested in converting look at this ;)

greetz regalis
Attached Files
File Type: inc ojos.inc (3.4 KB, 120 views)
__________________
regalis is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 05-31-2007 , 20:41   Re: Check if player is in radius of entity?
Reply With Quote #3

this should work....i converted it into fakemeta...
The problem was here:
[quote]
if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
[quote]

Not tested...but looks good ;)
Code:
#include <fakemeta>

// Note that fOrigin1 and fOrigin2 are 2 different users current origins

new entClass[33];
new playerNear, idNear;
new Float:checkRadius = 75.0;

new checkEnt = -1;
while((checkEnt = engfunc(EngFunc_FindEntityInSphere, checkEnt, fOrigin1, checkRadius)) != 0)
{
    pev(checkEnt, pev_classname, entclass, 32)
    if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
    {
        playerNear = 1;
    }
    else
    {
        playerNear = 0;
    }
}

checkEnt = -1;
while((checkEnt = engfunc(EngFunc_FindEntityInSphere,checkEnt, fOrigin2, checkRadius)) != 0)
{
    pev(checkEnt, pev_classname, entclass, 32)
    if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
    {
        idNear = 1;
    }
    else
    {
        idNear = 0;
    }
}

if(idNear == 1)
{
    // The player is near an item or trigger entity
}
else
{
    // The player isn't near an item or trigger entity
}

if(playerNear == 1)
{
    // The player is near an item or trigger entity
}
else
{
    // The player isn't near an item or trigger entity
}
greetz regalis
__________________
regalis is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 05-31-2007 , 20:51   Re: Check if player is in radius of entity?
Reply With Quote #4

regalis <3 Fakemeta

A marriage waiting to happen.
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 05-31-2007 , 21:00   Re: Check if player is in radius of entity?
Reply With Quote #5

I'm not going to marry ;)
But i love fakemeta*lol*
Its much better than engine...the problem is that engine is loaded because of the widely use of it..0o
Therefore its pointless if you use engine or fakemeta...but in future maybe engine will disapear!?...and then i will marry fakemeta *lol*
__________________
regalis is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 05-31-2007 , 21:31   Re: Check if player is in radius of entity?
Reply With Quote #6

wow, anyway help me with my nade problem lol look at my thread again new problem
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-01-2007 , 02:08   Re: Check if player is in radius of entity?
Reply With Quote #7

I doubt those while() things would work ....
_Master_ is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-01-2007 , 06:31   Re: Check if player is in radius of entity?
Reply With Quote #8

Quote:
Originally Posted by _Master_ View Post
I doubt those while() things would work ....
Why do you think so?
__________________
regalis is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-01-2007 , 07:19   Re: Check if player is in radius of entity?
Reply With Quote #9

Because if the last checked entity is NOT near then the result is negative (no matter if a previously found entity was "close").
Not to mention that
Code:
if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
helps with being buggy

EDIT:
Code:
new checkEnt = -1;
playerNear = 0;
while((checkEnt = engfunc(EngFunc_FindEntityInSphere, checkEnt, fOrigin1, checkRadius)) != 0 && !playerNear)
{
    pev(checkEnt, pev_classname, entclass, 32)
    if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)  playerNear = 1;
}

checkEnt = -1;
idNear = 0;
while((checkEnt = engfunc(EngFunc_FindEntityInSphere,checkEnt, fOrigin2, checkRadius)) != 0 && !idNear)
{
    pev(checkEnt, pev_classname, entclass, 32)
    if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1) idNear = 1;
}

Last edited by _Master_; 06-01-2007 at 07:34.
_Master_ is offline
regalis
Veteran Member
Join Date: Jan 2007
Location: F*cking Germany
Old 06-01-2007 , 07:24   Re: Check if player is in radius of entity?
Reply With Quote #10

lol you are right!
I didn't saw that...(too tired) *omg*

Quote:
....
if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
{
playerNear = 1;
break;
}

...
...

if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
{
idNear = 1;
break;
}
This should work ;)


*Edit*
What do you mean with
Quote:
Originally Posted by _Master_ View Post
Not to mention that
Code:
if(containi(entClass, "item") != -1 || containi(entClass, "trigger") != -1)
helps with being buggy
Why is that buggy?..0o
__________________

Last edited by regalis; 06-01-2007 at 07:27.
regalis 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 22:24.


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