Raised This Month: $ Target: $400
 0% 

Random locations generator


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-15-2010 , 14:09   Random locations generator
Reply With Quote #1

I will share with all this utility to generate random locations to be used as spawnpoints or whatever you want.

With this you can get random spawns with a minimum distance between each one.

I know there's other alternatives but didn't help me
Hawk Tutorial: http://forums.alliedmods.net/showthread.php?p=519409
Chronic's plugin: http://forums.alliedmods.net/showthread.php?p=669666
I'm using some checks to be sure the location will be suitable to spawn a player or and entity without problems:
  • Minimum distance between points on first pass
  • Check for empty point contents
  • Check for hull (HULL_LARGE)
  • Avoiding locations near sky (250.0 units)
  • Avoiding water and other surfaces on floor
  • Visibility between consecutive points (to get "in map" points)

I tested this on some standard and custom maps without problems.

Sometimes you can get a location over a box but you can check that outside this utility. Also I worked to avoid ceiling locations.

I will be glad with feedback about useless locations (outside map, non stuck-free locations, etc).

Ideas and improvements are welcome too.

Here's an example on how to use the included file

PHP Code:
#include <amxmodx>
#include <superspawns>

public plugin_init()
{
    
// First we have to initialize the arrays and parameters
    // The value 3500.0 is the minimum distance between points
    // Nearest points will be found, but GetOrigin will erase points
    // with less than 3500.0 distance with other used points and return
    
SsInit(3500.0)

    
// Let start scanning the map
        
SsScan()

    
// This call is to dump on server logs the origins found
        
SsDump()

    
// This command will call GetOrigin() to get a new location, then spawn a model (is't just an example)
        
register_concmd("spawnent""spawnent")
}

public 
spawnent(id)
{
        new 
Float:origin[3]

    
// SsGetOrigin() will return true if useful location was found
    // will return false if there's no more usefull locations

        
if(SsGetOrigin(origin))
        {
                new 
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
                if(
pev_valid(ent))
                {
                        
engfunc(EngFunc_SetModelent"models/player/sas/sas.mdl")
                        
engfunc(EngFunc_SetOriginentorigin)
                }
        }
        else
        {
                
server_print("No more locations")
        }

        return 
PLUGIN_HANDLED

Attached Files
File Type: inc superspawns.inc (4.6 KB, 2062 views)
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.

Last edited by joropito; 07-15-2010 at 16:09.
joropito is offline
Send a message via MSN to joropito
 



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 23:47.


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