• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

What's wrong with this code?

Status
Not open for further replies.
I'm making a random distance and rotation System for Catapults(probably other things, too...) and have made this code for the Attack ability(Yes, I have a custom dummy-ability for that.) It's supposed to make it attack at a random distance infront of itself, but instead it just moves a little around, looking really wierd.
Here's the code:
  • Attack
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Forward Attack
    • Actions
      • Unit - Order (Triggering unit) to Attack Ground ((Position of (Triggering unit)) offset by (Random real number between 300.00 and 2000.00) towards (Facing of (Triggering unit)) degrees)
Got any idea about what's wrong?
 

Rui

Rui

Level 41
Joined
Jan 7, 2005
Messages
7,550
Your map will lag in time, as that trigger is leaking. You should use variables (and maybe locals) in order to get it to de-leak it.

Also, I'm not surprised that the ability doesn't work. Triggering Unit is referring to the caster, not the target, thus the catapult is trying to attack-ground itself, and it can't, due to the Minimum Range. The target should be Target Unit of Ability Being Cast.
[TRIGGER=As I said previously, you're leaking a location. Here's a way to destroy the leak]
Set PointVariable = Position of (Target unit of ability being cast)
Unit - Order (Triggering unit) to Attack Ground PointVariable offset by (Random real number between 300.00 and 2000.00) towards (Facing of (Triggering unit)) degrees)
Custom script: call RemoveLocation(udg_PointVariable)
[/TRIGGER]
 
Rui, you don't udnerstand.
I'm using a "Dummy Ability" to activate "Attack Ground" at the target I'm specifying through triggers...
Here's a screenhot of my abilities for the Catapult, yes that's the one I want to have a random attack distance...
 

Attachments

  • Screenie.jpg
    Screenie.jpg
    104.1 KB · Views: 137
Rui, you don't udnerstand.
I'm using a "Dummy Ability" to activate "Attack Ground" at the target I'm specifying through triggers...
Here's a screenhot of my abilities for the Catapult, yes that's the one I want to have a random attack distance...

That is really odd. Can the catapult shoot at a minimum range of 300?

Your map will lag in time, as that trigger is leaking. You should use variables (and maybe locals) in order to get it to de-leak it.

Also, I'm not surprised that the ability doesn't work. Triggering Unit is referring to the caster, not the target, thus the catapult is trying to attack-ground itself, and it can't, due to the Minimum Range. The target should be Target Unit of Ability Being Cast.
  • Set PointVariable = Position of (Target unit of ability being cast)
  • Unit - Order (Triggering unit) to Attack Ground PointVariable offset by (Random real number between 300.00 and 2000.00) towards (Facing of (Triggering unit)) degrees)
  • Custom script: call RemoveLocation(udg_PointVariable)

There is also the not widely known offset leak. Offset actually leaks, the JASS equivalent is PolarProjectionBJ:
JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction

Since it returns location, it gives you a location which leaks. This is not widely known, but can be fixed by doing this:
  • Trigger
    • Events
    • Conditions
    • Actions
      • Set Loc = Position of (Triggering Unit)
      • Set Offset = Loc offset by (Random real number between 300.00 and 2000.00) towards (Facing of (Triggering unit)) degrees)
:wink:

Rui and I were just telling you what leaks.
 
Well, I've changed to code to this:
  • Attack
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Forward Attack
    • Actions
      • Set TriggeringUnit = (Triggering unit)
      • Wait 0.01 seconds
      • Set Target = ((Position of TriggeringUnit) offset by (Random real number between 300.00 and 2000.00) towards ((Facing of TriggeringUnit) + (Random real number between -6.00 and 6.00)) degrees)
      • Wait 0.01 seconds
      • Unit - Order TriggeringUnit to Attack Ground Target
Now it attacks at the right spot, but just before it does that, it kinda teleports a little down and left:
__________
¤¤¤¤¤¤CB¤¤|
¤¤¤¤¤¤¤¤¤¤|
¤¤CA¤¤¤¤¤¤|
~~~~~~~~
CB=Catapult Before
CA=Catapult After

Does anyone know what may be causing this?
 
I've discovered it's the Collision size that's making it move when it casts that ability. Why, I don't know, but I've set the collision size to "0", so it works fine now... Looks a bit ugly, but...
I've also added a dummy-unit as a "Catapult-Controller" Makes the turning and attacking abilities much more visible and it fixed a bug I had with the player beeing able to press "Attack ground" and pick the target they wanted to attack without the turning abilities...
I attached a screenie of the Catapult-Controller's abilities.
 

Attachments

  • Screenie.jpg
    Screenie.jpg
    105.4 KB · Views: 154
Status
Not open for further replies.
Top