ROG is an include file which allows you to generate random valid origins around the map. It could be used to create random player spawns or in Battle Royale mods(PUBG/Fortnite) to spawn the floor loot/drop crates/llamas, etc.
I know there are already 2 other includes that to the same thing(one made by joropito and one made by GHW_Chronic), but seeing how people complain that this 2 includes produce sometimes invalid points I decided to give it a try and see if I can make something that produces more consistent results in a shorter time.
Below are comparison results between
superspawns and
rog on some default and custom maps:
Spoiler
Code:
de_mon
rog: 595 origins in 103 miliseconds
superspawns: 165 origins in 158 miliseconds
Code:
hg_industrialzone
rog: 335 origins in 53 miliseconds
superspawns: 118 origins in 413 milliseconds
Code:
de_dust2
rog: 99 origins in 21 miliseconds
superspawns: 41 origins in 261 miliseconds
Code:
de_nuke
rog: 104 origins in 33 miliseconds
superspawns: 36 origins in 459 miliseconds
Code:
cs_office
rog: 96 origins in 41 miliseconds
superspawns: 40 origins in 508 miliseconds
Code:
de_chateau
rog: 77 origins in 22 miliseconds
superspawns: 27 origins in 297 miliseconds
Code:
big_city2
rog: 299 origins in 36 miliseconds
superspawns: 97 origins in 319 miliseconds
On average
rog produces
3x more origins than
superspawns.
On average
rog generates origins
7.8x faster than
superspawns.
Keep in mind that the number of origins depends on the minimum distance between points(in above tests 250 was used for both includes).
Functions:
1.
ROGInitialize(Float:MinDistance, const CheckFunction[] = "") initializes the random origin generator and fills the arrays.
MinDistance is the minimum distance between points.
CheckFunction allows you to set custom conditions for origins.
2.
ROGGetOrigin(Float:Origin[3]) retrieves a random origin. Note that once all origins are used it will start over, meaning it will never run out of points.
3.
ROGShuffleOrigins() randomizes the origin array.
4.
ROGDumpOriginData() shows all generated origins and their count.
Because
rog is fast you can generate origins during runtime without freezing the server, meaning that at any point you can call again
ROGInitialize() without any troubles.
If you don't want to call again
ROGInitialize() but you also don't want to always spawn your entities in the same place you can use
ROGShuffleOrigins which will randomize the origins.
Example code(which can also be used to manually check the generated origins):
PHP Code:
#include <amxmodx>
#include <rog>
#include <fakemeta>
public plugin_init()
{
ROGInitialize(250.0)
ROGDumpOriginData()
register_clcmd("say /next", "ClientCommand_NextOrigin")
register_clcmd("say /generate", "ClientCommand_GenerateOrigins")
register_clcmd("say /shuffle", "ClientCommand_ShuffleOrigins")
}
public ClientCommand_NextOrigin(id)
{
//get the next origin and spawn the player there
new Float:Origin[3]
ROGGetOrigin(Origin)
engfunc(EngFunc_SetOrigin, id, Origin)
}
public ClientCommand_GenerateOrigins(id)
{
//generate a new set of origins during runtime
ROGInitialize(250.0)
}
public ClientCommand_ShuffleOrigins(id)
{
//shuffle the existing set of origins
ROGShuffleOrigins()
}
Custom conditions:
Now you can add custom conditions for filtering origins, without editing the include file.
Example code:
PHP Code:
#include <amxmodx>
#include <rog>
#include <fakemeta>
public plugin_init()
{
ROGInitialize(250.0, "CheckOrigin")
ROGDumpOriginData()
register_clcmd("say /next", "ClientCommand_NextOrigin")
}
public CheckOrigin(Float:origin[3])
{
if(origin[0] < -2000.0)
{
return 0
}
return 1
}
public ClientCommand_NextOrigin(id)
{
new Float:Origin[3]
ROGGetOrigin(Origin)
engfunc(EngFunc_SetOrigin, id, Origin)
}
It will skip all origins that have origin[0] < -2000.0.
To skip an origin you have to return 0.
If you do not wish to use this feature simply leave the second param empty.
Credits:
edon for testing and ideas
Previous version downloads: 350