| 03-19-2009, 10:09 AM | #1 |
Im trying to get some random spawns in my map, but I dont want them to ever be to close to each other so is there a way to spawn units with something like random point in region but not within 400range of any other unit |
| 03-19-2009, 01:06 PM | #2 |
How often are you spawning? You could make a custom region on the fly that it is the entire spawn area minus regions defined by proximity to existing units. Maybe, in theory anyway. Moving you to the triggering forum. |
| 03-19-2009, 01:36 PM | #3 | |
Quote:
If it is just a single unit then you can do something like JASS:loop set x = pickRandomX() set y = pickRandomX() exitwhen {unit is not in range of x,y} endloop For more units you can do: JASS:loop set x = pickRandomX() set y = pickRandomX() set i=0 good = true loop exitwhen (i== N) or not good if { unit[i] is in range of x,y } then good=false endif set i=i+1 endloop exitwhen (good) endloop However, always make sure there are at least as much valid points than invalid points, else this code will take a while... (The expected number of tries is (P+1)/P where P is the probability to find a valid point. With P>=0.5 , that's a breeze. Also, if there are a lot of units, like 50, it might be too slow for a periodic event. Let me think for a while on how to solve it later... |
| 03-19-2009, 08:10 PM | #4 |
anyway to do it in gui? I dont know JASS It happens basicly at the start of a game or every few zones. Basicly when the map starts im creating a bunch of random units all over the map in my rpg. Right now however sometimes to many units get clusted then one part of the map looks empty so Im just trying to get stuff more spread out but still random |
| 03-19-2009, 08:49 PM | #5 |
It isn't really Jass, it is pseudocode. More spread out? You could divide the map in n section and make sure to create one random unit per section. |
| 03-20-2009, 01:25 AM | #6 |
Dreadfully inefficient compared to the methods described above, but I think it achieves the most authentic effect. Killing and removing the unit happens instantaneously, so it won't show up on the map at all; for all intents and purposes, it wasn't there. The "Pick every unit" function only does anything if there's at least one unit of the type described in range, so it shouldn't kill every unit that's created. If there's hiccups, let me know... |
| 03-20-2009, 03:12 AM | #7 |
That's actually pretty awful. Is there an actual reason to trust it on a trigger running periodically rather than just call the trigger after creating the unit? There isn't a lot of sense in actually doing this after the unit was created...You could just prevent creating it whatseover.. |
| 03-25-2009, 05:37 AM | #10 |
CreateLoneUnit: StartingCreeps: And here's where waits become a problem. Since you're using GUI, not JASS, you can't use more than one local variable - and here you need two. I can write you a global JASS function, but then you'd have to call it with a custom script. I lack the skill and knowledge to make a self-contained trigger that does all the things you'd want. If you're comfortable with that... Okay, here's the JASS script. Copy and paste it into your "global functions" section (the "trigger" in the Trigger Editor that has the same name as the map). JASS:globals constant real DISTANCE = 400.00 // Minimum distance between two spawned creeps constant player ENEMY = Player(5) // Enemy player. Player(5) is actually Player 6 (orange). endglobals // Do not change anything below this comment or ELSE. function StupidBoolExprFy takes nothing returns boolean return IsUnitOwnedByPlayer(GetFilterUnit(),ENEMY) endfunction function CreateLoneUnit takes rect spawnRegion, integer spawnUnit returns nothing local real xPos = GetRandomReal(GetRectMinX(spawnRegion),GetRectMaxX(spawnRegion)) local real yPos = GetRandomReal(GetRectMinY(spawnRegion),GetRectMaxY(spawnRegion)) local group otherUnits = null call GroupEnumUnitsInRange(otherUnits,xPos,yPos,DISTANCE,Filter(function StupidBoolExprFy)) if otherUnits == null then call CreateUnit(ENEMY,spawnUnit,xPos,yPos,bj_UNIT_FACING) else call CreateLoneUnit(spawnRegion, spawnUnit) endif call DestroyGroup(otherUnits) return endfunction function CreateLoneUnitWait takes rect spawnRegion, integer spawnUnit, real duration returns nothing if duration > 0 then call PolledWait(duration) endif call CreateLoneUnit(spawnRegion, spawnUnit) return endfunction ReplaceCreeps: ReplaceCreepsStartingCreeps: (((waits for Vexorian [or worse, *not* Vexorian] to pick this apart))) |
