• 🏆 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!

Random Attack Position (Errr...look inside)

Status
Not open for further replies.
Level 22
Joined
Jun 23, 2007
Messages
3,242
Alright, so im fairly sure if you guys have played any other RTS, artillery behaves different since their projectiles dont usually land dead on their specified target, they often hit a random area in a small zone.
however, as we all know, wc3 units are always dead smack on target.
so how would i create random attack ground targets?
 
LOCATION[1] would be the random point. Change 90,90 to higher numbers to increase the AOE.
Be sure to remove the locations after using them.

  • Untitled Trigger 001
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Animate Dead
    • Actions
      • Set LOCATION[0] = (Target point of ability being cast)
      • Set LOCATION[1] = (Random point in (Region centered at LOCATION[0] with size (90.00, 90.00)))
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
I've got a feeling this wouldnt work for auto-attacking artillery units. wouldnt the the tank fire right BEFORE the trigger fires? or he might be dead on target the first hit, but the second shots will be off.
Could someone show me how to make an ability where whenever the tank is channeling the Bombard ability, dummies will appear at the tanks position every x seconds and attack ground in a random location at the point of ability being cast.
the only real problem ill really have is the loop, since i want it to be mui/mpi. and i have almost no knowledge in that.
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
you want it to auto attack random units or random spots?

if units
set temploc2 = position of triggering unit
set temploc = temploc2 offset by random number between 100 and 600
set tempgroup = random n units in range of temploc with matching conditions (your choice)
unit group pick

order "your unit" to attack picked unit

if it is about location you do the same but skip the temp group and just order your unit to attack ground on temploc2

DONT FORGOT THESE LINES AFTER

call removeLocation(udg_TempLoc)
call RemoveLocation(udg_TempLoc2)
call DestroyGroup(udg_TempGroup)
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
  • Tempest
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Tempest Artillery Tank
      • (Issued order) Equal to (Order(attackground))
    • Actions
      • Set TempPoint = (Target point of issued order)
      • Set TempPoint1 = (Random point in (Region centered at TempPoint with size (400.00, 400.00)))
      • Unit - Order (Triggering unit) to Attack Ground TempPoint1
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempPoint1)
ok heres what i got so far: problem is that the tank keeps firing at tempoint1 instead of firing at another random location
 
Level 22
Joined
Nov 14, 2008
Messages
3,256
that trigger leaks a region

if you want it to first at more point, make a loop

For each and every IntegerA 1 to "Amount you want to fire"
Loop

Also remember the Temppoint and custom script to remove temppoint should be outside the loop while temppoint1 and its custom script should be inside the loop!
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
hum, but since this is the units normal attack, he could fire on infinitely! what to do then?
ill try it out at the highest itll go and come back. tank-commander said he would do this, so ill check that out too when he finishes. but for now, ill try to do it on my own.

edit: o and where am i leaking a region? when i create on centered on temppoint?
edit2:
  • Tempest
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Tempest Artillery Tank
      • (Issued order) Equal to (Order(attackground))
    • Actions
      • Set TempPoint = (Target point of issued order)
      • For each (Integer A) from 1 to 9999999, do (Actions)
        • Loop - Actions
          • Set TempPoint1 = (Random point in (Region centered at TempPoint with size (400.00, 400.00)))
          • Unit - Order (Triggering unit) to Attack Ground TempPoint1
          • Custom script: call RemoveLocation(udg_TempPoint1)
      • Custom script: call RemoveLocation(udg_TempPoint)
this makes my map crash.
 
Last edited:
Level 22
Joined
Nov 14, 2008
Messages
3,256
yes and why it crashes, it is istantly performing 9999999 in a pico second or less and that is very ehum ...

if you want the unit to stop just add the line order unit to stop AFTER the loop and the loop will still fire all and stop after, and beware do not put it in the loop
 
Level 14
Joined
Aug 31, 2009
Messages
775
To do this, I'd use 2 different triggers.
  • Artillery Accuracy Randomiser
  • Events
    • Unit - A unit is attacked
  • Conditions
    • Unit type of (Attacking Unit) equal to <Your Artillery Unit>
  • Actions
    • Set TempLoc1 = (Position of (Triggering Unit))
    • Set TempLoc2 = TempLoc1 offset by (Random Real number between 0 and X) towards (Random Angle) degrees
    • Unit - Order (Attacking Unit) to Attack Ground TempLoc2
    • Custom script: call RemoveLocation(udg_TempLoc1)
    • Custom script: call RemoveLocation(udg_TempLoc2)
Set the Value of X to be whatever you want. Make it smaller to make the artillery more accurate.

For even more realism, change the value of X to be distance dependant.
For example, X could be
  • Set Point1 = Position of (Attacking Unit)
  • Set Point2 = Position of (Triggering Unit)
  • Set X = (Distance between Point1 and Point2) / 20.00
  • Custom script: Call RemoveLocation (udg_Point1)
  • Custom script: Call RemoveLocation (udg_Point2)
This would make your artillery much more accurate when shooting at closer ranges, but very inaccurate over a long distance. By dividing by twenty, the inaccuracy is scaled to 5% of the distance that is being fired. A reasonable scaler would be to replace the number 20 with anything between 15 and 40.

Then, in a separate trigger.
  • Stop Firing
  • Events
    • Time - Every Y seconds of Game Time
  • Conditions
  • Events
    • Set ArtilleryUnits = Units in (Playable Map Area) matching ((Current Order of (Matching Unit) equal to Order(attackground) and (Unit type of (Matching Unit)) equal to <Your Unit>))
    • Unit Group - Pick Every unit in ArtilleryUnits and Do (Actions)
      • Unit - Order (Picked Unit) to Stop
    • Custom script: call DestroyGroup(udg_ArtilleryUnits)
The value of Y should be just a tiny bit over the attack speed of your artillery units (eg. 0.03 seconds longer). If you have multiple types of artillery, you should make a trigger for each to avoid them being unable to attack due to being ordered to stop.

EDIT: Made it leak free also, for completion purposes.

The main problem with this method however is that the inaccuracy can be bypassed by specifically telling your units to attack ground at the position of the enemies, thereby bypassing the inaccuracy trigger. However, it will only fire once at that accuracy, due to the stop trigger.
 
Try these.. (Even though they leak a *Sigh* Rect)

  • Events
    • Trigger - Turn off (This trigger)
    • Set TempPoint = (Target point of issued order)
    • Set TempPoint1 = (Random point in (Region centered at TempPoint with size (400.00, 400.00)))
    • Unit - Order (Triggering unit) to Attack Ground TempPoint1
    • Custom script: call RemoveLocation(udg_TempPoint1)
    • Custom script: call RemoveLocation(udg_TempPoint)
    • Trigger - Turn on This Trigger
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
alright thanks guys.
@ Damage - Couldnt I just change all the variables to something like point of issued order, and for event unit is issued order, condition issued order equal to attackground

@ikillforyou - alright ill try that out
 
Level 14
Joined
Aug 31, 2009
Messages
775
No, because the unit would just keep on being told to shoot again and again and loop endlessly.

If for example, I shoot at the location 0,0 it will offset it to say, 0,50 and order the artillery to fire there. Then, it will offset that to something else, like -25,35, and it will continue to offset again and again. The unit would be stuck in an endless loop of orders - this is bad of course.

I can't off the top of my head, think of a way to remove the specific order to allow attack ground.
However, making the unit classified as a "Ward" will remove all the buttons from the unit's interface (Such as move, patrol, attack etc.) but it will still be moveable and orderable by right clicking and it WILL still auto attack enemies as a normal unit.

EDIT:
Do NOT use the method that ikillforyou uses, as there is a Region leak.
Change the line that reads
  • Set TempPoint1 = (Random point in (Region centered at TempPoint with size (400.00, 400.00)))
to instead read:
  • Set TempPoint1 = TempPoint offset by (Random Real number between 0 and X) towards (Random Angle) degrees
Not only that, but using a square region to define an AoE is very poor - it is a square area afterall. Whereas my method defines a circular area, which is what we want.
Also, Turning on and off the trigger in his trigger does absolutely nothing, as it is turned on and off instantly.
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
u can just change the attack type of the unit to get rid of the attack ground ability. only Artillery attack type units gain attack ground. However, i want players to be able to attack in to fog of war, which either requires an ability that acts like attack ground that fires randomly in an area, or attack ground itself firing randomly.
 
Level 14
Joined
Aug 31, 2009
Messages
775
If you make the unit not able to attack ground, then the attack ground order wouldn't work.... obviously.

You could also just base the ability on something like Blizzard, and remove all damage/effects from it, and run the trigger to randomise the attack from there on.
 
Level 22
Joined
Jun 23, 2007
Messages
3,242
this does not work:
  • Tempest
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Tempest Artillery Tank
    • Actions
      • Set TempPoint = (Position of (Attacked unit))
      • Set TempPoint1 = (TempPoint offset by (Random real number between 0.00 and TempestRandomAttackX) towards (Random angle) degrees)
      • Set TempestPoint1 = (Position of (Attacking unit))
      • Set TempestPoint2 = (Position of (Attacked unit))
      • Set TempestRandomAttackX = ((Distance between TempestPoint1 and TempestPoint2) / 30.00)
      • Unit - Order (Attacking unit) to Attack Ground TempPoint1
      • Custom script: call RemoveLocation(udg_TempPoint1)
      • Custom script: call RemoveLocation(udg_TempPoint)
      • Custom script: call RemoveLocation(udg_TempestPoint1)
      • Custom script: call RemoveLocation(udg_TempestPoint2)
the unit fails to attack ground when ordered to. removing the artillery attack type would also remove it's ability to attack ground. suggestions?
 
Status
Not open for further replies.
Top