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

Buff at random specific units on the map

Level 4
Joined
Sep 10, 2023
Messages
47
Hello I want to make an ability that when cast it randomly gives a debuff (doom) on a random unit around the map (random villager). I need to make an infection ability that is casted on a random villager unit.


Ive read that you cant manually set a trigger to give a buff, but you can set a unit with the ability and then cast the ability to a target (make it invisible and all). I wonder now how I can make the unit to spawn on a random area? where there are villagers nearby or maybe make the ability have a really long cast range.
 
Level 21
Joined
Aug 29, 2012
Messages
865
If you're concerned about range, you can spawn your dummy caster right on top of your target

  • Actions
    • Set VariableSet InfectionTarget = (Random unit from (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Peasant)))
    • Unit - Create 1 Dummy for Neutral Hostile at (Position of InfectionTarget) facing Default building facing degrees
    • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
    • Unit - Add Doom to (Last created unit)
    • Unit - Order (Last created unit) to Neutral Pit Lord - Doom InfectionTarget
(This leaks, that's just an example)

But giving it a range of like 9999999 should work too, then you can even preplace it in the middle of your map and not worry about creating it
 
Level 35
Joined
Feb 5, 2009
Messages
4,566
Put all the units you want to have a chance of being randomly selected for the ability to be cast

Set a unit variable to be a random unit from that unit group

Assign the position of that unit to a point variable

Create your dummy caster (which will need to be edited in the object editor to meet your requirements for being hidden) at the point variable, order it to cast your ability on the randomly selected unit and set its expiration timer to something small (1 second will do). This assumes that the dummy caster already has the ability in the object editor - if not, do as Chaosium suggested and add the ability to the last created unit before ordering it to cast.

To clear the memory leak, use the Custom Script "call RemoveLocation(udg_YourVariableNameHere)" for the point variable. Always do this when you're done with point variables before assigning another location to the same variable.



Tbh Chaosium's suggestion is going to look a lot neater, you just need to be wary of memory leaks as he stated. If you place the dummy caster on top of the target unit, you don't have to worry about casting range so much.
 
Top