AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Find proper origin to spawn. (https://forums.alliedmods.net/showthread.php?t=146763)

Jacob 12-31-2010 23:35

Find proper origin to spawn.
 
PHP Code:

new ent create_entity("info_target")
entity_set_origin(entorigin)
... 

my question is that if spawn 5 or more ents when round start,how to make sure the distance between two ents is more than 500,if distance<500,then make a loop to find another origin to spawn till find a proper one.
thanks in advance.

Elusive138 01-01-2011 03:00

Re: Find proper origin to spawn.
 
You can use if (get_distance_f(origin1, origin2) < 500.0) and get a new origin, or some variation.

Jacob 01-01-2011 03:11

Re: Find proper origin to spawn.
 
Quote:

Originally Posted by Elusive138 (Post 1383520)
You can use if (get_distance_f(origin1, origin2) < 500.0) and get a new origin, or some variation.

please show the full example.

Exolent[jNr] 01-01-2011 03:50

Re: Find proper origin to spawn.
 
Show your full code in getting the first original origin.

Jacob 01-01-2011 04:23

Re: Find proper origin to spawn.
 
Quote:

Originally Posted by Exolent[jNr] (Post 1383536)
Show your full code in getting the first original origin.

i tested the RuneMod plugin today, found that sometimes two or three runes spawned at a same location,so i thought this part of code is not that good.

PHP Code:

new EntNum SpawnRune(RuneIndex,g_SpawnOrigin[SpawnPoint]) // We spawn the rune
    
new LocStatus CheckDistance(EntNum,SpawnPoint)     // We check the the Spawn location the rune was spawned at, and 
    
    
if(LocStatus == 2)   // This means the newly spawned rune was to close to 1 of the other runes. We now try 5 random other locations to see if their free
    
{
     new 
CPS=0   // Just incase, we will only check 5 diffrent spawn locations
     
while( LocStatus == && CPS 5)
     {
      
CPS++
      
SpawnPoint random_num(1,g_NumberOfSpawnPoints)
      
LocStatus CheckDistance(EntNum,SpawnPoint)
     }
     
set_origin(EntNum,g_SpawnOrigin[SpawnPoint])
    } 

PHP Code:

stock CheckDistance(EntNum,IndexInSpawnArray)  // This stuck is used to check the distance between where a rune is spawned, and the other runes ingame. To make sure their not spawned to close together
{
 new 
Origin[3]
 for(new 
i=0;i<=MAX_RUNESINGAME;i++) if(g_RuneEntNum[i][0] && g_RuneEntNum[i][0] != EntNum)
 {
  
get_origin(g_RuneEntNum[i][0],Origin)
  if(
get_distance(Origin,g_SpawnOrigin[IndexInSpawnArray]) < MIN_DISTANCE_BETWEEN_RUNES)
  {
   return 
2
  
}
 }
 return 
1



Exolent[jNr] 01-01-2011 04:36

Re: Find proper origin to spawn.
 
Change MIN_DISTANCE_BETWEEN_RUNES to 500.

Also, if there are runes at all 5 origins that are checked first, the plugin will not continue to check for an empty one.

Jacob 01-02-2011 01:37

Re: Find proper origin to spawn.
 
Quote:

Originally Posted by Exolent[jNr] (Post 1383545)
Change MIN_DISTANCE_BETWEEN_RUNES to 500.

Also, if there are runes at all 5 origins that are checked first, the plugin will not continue to check for an empty one.

thanks!


All times are GMT -4. The time now is 02:04.

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