Raised This Month: $12 Target: $400
 3% 

ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-28-2018 , 07:30   ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
Reply With Quote #1

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


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

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_SetOriginidOrigin

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
Attached Files
File Type: inc rog.inc (8.0 KB, 1013 views)
__________________

Last edited by HamletEagle; 02-16-2019 at 11:41.
HamletEagle is offline
 


Thread Tools
Display Modes

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 13:03.


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