• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Creating units on non-visible areas

Status
Not open for further replies.
Level 23
Joined
Oct 20, 2012
Messages
3,075
Hey! you might not understand the title so here's a bit of an explanation on what I want to do.

I wanted to make a spell that will be able to target an enemy unit. The effect would be that the target unit, upon being buffed by the spell, will be periodically bombarded by suicidal ghosts that appear from the shadows.

Basically, I want to create units on areas that are not visible to enemies, allies or the target itself, and then order it to move towards the target and self destruct. (like using KABOOM on the target unit) These created units will not provide vision to its owner and the spell should be MUI.

So could you guys give me any idea on how I should be able to do the unit creation part? I have absolutely no idea how to start making such a spell.
 
You can use this snippet to check if a coordinate is visible.
http://www.hiveworkshop.com/forums/submissions-414/snippet-ispointvisible-249573/#post2501474


A possible approach to this

JASS:
function CreateRandomSuicideUnit takes integer unitID, unit target, player owner returns unit
   local unit u = CreateUnit(unitID, owner, GetUnitX(target), GetUnitY(target), 0)
   local integer i = 0
   call SetUnitPosition(u, GetUnitX(u)+GetRandomReal(-3000, 3000), GetUnitY(u)+GetRandomReal(-3000,3000))
   loop
      if IsUnitVisible(u, GetOwningPlayer(target)) then
         call SetUnitPosition(u, GetUnitX(u)+GetRandomReal(-3000, 3000), GetUnitY(u)+GetRandomReal(-3000,3000))
      else
         exitwhen true
      endif
      exitwhen i > 20
      set i = i + 1
   endloop
   return u
endfunction
When you use this function, it should create the unit outside of visibility in most cases. However, there's a slight chance the unit will spawn within sight (as it only tries 20 times to find a spot).

You still need to order the unit to attack or use your kaboom ability; this will only handle the spawning.
 
Last edited:
Level 23
Joined
Oct 20, 2012
Messages
3,075
Every so often, pick random points and check if they're visible with the boolean comparison "Visibility - Point Visible to Player".

You can use this snippet to check if a coordinate is visible.
http://www.hiveworkshop.com/forums/submissions-414/snippet-ispointvisible-249573/#post2501474


A possible approach to this

JASS:
function CreateRandomSuicideUnit takes integer unitID, unit target, player owner returns unit
   local unit u = CreateUnit(unitID, owner, GetUnitX(target), GetUnitY(target), 0)
   local integer i = 0
   call SetUnitPosition(u, GetUnitX(u)+GetRandomReal(-3000, 3000), GetUnitY(u)+GetRandomReal(-3000,3000))
   loop
      if IsUnitVisible(u, GetOwningPlayer(target)) then
         call SetUnitPosition(u, GetUnitX(u)+GetRandomReal(-3000, 3000), GetUnitY(u)+GetRandomReal(-3000,3000))
      else
         exitwhen true
      endif
      exitwhen i > 20
      set i = i + 1
   endloop
   return u
endfunction
When you use this function, it should create the unit outside of visibility in most cases. However, there's a slight chance the unit will spawn within sight (as it only tries 20 times to find a spot).

You still need to order the unit to attack or use your kaboom ability; this will only handle the spawning.

Oh right, I forgot about that function. Though I still need to narrow it down to creating the unit within 1000 area of the target. Thanks. ^^

Zwiebelchen, I only understand a fraction of that thing but I'll try. ^^

Give them permanent invisiblity when spawning that you remove after a few seconds?

I wanted to give the illusion that the units are from somewhere at first then just move towards the target. I don't want them to appear from nothing out of nowhere. Thanks for trying though.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,207
Units can have up to 1800 (or was it 1600?) sight radius if I recall. Checking within that will mostly fail, especially if the unit is air based.

How I would do it...
Code:
Pick a random angle.
For every point 128 units apart towards the random angle from the victim unit up to 2400 units.
    If point is visible create ghost, do whatever and stop executing.
Repeat the above a couple of times if it fails but do be aware such tests are likely expensive so the numbed of tries should be small. Instead of a fully random angle, you could spread them out a bit based on the number of tries so that they are more distributed (no chance that it will repeat trying the same angle).

The optimum approach would be to brute force testing all tiles around the target in a staggered fashion to distribute computational load. This could potentially give optimum results, finding even the smallest unseen area such as behind a tree with relative ease.
 
Status
Not open for further replies.
Top