Random locations generator

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1189
Gender:
United States of America

Random locations generator

Post by Archive-Poster »

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

Code: Select all

#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_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
                if(pev_valid(ent))
                {
                        engfunc(EngFunc_SetModel, ent, "models/player/sas/sas.mdl")
                        engfunc(EngFunc_SetOrigin, ent, origin)
                }
        }
        else
        {
                server_print("No more locations")
        }

        return PLUGIN_HANDLED
} 
Attachments
superspawns.inc.zip
(1.66 KiB) Downloaded 4 times

Who is online

Users browsing this forum: No registered users and 1 guest