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

Auto-casting AoE on Ground?

Status
Not open for further replies.
Level 6
Joined
Aug 12, 2007
Messages
201
Here are the four tentatively final triggers I am about to test:

  • Catapult Attack Enemies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Not equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Set Attack_loc = (Position of (Attacked unit))
      • Unit - Order (Attacking unit) to Human Mortar Team - Flare Attack_loc
      • Custom script: call RemoveLocation(udg_Attack_loc)
      • Wait 1.00 seconds
      • Custom script: call IssueImmediateOrder(u,"stop")
  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: loop
      • Custom script: call IssuePointOrder(u,"flare",GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
      • Wait 5.00 seconds
      • Custom script: exitwhen GetUnitCurrentOrder(u) == OrderId("move") or GetUnitCurrentOrder(u) == OrderId("holdposition")
      • Custom script: endloop
  • Catapult Attack Ground
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Issued order) Equal to (Order(attackground))
      • (Unit-type of (Triggering unit)) Equal to Catapult
    • Actions
      • Custom script: local real x = GetOrderPointX()
      • Custom script: local real y = GetOrderPointY()
      • Custom script: loop
      • Custom script: call IssuePointOrder(GetTriggerUnit(), "attackground", x+GetRandomReal(-256,256),y+GetRandomReal(-256,256))
      • Wait 5.00 seconds
      • Custom script: exitwhen GetUnitCurrentOrder(GetTriggerUnit()) != OrderId("attackground")
      • Custom script: endloop
  • Catapult Channel
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to CatapultChannel
    • Actions
      • Custom script: call IssuePointOrder(GetTriggerUnit(), "attackground", GetSpellTargetX()+GetRandomReal(-256,256),GetSpellTargetY()+GetRandomReal(-256,256))
      • Wait 1.00 seconds
      • Unit - Order (Triggering unit) to Stop
See any issues?

Well there is one immediate issue. Ordering it to attack ground causes it to shoot three random locations nowhere near where I attack grounded, and then it crashed Warcraft 3 with a fatal error message. :confused:

EDIT: After roughly three shots at all it immediately crashes Warcraft 3 with a fatal error. It doesn't shoot anywhere near (-256,256), more like any point on the map it feels like. I actually had a problem like this before, wherein getting a real and using it directly was causing it to shoot totally random far off locations, but doing this:
  • Unit - Order CatapultTarget to Attack Ground (Attack_loc offset by ((Real(RandomAttackX)), (Real(RandomAttackY))))
Getting two Integers and then converting them to Reals solved it from shooting really far off for no reason. Don't know how to do this in code like this, nor whether or not this will prevent is from fatal erroring to the desktop.
 
Level 6
Joined
Aug 12, 2007
Messages
201
It crashes in every type of attack so should I do that in every trigger around that part? And did you read what I edited in above about converting from integers because that solved my shooting really far away problem before. It didn't make things crash then though.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Sorry, forgot to fix the other one:

This will fix the crash:

  • Catapult Attack Ground
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Issued order) Equal to (Order(attackground))
      • (Unit-type of (Triggering unit)) Equal to Catapult
    • Actions
      • Custom script: local real x = GetOrderPointX()
      • Custom script: local real y = GetOrderPointY()
      • Custom script: loop
      • Trigger - Turn Off (This Trigger)
      • Custom script: call IssuePointOrder(GetTriggerUnit(), "attackground", x+GetRandomReal(-256,256),y+GetRandomReal(-256,256))
      • Trigger - Turn On (This Trigger)
      • Wait 5.00 seconds
      • Custom script: exitwhen GetUnitCurrentOrder(GetTriggerUnit()) != OrderId("attackground")
      • Custom script: endloop
  • Catapult Channel
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to CatapultChannel
    • Actions
      • Trigger - Turn off (Catapult Attackground)
      • Custom script: call IssuePointOrder(GetTriggerUnit(), "attackground", GetSpellTargetX()+GetRandomReal(-256,256),GetSpellTargetY()+GetRandomReal(-256,256))
      • Trigger - Turn On (Catapult Attackground)
      • Wait 1.00 seconds
      • Unit - Order (Triggering unit) to Stop
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
It crashes in every type of attack so should I do that in every trigger around that part? And did you read what I edited in above about converting from integers because that solved my shooting really far away problem before. It didn't make things crash then though.
The shooting really far away is because 256 is a huge offset, to be honest. Try reducing the offset to GetRandomReal(-100,100)
 
Level 6
Joined
Aug 12, 2007
Messages
201
I am confused how 256 is a huge offset though, I meant a regular Footman can hit 100 away from itself, so I figured a total distance of 512 wouldn't be a whole lot. Does a real function differently or something? Currently it can shoot up to 1200 away so I don't see how 256 should be a large difference. Maybe this is why getting an integer and converting it to a real made it shoot a much less distance because an integer is more in line with what the system says when a footman can hit 100 away while a real is like some other value entirely?

EDIT: It stopped firing crazy far away now after I added your turn off this triggers, not sure why, but now two new problems have occurred. Its a building so when attacking my own troops I can't tell it to move or to hold position to stop firing because it can't move. And the second bug is now whenever I tell it to attack ground, it will fire on the same spot two to three times, then get a new location, and repeat two or three more times, etc. This is the only time it does this, all others get a new location after each shot.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Think of an integer like a fake number. An integer cannot have decimals, which is not realistic because in real life there is an infinite number of decimals you can have.

Think of a real number as... guess...

So the fact that you have different results applying integers than applying real numbers is not tangible. There is no difference with the math.

However, looking at it, there is no problem using integers instead of reals in any of these codes. Just change all the GetRandomReal(-256,256) into GetRandomInt(-256,256) and, if it gets the job done, more power to you.
 
Level 6
Joined
Aug 12, 2007
Messages
201
Think of an integer like a fake number. An integer cannot have decimals, which is not realistic because in real life there is an infinite number of decimals you can have.

Think of a real number as... guess...

So the fact that you have different results applying integers than applying real numbers is not tangible. There is no difference with the math.

However, looking at it, there is no problem using integers instead of reals in any of these codes. Just change all the GetRandomReal(-256,256) into GetRandomInt(-256,256) and, if it gets the job done, more power to you.

I took math in highschool so I now how Integers and Reals work, I was just wondering if Warcraft did something different with them. It stopped shooting really far away now anyways after I added the two Turn On and Off parts, but now its acting funny in different ways.

EDIT: Unchecking that option didn't do anything, but I figured out it is doing it exactly twice. It fires on XY, then fires on XY again, then it changes to a new spot, fires on that XY, fires on that XY again, etc. I think I might know what is wrong with it though. Testing it.

Managed to fix it myself for a change! I was using a wait of 5.00 but I forgot it still had a firing cooldown of 2.50, so it was managing two shots before it updated the spot to shoot at.
 
Level 6
Joined
Aug 12, 2007
Messages
201
I set it up like that but now it is back to firing once and then stopping on its own with no loop, Maybe if the u,1 value is 0 instead of 1, and with the rest of it all reversed?
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
That was happening because as soon as he finishes flare, he automatically stops. So I added a wait which you can adjust (Depending on how long it takes flare to cast).

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: loop
      • Custom script: call IssuePointOrder(u,"flare",GetUnitX(GetTriggerUnit()),GetUnitY(GetTriggerUnit()))
      • Wait 1.00 seconds
      • Custom script: call SetUnitUserData(u,1)
      • Wait 1.50 seconds
      • Custom script: exitwhen GetUnitUserData(u) != 1
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
I'm not sure what times to set where because even with that no matter how long or short a wait in either of those waits or how long a cooldown I give Channel, it still only fires once and then stops. Which variable is supposed to coincide with which to get it to keep shooting?
 
Level 6
Joined
Aug 12, 2007
Messages
201
With 0 on both it immediately casts both channel and fires on the unit, then after a few seconds it casts channel again, doesn't fire on the unit though and goes back to the default no target angle cannon towers have when they are built.

That is with the waits of 1 and 1.5 you had in the trigger, not any of the values I experimented with.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
If I understand you correctly, this should solve:

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: call IssueImmediateOrder(u,"stop")
      • Wait - 0.00 seconds
      • Custom script: loop
      • Custom script: call IssuePointOrder(u,"flare",GetRandomInt(-256,256)+GetUnitX(GetTriggerUnit()),GetRandomInt(-256,256)+GetUnitY(GetTriggerUnit()))
      • Wait 1.00 seconds
      • Custom script: call SetUnitUserData(u,1)
      • Wait 1.50 seconds
      • Custom script: exitwhen GetUnitUserData(u) != 1
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
This time it attacked/cast channel, waited for a second, cast channel again and aimed it's cannon tower top as if it were going to attack but didn't fire, and then it goes back to the default position after that with no more channel.

Maybe something I did messed it up, just in case I'll put my map file again. I might have set or changed a wait I wasn't supposed to possibly.

Like when I said before that my timers were 5.00 and my attack cooldown was 2.5, I set the attack to 5.00 the way I intended, not the other way around if that effects anything.
 

Attachments

  • InaccurateCatapultBribesCodeNew.w3x
    20.8 KB · Views: 55

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Yeah... try it out like this:

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: local unit v = GetTriggerUnit()
      • Custom script: call IssueImmediateOrder(u,"stop")
      • Custom script: loop
      • Custom script: call IssuePointOrder(u,"flare",GetRandomInt(-256,256)+GetUnitX(v),GetRandomInt(-256,256)+GetUnitY(v))
      • Wait 1.00 seconds
      • Custom script: call SetUnitUserData(u,1)
      • Wait 1.50 seconds
      • Custom script: exitwhen GetUnitUserData(u) != 1
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
Still the exact same effect of shoot/channel, channel/aim, maybe there is something wrong with the channel code instead of this one?

This is what it looks like now:

  • Catapult Channel
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to CatapultChannel
    • Actions
      • Trigger - Turn off Catapult Attack Ground <gen>
      • Custom script: call IssuePointOrder(GetTriggerUnit(), "attackground", GetSpellTargetX()+GetRandomReal(-256,256),GetSpellTargetY()+GetRandomReal(-256,256))
      • Trigger - Turn on Catapult Attack Ground <gen>
      • Wait 5.00 seconds
      • Unit - Order (Triggering unit) to Stop
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Well, I imagine you want to keep using flare, right? Or do you want it to attack ground on your allies now?

Here, this one final test to try to get "flare" working right. If it fails, let me know.

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: local unit v = GetTriggerUnit()
      • Wait - 0.00 seconds
      • Custom script: call IssueImmediateOrder(u,"stop")
      • Wait - 0.00 seconds
      • Custom script: loop
      • Custom script: call IssuePointOrder(u,"flare",GetRandomInt(-256,256)+GetUnitX(v),GetRandomInt(-256,256)+GetUnitY(v))
      • Wait 1.50 seconds
      • Custom script: call SetUnitUserData(u,1)
      • Wait 1.00 seconds
      • Custom script: exitwhen GetUnitUserData(u) != 1
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
Sadly no change with that trigger either. I'm not 100% sure what the channel/flare is doing at this point anymore really, it just seems to be cast for the sake of being cast, the damage and everything comes directly from the attack.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Well change the missile art of the tower to the flare missile art if you like, and do this:

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • (Unit-type of (Attacking unit)) Equal to Catapult
      • (Owner of (Attacking unit)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetAttacker()
      • Custom script: local unit v = GetTriggerUnit()
      • Custom script: loop
      • Trigger - Turn off Catapult Attack Ground
      • Custom script: call IssuePointOrder(u, "attackground", GetUnitX(v)+GetRandomInt(-256,256),GetUnitY(v)+GetRandomInt(-256,256))
      • Trigger - Turn on Catapult Attack Ground
      • Wait 2.50 seconds
      • Custom script: exitwhen GetUnitCurrentOrder(u) != OrderId("attackground")
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
Flare was only ever just the string I was using to fire Channel, there is no real flare-ing at all going on. I'll try that one now.
So this turns regular attack commands into attack grounds on your own troops? It did fix it in that he continues to shoot over and over, but at the starting location since it is now an attack ground. I am a little sad at the loss of it being able to track the own unit as if it were an enemy unit.
 
Level 6
Joined
Aug 12, 2007
Messages
201
No no not auto attack, I mean like if you manually tell your tower to attack your own people, right now it doesn't keep attacking them like it would if this were a real unit and not made to be this way with triggers, it turns the command into an attack ground and targets there instead.
 
Level 6
Joined
Aug 12, 2007
Messages
201
Well what do you want to do? haha, if you change it back then you won't be able to add the poor accuracy. It's either attack-point or attack-unit, but when you attack-unit you cannot adjust the attack-offset.

Well, not being able to attack your own guys is not a huge problem, since odds are most players won't target themselves anyways.

I am blown away by the amount of effort involved to make an attack miss. Trust the game to have perfect accuracy no problem, but it takes six pages of posts and five individual triggers full of custom scripts to make it miss.

Thanks for all the effort you put into this, it was a real help, I know I couldn't do 1/1000 of the custom scripts you showed me here today.
 

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
This should solve all your problems. Sometimes it will attack the unit directly, sometimes it will attack the ground and hope to hit it.

  • Catapult Attack Allies
    • Events
      • Unit - A unit Is issued an order targetting an object
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Catapult
      • (Owner of (Target unit of Issued Order)) Equal to (Owner of (Triggering unit))
    • Actions
      • Custom script: local unit u = GetTriggerUnit()
      • Custom script: local unit v = GetOrderTargetUnit()
      • Custom script: loop
      • If (All Conditions are true) then do (then actions) else do (else actions)
        • Conditions
          • (random integer between 1 and 10) greater than 5)
        • Then - Actions
          • Trigger - Turn Off (this trigger)
          • Custom script: call IssueTargetOrder(u,"attack",v)
          • Trigger - Turn on (this trigger)
        • Else - Actions
          • Trigger - Turn off Catapult Attack Ground
          • Custom script: call IssuePointOrder(u, "attackground", GetUnitX(v)+GetRandomInt(-256,256),GetUnitY(v)+GetRandomInt(-256,256))
          • Trigger - Turn on Catapult Attack Ground
      • Wait 2.50 seconds
      • Custom script: exitwhen GetUnitCurrentOrder(u) == OrderId("stop")
      • Custom script: endloop
 
Level 6
Joined
Aug 12, 2007
Messages
201
Good stuff, I think that pretty much does it. Works consistently with no bugs. Again I really appreciate all the help you gave, +rep for sure.
 
Level 8
Joined
May 21, 2008
Messages
218
ok, i will try to explain.

Thing of a trigger like the one on a gun. You pull it once, it fires. You tell it to do actions, so when the trigger fires, it calls the actions. Actions are seperate from the trigger. If you tell the action to wait, that does not mean that the trigger waits. So you can have a trigger fire a thousand times per second with a wait inside of the actions, and the triggers will not wait for the other actions to finish before firing again.

No, your wrong. If you put a wait action in, the trigger will go to the action, wait one second, and then continue. It only follows orders in a determined manner.

Edit: wait it works? Try casting two at once. I'm confused.
 
Status
Not open for further replies.
Top