AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Finding near origins (https://forums.alliedmods.net/showthread.php?t=107043)

Alucard^ 10-22-2009 02:40

Finding near origins
 
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.

ot_207 10-22-2009 08:23

Re: Finding near origins
 
What do you want to create at that origin?
Or what do you want to use that origin for?

SnoW 10-22-2009 09:04

Re: Finding near origins
 
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;



Exolent[jNr] 10-22-2009 13:04

Re: Finding near origins
 
@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 ); }

Hawk552 10-22-2009 13:48

Re: Finding near origins
 
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)



Alucard^ 10-22-2009 17:33

Re: Finding near origins
 
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.

Hawk552 10-22-2009 17:59

Re: Finding near origins
 
Quote:

Originally Posted by Alucard^ (Post 969448)
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^ (Post 969448)
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.

Arkshine 10-22-2009 18:08

Re: Finding near origins
 
Both PointContents() and EngFunc_PointContents are the same by calling the HL1 engine function.

Alucard^ 10-23-2009 01:49

Re: Finding near origins
 
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? 


Hawk552 10-23-2009 08:23

Re: Finding near origins
 
Quote:

Originally Posted by Alucard^ (Post 969676)
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^ (Post 969676)
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 



All times are GMT -4. The time now is 17:34.

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