AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   ROG - A better random origin generator[NO HIDDEN ZONES UPDATE] (https://forums.alliedmods.net/showthread.php?t=309495)

HamletEagle 07-28-2018 07:30

ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
1 Attachment(s)
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

edon1337 07-28-2018 12:53

Re: ROG - A better random origin generator
 
Awesome job :up:
Also, I think you should mention that this value
PHP Code:

for(new 1<= 10000i++) 

can be reduced if you're not looking to find 500+ valid origins. It will reduce run-time of the plugin

EFFx 07-29-2018 09:03

Re: ROG - A better random origin generator
 
Tested a little, and got these feedbacks:

A check for de_mon map:

PHP Code:

if((fOrigin[2] <= -1000.0) || (fOrigin[2] >= 350.0)) 

Because it generates points under the map, if you guys didn't know, the de_mon map has another simple map under the original one. So with the <= -1000.0 it doesn't spawn entities there.
About the >= 350.0, it's generating points in the montains, which is bad, because players can drop there and camp forever.

The differences of the randomspawns that I found:

1. It has more checks for invalid points than the randomspawns
2. It generates the points more faster than the randomspawns
3. It generates more points than the randomspawns.

But, both generates goods and BADS points.

There are others maps with some blocked areas, like de_hotpoint and what I mentioned about the de_mon, it'll generate points there too. I don't know if there's a way to check that, but, that's a considerable issue.
That's my feedback for now...

de_mon simple map picture: http://prntscr.com/kce3zq

edon1337 07-29-2018 09:07

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by EFFx (Post 2606799)
Tested a little, and got these feedbacks:

A check for de_mon map:

PHP Code:

if((fOrigin[2] <= -1000.0) || (fOrigin[2] >= 350.0)) 

Because it generates points under the map, if you guys didn't know, the de_mon map has another simple map under the original one. So with the <= -1000.0 it doesn't spawn entities there.
About the >= 350.0, it's generating points in the montains, which is bad, because players can drop there and camp forever.

We're already aware of the outside areas and the hill sides. I made a stock that can be used in maps where the outside area is underground (such as de_mon). As for the 'mountains' I still don't have a solution.

PHP Code:

public Float:GetValidPoint( )  
{  
    new 
Float:fPoint];  
    
fPoint] = GetLowestPoint( );  

    
fPoint] += 10.0;  
    while( ( 
engfuncEngFunc_PointContentsfPoint ) == CONTENTS_SOLID ) || ( engfuncEngFunc_PointContentsfPoint ) == CONTENTS_WATER ) )  
    {  
        
fPoint] += 1.0;  
    }  
          
    new 
pcCurrent engfuncEngFunc_PointContents fPoint );  
          
    if( 
pcCurrent == CONTENTS_EMPTY )  
    return 
fPoint];  
          
    return 
0.0;  
}  

public 
Float:GetLowestPoint( )  
{  
    new 
pcCurrent;  
    new 
Float:fStartingOffset];  
      
    while( ( 
engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_SOLID ) || ( engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_WATER ) || ( engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_EMPTY ) )  
    {  
        
fStartingOffset] -= 5.0;   
    }  
      
    
pcCurrent engfuncEngFunc_PointContents fStartingOffset );   

    if( 
pcCurrent == CONTENTS_SKY )  
    return 
fStartingOffset];  
      
    return 
0.0;  


Usage
PHP Code:

new Float:fLowestPoint GetValidPoint( ); 

FYI, -350.0 is a non stuck-free origin in de_mon. ~ -420.0 is the minimum.

HamletEagle 07-29-2018 09:16

Re: ROG - A better random origin generator
 
About this "bad spots", from the point of view of the checks the points are fully valid, meaning a player can fit there without being stuck.
I tried to find a way to filter outside map areas or areas where the player can't get out but I failed.

So yeah, I don't know how we could filter out this points, because again, they are valid spots. Maybe we could run some kind of pathfinding algorithm and if it fails we could assume it's a bad spot and ignore this origin.
The downside is the execution time will be increased tremendously and such algorithms are not easy to implement.

edon1337 07-29-2018 09:21

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by HamletEagle (Post 2606804)
About this "bad spots", from the point of view of the checks the points are fully valid, meaning a player can fit there without being stuck.
I tried to find a way to filter outside map areas or areas where the player can't get out but I failed.

So yeah, I don't know how we could filter out this points, because again, they are valid spots. Maybe we could run some kind of pathfinding algorithm and if it fails we could assume it's a bad spot and ignore this origin.
The downside is the execution time will be increased tremendously and such algorithms are not easy to implement.

Is there any method on making an entity slide down if the place is steepy?

HamletEagle 07-29-2018 09:28

Re: ROG - A better random origin generator
 
Yes, with some knowledge about traceline and vectors you can do that.

edon1337 07-29-2018 09:31

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by HamletEagle (Post 2606810)
Yes, with some knowledge about traceline and vectors you can do that.

Then you got your answer how to do it without using pathfinding, these hills are all steepy. Though there's nothing in the forum about this..

HamletEagle 07-29-2018 09:34

Re: ROG - A better random origin generator
 
This would be a fix for a specific map. If we start creating custom code for every possible map we are not accomplishing anything.
If you guys need more checks for your mods you are free to modify the include in any way.

edon1337 07-29-2018 09:37

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by HamletEagle (Post 2606813)
This would be a fix for a specific map. If we start creating custom code for every possible map we are not accomplishing anything.
If you guys need more checks for your mods you are free to modify the include in any way.

I've never seen any hills in any other map, I think de_mon is the only one

EFFx 07-29-2018 09:39

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by edon1337 (Post 2606807)
Is there any method on making an entity slide down if the place is steepy?

I'm using movetype_toss and pev_gravity 1.0 here, and it does slide on steepy places.

Quote:

Originally Posted by edon1337 (Post 2606802)
We're already aware of the outside areas and the hill sides. I made a stock that can be used in maps where the outside area is underground (such as de_mon). As for the 'mountains' I still don't have a solution.

PHP Code:

public Float:GetValidPoint( )  
{  
    new 
Float:fPoint];  
    
fPoint] = GetLowestPoint( );  

    
fPoint] += 10.0;  
    while( ( 
engfuncEngFunc_PointContentsfPoint ) == CONTENTS_SOLID ) || ( engfuncEngFunc_PointContentsfPoint ) == CONTENTS_WATER ) )  
    {  
        
fPoint] += 1.0;  
    }  
          
    new 
pcCurrent engfuncEngFunc_PointContents fPoint );  
          
    if( 
pcCurrent == CONTENTS_EMPTY )  
    return 
fPoint];  
          
    return 
0.0;  
}  

public 
Float:GetLowestPoint( )  
{  
    new 
pcCurrent;  
    new 
Float:fStartingOffset];  
      
    while( ( 
engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_SOLID ) || ( engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_WATER ) || ( engfuncEngFunc_PointContentsfStartingOffset ) == CONTENTS_EMPTY ) )  
    {  
        
fStartingOffset] -= 5.0;   
    }  
      
    
pcCurrent engfuncEngFunc_PointContents fStartingOffset );   

    if( 
pcCurrent == CONTENTS_SKY )  
    return 
fStartingOffset];  
      
    return 
0.0;  


Usage
PHP Code:

new Float:fLowestPoint GetValidPoint( ); 

FYI, -350.0 is a non stuck-free origin in de_mon. ~ -420.0 is the minimum.

My check worked here, but I gotcha.

And Hamlet, I tried some checks here, but I failed too. I get back to my oldest and newbie spawn points. But i'll try to help everyone with this include, 'cos it worths.

edon1337 07-29-2018 09:42

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by EFFx (Post 2606816)
I'm using movetype_toss and pev_gravity 1.0 here, and it does slide on steepy places.

Try using that on entities that you're creating and see if it slides down the hills

EFFx 07-29-2018 09:51

Re: ROG - A better random origin generator
 
It slides here, but not on the montains, it slides on literally steepy places, here as example: http://prntscr.com/kcegra
Another one: http://prntscr.com/kcegwe

edon1337 07-29-2018 10:00

Re: ROG - A better random origin generator
 
Quote:

Originally Posted by EFFx (Post 2606821)
It slides here, but not on the montains, it slides on literally steepy places, here as example: http://prntscr.com/kcegra
Another one: http://prntscr.com/kcegwe

Aren't the hills as steepy as the first picture?

EFFx 07-29-2018 10:02

Re: ROG - A better random origin generator
 
Not that much.

HamletEagle 07-29-2018 12:28

Re: ROG - A better random origin generator[UPDATED]
 
Updated: now you can add your own conditions without editing the include to filter origins. Check the main post.

zmd94 08-20-2018 05:06

Re: ROG - A better random origin generator[UPDATED]
 
Nice, HamletEagle.

JocAnis 08-20-2018 09:45

Re: ROG - A better random origin generator[UPDATED]
 
if we use it, is there a chance the origin will be generated on the box, where player cant get there? for example: https://i.imgur.com/9kFIO95.jpg

edon1337 08-20-2018 09:54

Re: ROG - A better random origin generator[UPDATED]
 
Quote:

Originally Posted by JocAnis (Post 2611302)
if we use it, is there a chance the origin will be generated on the box, where player cant get there? for example: https://i.imgur.com/9kFIO95.jpg

Unfortunately, yes.

HamletEagle 08-20-2018 10:52

Re: ROG - A better random origin generator[UPDATED]
 
Quote:

Originally Posted by JocAnis (Post 2611302)
if we use it, is there a chance the origin will be generated on the box, where player cant get there? for example: https://i.imgur.com/9kFIO95.jpg

This type of boxes are easy to filter.

Garey 09-12-2018 16:17

Re: ROG - A better random origin generator[UPDATED]
 
About steep surfaces: You always can do something like that:
PHP Code:

         //Detect the floor, so we don't spawn the player in air
        
FloorOrigin[0] = RandomOrigin[0]
        
FloorOrigin[1] = RandomOrigin[1]
        
FloorOrigin[2] = -8192.0
        
        engfunc
(EngFunc_TraceLineRandomOriginFloorOriginDONT_IGNORE_MONSTERS00)
        
get_tr2(0TR_vecEndPosRandomOrigin)
        
get_tr2(0TR_vecPlaneNormalplaneNormal)
        
// If we hit a steep plane
        
if(planeNormal[2] < 0.7)
            continue; 


HamletEagle 01-17-2019 09:16

Re: ROG - A better random origin generator - NEW UPDATE
 
Update:
-made rog almost twice as fast as it was before. For example, in de_mon, it took 207ms to generate all the points, now it takes 100ms.
-previously it was 4.3x faster than superspawn, now it is 7.8x faster than SS.
-it generates the same amount of points, but in half the time it took before.

-added a check to prevent spawn points on top of entities(this should filter boxes like the ones from dust2 bombsite).
-added the same check that is used in regamedll for steep surfaces. If the ground is too step and the player would start sliding down, then that point will not be taken into account.

I have more updates planned, which should hopefully filter even more tricky points(like spawning in places that are too high).

JocAnis 01-17-2019 10:36

Re: ROG - A better random origin generator - NEW UPDATE
 
is it possible to prevent spawning player to 'weird' places on maps...like on awp_india (you have a room under the center of the map, where you cant go nowhere from it...i think thats the main problem (and only?) with this module

klippy 01-17-2019 11:04

Re: ROG - A better random origin generator - NEW UPDATE
 
You would need a to pathfind from the generated point to a player spawn point to verify that the generated spot is valid (that means it's in the playable area).

HamletEagle 01-17-2019 11:19

Re: ROG - A better random origin generator - NEW UPDATE
 
Quote:

Originally Posted by JocAnis (Post 2635158)
is it possible to prevent spawning player to 'weird' places on maps...like on awp_india (you have a room under the center of the map, where you cant go nowhere from it...i think thats the main problem (and only?) with this module

Read the previous replies. But yeah, it's what klippy said.
I want to keep it fast, and adding a pathfinding algorithm is against this purpose.
This is exactly why I added an option to define your own conditions for origins. Just get the origin of that room and tell rog to ignore it.

HamletEagle 02-16-2019 11:44

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
Update: added logic to prevent points from being generated inside hidden map zones(like the ones from de_mon/de_dust2/awp_india). I can not guarantee the algorithm is fail proof, so if you find a map where it doesn't work properly, please let me know so it can be fixed.

This should come with a minimal speed loss(few seconds in most maps) and with a decrease in generated points(firstly because hidden points are excluded and secondly because the algorithm will flag some valid points as being in a hidden area - mostly in indoor maps).
If you find a map where it generates an absurdly low amount of points also please let me know.

The benchmarks were not updated because I'm too lazy. I should update them soon.

NOVA GAMING 08-26-2020 03:05

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

Originally Posted by HamletEagle (Post 2639917)
Update: added logic to prevent points from being generated inside hidden map zones(like the ones from de_mon/de_dust2/awp_india). I can not guarantee the algorithm is fail proof, so if you find a map where it doesn't work properly, please let me know so it can be fixed.

This should come with a minimal speed loss(few seconds in most maps) and with a decrease in generated points(firstly because hidden points are excluded and secondly because the algorithm will flag some valid points as being in a hidden area - mostly in indoor maps).
If you find a map where it generates an absurdly low amount of points also please let me know.

The benchmarks were not updated because I'm too lazy. I should update them soon.


Sir , I find a Hidden Map zone in cs_assault (Original CS Map) , i was using ROG for my Teleport Machine plugin which teleport you To Some Origins

https://i.imgur.com/ZFjU2ro.jpg

HamletEagle 08-26-2020 05:52

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
This isn't exactly the type of "hidden zone" ROG was updated to detect. It detects mostly rooms under/above the map, not areas that are connected to the map but separated by an invisible wall.
As I said before, to filter these places properly we need to run a pathfinding algorithm and see if the zone can be reached or not. While a very inneficient version can be easily implemented, it will make the include extremely slow, probably to the point where it's unusable. Better implementations will require a module and a lot of work.

Natsheh 01-29-2021 15:36

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
I think the Float:MinDistance doesn't work quiet well, i tried spawn some boxes around the map and each box have 600.0 unit distance between the other, but it fails and spawns nearby.

Edit : I might give it a try and try to fix the code, but i don't promise anything :)

Edit #2: seems like the problem was caused because i was using the origin check function to insert valid origins, because the check distance function is after check function.

Natsheh 12-25-2021 06:21

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
1 Attachment(s)
If its possible to validate the origins and not spawn them outside of the maps for maps that have a skybox around the whole map,
and also if you can add a safety check for the player not spawn inside ( trigger_hurt, trigger_teleport, trigger_push )

Preview of the issue

Attachment 192788

HamletEagle 12-25-2021 06:53

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
As I said before, please attach the map so I can run tests.

Natsheh 12-25-2021 10:56

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

Originally Posted by HamletEagle (Post 2766881)
As I said before, please attach the map so I can run tests.

Here's the map example.

Natsheh 03-03-2022 15:40

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
Edit : Bad maps ( skybox around the whole map ) would rather not to be used.

Hellkong 02-06-2024 01:47

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
The latest version?

Natsheh 02-06-2024 12:49

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

Originally Posted by Hellkong (Post 2817532)
The latest version?

You can use this one its modified and it has been optimized...
Althought you need to save the data because its takes a while computing random origins around the map...

Hellkong 02-07-2024 11:42

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

Originally Posted by Natsheh (Post 2817562)
You can use this one its modified and it has been optimized...
Althought you need to save the data because its takes a while computing random origins around the map...

It's nicely written, thank you.

Why using engine and fakemeta both?

HamletEagle 02-08-2024 08:56

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

Originally Posted by Hellkong (Post 2817532)
The latest version?

The latest version is attached in the main post.

@Natsheh, I do not have time to check your file, but I find it contradictory that you claim it is optimized and at the same time claim it takes a long time to compute the random origins.

My version of ROG, the one from the main post, doesn't require caching, as the computation is very fast. Disabling the "no hidden zones" check (if you do not need it) will also make it much faster than it already is.

I should prepare an update and add a parameter to enable/disable the hidden zones check. In the meantime, if someone wants to do it quick and dirty, you can replace this code block:
PHP Code:

if(CheckPointsForVisibility(RandomOriginClosestOrigin))
{
    
IsVisible true


with this:

PHP Code:

IsVisible true 

(basically, remove the call to CheckPointsForVisibility)

georgik57 02-24-2024 05:25

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
Can this be used to generate spawns for maps with under 32?
Would eliminate the need for edited maps with 32 slot spawns.

Hellkong 02-24-2024 17:15

Re: ROG - A better random origin generator[NO HIDDEN ZONES UPDATE]
 
I tested this with 35hp map, and the spawns in the black hidden zone, not in the valid map, superspawns in the other hand spawns in the specific map

https://tsarvar.com/en/maps/counter-strike-1.6/35hp


All times are GMT -4. The time now is 22:24.

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