Raised This Month: $ Target: $400
 0% 

Finding near origins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 10-22-2009 , 13:48   Re: Finding near origins
Reply With Quote #1

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
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