AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Random locations generator (https://forums.alliedmods.net/showthread.php?t=132500)

joropito 07-15-2010 14:09

Random locations generator
 
1 Attachment(s)
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



xPaw 07-15-2010 14:31

Re: Random locations generator
 
Well done, will be using this for sure

ot_207 07-15-2010 14:35

Re: Random locations generator
 
Good job joro.
I would have posted this tutorial if I would have worked on runemodx. When I was at the start of the project I wanted to improve what Chronic made, but no problem.
I now have what you did, good job again!

wrecked_ 07-15-2010 14:45

Re: Random locations generator
 
joropito, you're the man.

drekes 07-15-2010 16:06

Re: Random locations generator
 
awesome work.

Alucard^ 07-16-2010 00:02

Re: Random locations generator
 
Cool!!!!! i will use this. Nice job.

infek 07-21-2010 20:59

Re: Random locations generator
 
I've been looking for this, damn thanks

joropito 07-21-2010 22:07

Re: Random locations generator
 
Currently I have a better than the one in firts post.

I will update as soon as possible.

5c0r-|3i0 07-31-2010 10:28

Re: Random locations generator
 
Cool....Thanks :D

Gadzislaw007 07-31-2010 10:38

Re: Random locations generator
 
Oh, this is great. Will use... somewhen... for sure ;]


All times are GMT -4. The time now is 16:01.

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