Unit Snippets

Status
Not open for further replies.

Darthfett

Aerospace/Cybersecurity Software Engineer
Reaction score
615
Auto Reorder Code

Do your units constantly go back to their starting place when you order them to attack-move? Well this code will fix that, and will make sure they are constantly ordered to go to the original location that you ordered them to move!

It starts with a JASS trigger to store the X and Y of the location that the unit was ordered.

Code:
globals
    gamecache udg_ordercache
endglobals

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function STL_Conditions takes nothing returns boolean
    return (GetOwningPlayer(GetOrderedUnit()) == Player(11) and GetIssuedOrderId() == String2OrderIdBJ("attack")) == true
endfunction

function SetTargLoc takes nothing returns nothing
    local unit u = GetOrderedUnit()
    local integer id = H2I(u)
    call StoreReal(udg_ordercache,I2S(id), "X",GetUnitX(u))
    call StoreReal(udg_ordercache,I2S(id), "Y",GetUnitY(u))
    set u = null
endfunction

function InitTrig_SetTargLoc takes nothing returns nothing
    set gg_trg_SetTargLoc = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( gg_trg_SetTargLoc, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( gg_trg_SetTargLoc, function SetTargLoc )
    call TriggerAddCondition(gg_trg_SetTargLoc,Condition(function STL_Conditions))
endfunction

When you put this into your map, you should delete the globals section, and add in the variable "ordercache", and of type Game Cache. This code also has a condition that makes it so the auto reordering will only affect units owned by Player 12 (Brown). You should also put function H2I in the map icon at the top of your trigger editor, if you don't already have it in their.

Here is the second trigger, which will automatically order all the units to their current target location.

Code:
globals
    gamecache udg_ordercache
endglobals

function H2I takes handle h returns integer
    return h
    return 0
endfunction

function AutoReorderUnits takes nothing returns nothing
    local group tempgroup = CreateGroup()
    local unit TEMP_Unit
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        if GetOwningPlayer(TEMP_Unit) != Player(11) then
            call GroupRemoveUnit(tempgroup,TEMP_Unit)
        endif
    endloop
    loop
        set TEMP_Unit = FirstOfGroup(tempgroup)
        exitwhen TEMP_Unit == null
        call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"X"),GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"Y"))
		call GroupRemoveUnit(tempgroup,TEMP_Unit)
    endloop
	call DestroyGroup(tempgroup)
	set tempgroup = null
endfunction

function InitTrig_AutoReorderUnits takes nothing returns nothing
    set gg_trg_AutoReorderUnits = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_AutoReorderUnits,2.00,true)
    call TriggerAddAction(gg_trg_AutoReorderUnits,function AutoReorderUnits)
endfunction

This one, you'll just have to remove the globals section. It will automatically order all the units in tempgroup, which I have left as a blank group for you to set. It can be all the units owned by Brown, or just some of them.

I hope you find this one useful! It is one of the triggers that may be included in Infiltration, if you have seen the map yet.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
715
Are you tired of making pathing to your TD's? All those separate trigger are so annoying? Try this!

Step 1

Firstly, make a region variable with the array size of how much regions you have. Then, set them. (Make sure you set the arrays from 0, not from 1)

Code:
Region Initialization
    Events
        Map initialization
    Conditions
    Actions
        Set pathing_regions[0] = starting gen <gen>
        Set pathing_regions[1] = region gen <gen>
        Set pathing_regions[2] = region gen 2 <gen>
        Set pathing_regions[3] = region gen 3 <gen>
        Set pathing_regions[4] = region gen 4 <gen>
        Set pathing_regions[5] = region gen 5 <gen>
        Set pathing_regions[6] = region gen 7 <gen>
        Set pathing_regions[7] = end gen <gen>

Step 2

Now, you need another trigger for moving the creeps. Start by adding the events.
Code:
Events
    Unit - A unit enters starting gen <gen>
    Unit - A unit enters region gen <gen>
    Unit - A unit enters region gen 2 <gen>
    Unit - A unit enters region gen 3 <gen>
    Unit - A unit enters region gen 4 <gen>
    Unit - A unit enters region gen 5 <gen>
    Unit - A unit enters region gen 7 <gen>
    Unit - A unit enters end gen <gen>

Then, perhaps, a condition to check, that the right unit triggers the actions.

Code:
Conditions
    (Owner of (Triggering unit)) Equal to Player 2 (Blue)

And lastly, the actions part. This uses the custom value of the triggering unit, which is 0 by default.

Code:
Actions
    Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
    Set loc_L = (Center of pathing_regions[(Custom value of (Triggering unit))])
    Unit - Order (Triggering unit) to Move To loc_L
    Custom script:   call RemoveLocation (udg_loc_L)

What this does is, when the unit enter the starting region, set the custom value of the unit to 1 and orders the unit to move to pathing_region[1] aka region gen. If it enter region gen, its sets the custom value to 2 and orders the unit to move to pathing_region[2] and ect. until the end.

Final result

Code:
Region Starting
    Events
        Unit - A unit enters starting gen <gen>
        Unit - A unit enters region gen <gen>
        Unit - A unit enters region gen 2 <gen>
        Unit - A unit enters region gen 3 <gen>
        Unit - A unit enters region gen 4 <gen>
        Unit - A unit enters region gen 5 <gen>
        Unit - A unit enters region gen 7 <gen>
        Unit - A unit enters end gen <gen>
    Conditions
        (Owner of (Triggering unit)) Equal to Player 2 (Blue)
    Actions
        Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
        Set loc_L = (Center of pathing_regions[(Custom value of (Triggering unit))])
        Unit - Order (Triggering unit) to Move To loc_L
        Custom script:   call RemoveLocation (udg_loc_L)

Hope this proves useful!

~Andrewgosu
 

Attachments

  • Advanced Pathing.w3x
    13.4 KB · Views: 356

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Smooth Vertex color changes

Here's a some triggers for a Smooth Vertex Color change. Here's the thread discussing these triggers.

Need 2 variables - TriggerRun and vred. Both variables should be set to variable type integer.
The following triggers are for the Red vertex color. Blue and green are the same format; any references to "vred" in the triggers needs to be changed to vblue or vgreen; "reddn" to greendn or bluedn.

Here's the attached file for it

This will set the variable values to 255 at the map initialisation.
Code:
Initialisation
    Events
        Map initialization
    Conditions
    Actions
        Set TriggerRun = 0
        Set vred = 255
        Set vgreen = 255
        Set vblue = 255

Initial trigger for Red Down
Code:
reddn init
    Events
        Player - Player 1 (Red) types a chat message containing reddn as An exact match 
    Conditions
    Actions 
        Set TriggerRun = 0 
        Set vred = 255 
        Trigger - Turn on Red Down <gen>

Sets vred to 0 from 255. This will take 2.55 seconds.
Code:
Red Down
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Set vred = (vred - 1)
        Set TriggerRun = (TriggerRun + 1)
        Animation - Change (Last created unit)'s vertex coloring to ((Real(vred))%, (Real(vgreen))%, (Real(vblue))%) with 0.00% transparency
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                TriggerRun Greater than or equal to 255
            Then - Actions
                Trigger - Remove (This trigger) from the trigger queue
                Trigger - Remove reddn init <gen> from the trigger queue
                Trigger - Turn off (This trigger)
            Else - Actions
                Do nothing

Initial trigger for Red Up
Code:
redup init
    Events
        Player - Player 1 (Red) types a chat message containing redup as An exact match
    Conditions
    Actions
        Set TriggerRun = 0
        Set vred = 0
        Trigger - Turn on Red Up <gen>


Sets vred to 255 from 0. This will take 2.55 seconds.
Code:
Red Up
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Set vred = (vred + 1)
        Set TriggerRun = (TriggerRun + 1)
        Animation - Change (Last created unit)'s vertex coloring to ((Real(vred))%, (Real(vgreen))%, (Real(vblue))%) with 0.00% transparency
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                TriggerRun Greater than or equal to 255
            Then - Actions
                Trigger - Remove (This trigger) from the trigger queue
                Trigger - Remove redup init <gen> from the trigger queue
                Trigger - Turn off (This trigger)
            Else - Actions
                Do nothing
 

elmstfreddie

The Finglonger
Reaction score
203
This triggering will kill any units in a unit group die if they walk onto a certain type of terrain. Very good for maze games.

Code:
Multiple Unit Terrain Detection
    Events
        Time - Every 0.01 seconds of game time
    Conditions
    Actions
        Unit Group - Pick every unit in UnitGroup and do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Terrain type at (Position of (Picked unit))) Equal to Lordaeron Summer - Dirt
                    Then - Actions
                        Unit - Kill (Picked unit)
                    Else - Actions
                        Do nothing

"UnitGroup" is a Unit Group type variable, add any unit you want to be affected by the "death terrain" to this unit group :)
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
715
If you ever want to display 'damage text' if someone does damage and you are sick of using Critical Strike and want some more manipulation possibilities, (like changing colour of the text), then here are the 2 easy triggers.

Firstly, You need to register the unit.

IsUnitRegistered - Unit Group variables


Code:
Register Unit
    Events
        Unit - A unit enters (Playable map area)
    Conditions
        ((Triggering unit) is in IsUnitRegistered) Not equal to True
    Actions
        Unit Group - Add (Triggering unit) to IsUnitRegistered
        Trigger - Add to Damage Dealt <gen> the event (Unit - (Triggering unit) Takes damage)

The condition is there to make sure an unit is not added twice. Wouldn't it be weird to get 2 floating texts per 1 attack?

Secondly, create the trigger, which displays the damage dealt.

tmpPoint - Point variable
textTag - Floating Text variable


Code:
Damage Dealt
    Events
    Conditions
    Actions
        Set tmpPoint = (Position of (Triggering unit))
        Floating Text - Create floating text that reads ((String((Integer((Damage taken))))) + !) at tmpPoint with Z offset 0.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency
        Set textTag = (Last created floating text)
        Floating Text - Change textTag: Disable permanence
        Floating Text - Change the lifespan of textTag to 5.00 seconds
        Floating Text - Change the fading age of textTag to 4.00 seconds
        Floating Text - Set the velocity of textTag to 64.00 towards 90.00 degrees
        Custom script:   call RemoveLocation( udg_tmpPoint )

The custom script is needed to remove the leaks.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
Code:
Limit Buildings
    Events
        Map initialization
    Conditions
    Actions
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Player - Limit training of Blacksmith to 1 for (Picked player)
 

Oninuva

You can change this now in User CP.
Reaction score
221
Slide Trigger

Code:
Slideonice
    Events
        Time - Every 0.03 seconds of game time
    Conditions
    Actions
        Custom script:   local location udg_Slide_loc
        Set SlideGroup = (Units in (Playable map area) matching (((Matching unit) is A structure) Equal to False))
        Unit Group - Pick every unit in SlideGroup and do (Actions)
            Loop - Actions
                Set Slide_loc[1] = (Position of (Picked unit))
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        [COLOR="seagreen"](Terrain type at (Position of (Picked unit))) Equal to Icecrown Glacier - Ice[/COLOR]
                    Then - Actions
                       [COLOR="Red"] Set Slide_loc[2] = (Slide_loc[1] offset by 10.00 towards (Facing of (Picked unit)) degrees)[/COLOR]
                        Set Slide_loc[3] = Slide_loc[2]
                        Unit - Move (Picked unit) instantly to Slide_loc[3]
                    Else - Actions
        Custom script:   call DestroyGroup(udg_SlideGroup)

Code:
TurnonIce
    Events
        Unit - A unit Is issued an order targeting a point
    Conditions
        [COLOR="SeaGreen"](Terrain type at (Position of (Triggering unit))) Equal to Icecrown Glacier - Ice[/COLOR]
    Actions
        Set SlidePoint = (Target point of issued order)
        Unit - Make (Triggering unit) face SlidePoint over 0.00 seconds
        Custom script:   call RemoveLocation(udg_SlidePoint)

Note: You can customize this trigger by changing The Terrain Type (Green) and also the slide speed by changing the offset distance. (Red)
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
715
Behold, the ultimate sliding trigger is here!


  • It is leak and lag free and requires no global variables. Not to mention it is MUI, MPI or whatnot.
  • Removes the attack button when sliding, to avoid the unit from auto-acquiring enemy targets, which make the "Stop" and "Attack" command buttons "blink" constantly.
  • Units owned by neutral players are immune to sliding - they can patrol on the ice and make it harder for you to be in motion.
  • While sliding, it also checks, whether the sliding unit is on the "Killer Terrain".
  • Easy to configure.
  • And it all is in one single trigger!

Enjoy.
 

Attachments

  • Sliding.w3x
    15.7 KB · Views: 393

Doomhammer

Bob Kotick - Gamers' corporate spoilsport No. 1
Reaction score
67
Preloading units makes sense when units with laggy models, and/or laggy passive abilities are to be created after the game has started. Especially the creation of a major amount of buildings at the exact same time can cause annoying lags in game. Since I've had quite a lot of trouble with these issues, I'll now present my solution.

JASS:
function PreloadUnit takes integer Id returns nothing
    call RemoveUnit(CreateUnit(Player(13), Id, 0.0, 0.0, bj_UNIT_FACING))
endfunction


Annotations:

1) make sure that the coordinates 0.0, 0.0 are pathable. If not, find the next suitable pathable location, and replace the coordinates in the function.

2) Preload all the laggy units from your map: Have a function called at map initialization and call the Preload function, e.g.
JASS:
call PreloadUnit(&#039;o00E&#039;)
 
Status
Not open for further replies.
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top