Raised This Month: $ Target: $400
 0% 

Finding near origins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-22-2009 , 02:40   Finding near origins
Reply With Quote #1

Well, I searched but didn't found exactly what I want.

For example, I have the origin of a player, so then... I want to get a random origin NEAR of the actual player origin, like an sphere.

Thx, and sry if i writed something wrong in english.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 10-22-2009 , 08:23   Re: Finding near origins
Reply With Quote #2

What do you want to create at that origin?
Or what do you want to use that origin for?
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 10-22-2009 , 09:04   Re: Finding near origins
Reply With Quote #3

If you don't want to spawn a solid entity or something similiar:
PHP Code:
stock get_near_origin( const origin], distance )
{
     
origin] += random_num( -distancedistance );
     
origin] += random_num( -distancedistance );
     
origin] += random_num( -distancedistance );
     return 
origin;

SnoW is offline
Send a message via MSN to SnoW
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 10-22-2009 , 13:04   Re: Finding near origins
Reply With Quote #4

@SnoW
That won't work, since you cannot change the value of a constant variable.

Code:
GetNearOrigin( const Float:vCenter[ 3 ], const Float:fRadius, Float:vReturn[ 3 ] ) {     vReturn[ 0 ] = vCenter[ 0 ] + random_float( -fRadius, fRadius );     vReturn[ 1 ] = vCenter[ 1 ] + random_float( -fRadius, fRadius );     vReturn[ 2 ] = vCenter[ 1 ] + random_float( -fRadius, fRadius ); }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-22-2009 , 13:48   Re: Finding near origins
Reply With Quote #5

This tutorial will give you much more detailed and useful information, such as checking if the origin is open and allowing you to scan continuously:

http://forums.alliedmods.net/showthread.php?t=49829

Here's some code that I wrote a while ago but which I didn't include in that tutorial:

PHP Code:
public SetRandomLocation(id,Num)
{
    if(
Num++ > 20)
        return 
0
    
    
new Float:pOrigin[3]
    for(new 
Count;Count 3;Count++)
        
// random_float seems to be broken, I dunno if it's just me
        
pOrigin[Count] = float(random_num(-floatround(MAP_MAX),floatround(MAP_MAX)))
    
    new 
Float:Result[3],Float:End[3]
    
End pOrigin
    End
[2] = -8000.0
    
    engfunc
(EngFunc_TraceLine,pOrigin,End,1,-1,0)
    
get_tr2(0,TR_vecEndPos,Result)
    
    
Result[2] += 36.1
    
    
if(EF_PointContents(Result) != CONTENTS_EMPTY)
    {
        new 
Retn SetRandomLocation(id,Num)
        return 
Retn
    
}
    
    new 
TR
    engfunc
(EngFunc_TraceHull,Result,Result,0,HULL_HUMAN,0,TR)
    if(
get_tr2(TR,TraceResult:TR_StartSolid) || get_tr2(TR,TraceResult:TR_AllSolid) || !get_tr2(TR,TraceResult:TR_InOpen))
    {
        new 
Retn SetRandomLocation(id,Num)
        return 
Retn
    
}
    
    new 
Ent,Classname[33]
    while((
Ent engfunc(EngFunc_FindEntityInSphere,Ent,Result,25.0)) != 0)
    {
        
pev(Ent,pev_classname,Classname,32)
        if(
containi(Classname,"trigger_") != -|| containi(Classname,"func_") != -1)
        {
            new 
Retn SetRandomLocation(id,Num)
            return 
Retn
        
}
    }
    
    
engfunc(EngFunc_SetOrigin,id,Result)
    
    return 
PLUGIN_HANDLED
}

public 
CheckLocation(id)
{
    new 
Flags entity_get_int(id,EV_INT_flags),Num
    
if(Flags FL_INWATER || Flags FL_SWIM || Flags FL_FLOAT)
        
SetRandomLocation(id,Num)

__________________

Last edited by Hawk552; 10-22-2009 at 15:22. Reason: added the code from outside of the tutorial
Hawk552 is offline
Send a message via AIM to Hawk552
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-22-2009 , 17:33   Re: Finding near origins
Reply With Quote #6

Thx to all guys... helped me.

Also, thx for the link to that tutorial Hawk... but the code that you posted, emm I didn't understand at all, I don't know practically nothing about engine module.

Oh and, a question...

PointContents is the same as point_contents native? becouse is the only that I did found it in the funcwiki.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...

Last edited by Alucard^; 10-22-2009 at 17:36.
Alucard^ is offline
Send a message via Skype™ to Alucard^
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-22-2009 , 17:59   Re: Finding near origins
Reply With Quote #7

Quote:
Originally Posted by Alucard^ View Post
Also, thx for the link to that tutorial Hawk... but the code that you posted, emm I didn't understand at all, I don't know practically nothing about engine module.
It's not that hard to understand. You should read through it and figure out what it's doing, because you're probably going to want most of it.

Quote:
Originally Posted by Alucard^ View Post
PointContents is the same as point_contents native? becouse is the only that I did found it in the funcwiki.
They are identical, but I can't remember what PointContents() is from. I believe it's the FM equivalent (as a stock), but I'm also pretty sure that there's an engfunc() call for it too.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 10-22-2009 , 18:08   Re: Finding near origins
Reply With Quote #8

Both PointContents() and EngFunc_PointContents are the same by calling the HL1 engine function.
__________________

Last edited by Arkshine; 10-22-2009 at 18:10.
Arkshine is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 10-23-2009 , 01:49   Re: Finding near origins
Reply With Quote #9

Thx, well... here the lines that I don't understand:

PHP Code:
End[2] = -8000.0 


PHP Code:
Result[2] += 36.1 


PHP Code:
(MAP_MAX// Is a define or what? 
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-23-2009 , 08:23   Re: Finding near origins
Reply With Quote #10

Quote:
Originally Posted by Alucard^ View Post
Thx, well... here the lines that I don't understand:

PHP Code:
End[2] = -8000.0 
PHP Code:
Result[2] += 36.1 
These two collectively help us fire a line trace downward. -8000 is pretty arbitrary and -4096.0 or -MAP_MAX would have worked. Remember, the third cell is the z axis, which is up and down.

The += 36.1 part raises the trace that hits the ground up by a nudge over 36.0, which is the height of a player.

Quote:
Originally Posted by Alucard^ View Post
PHP Code:
(MAP_MAX// Is a define or what? 
Yes, my mistake:

PHP Code:
// the max coords of a map
#define MAP_MAX 4096.0 
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 17:34.


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