• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

create and destroy lightning effect MUI HELP!

Status
Not open for further replies.
Level 4
Joined
Jul 2, 2008
Messages
50
Basically I want my work to be able to repair a building. When he does that it will create a lightning from the building to the repairing worker.

Note that repairing is a 0 cooldown channeling skill.

When my work stops channeling it will destroy the lightning effect. I want this to be done in MUI, can anyone tell me what's the trick to this? (show code prefered)

Thank you very much!
 
Level 4
Joined
Jul 2, 2008
Messages
50
Actually i tried cnp the siphon mana buffs and effects to the repair skills but it didn't work.

I am just trying to make repair look cooler, by adding a lightning effect to it so it actually looks like my worker is transfering energy into repairing the building.

It's been years since I've used to world editor so im totally blind at it right now, if anyone doesn't mind please show me the coding. I'm sure it shouldn't be hard at all.

Thank you very much for replying.
 
Ok, I made it with the default Repair. Here:
  • Order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Triggering unit) is A peon-type unit) Equal to True
    • Actions
      • Custom script: local real array r
      • Custom script: local unit u
      • Custom script: if GetIssuedOrderId() == 852024 or GetIssuedOrderId() == 851971 then
      • Set TargetStructure = (Target unit of issued order)
      • Custom script: if GetIssuedOrderId() == 851971 then
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TargetStructure Not equal to No unit
          • (TargetStructure is A structure) Equal to True
          • (Life of TargetStructure) Less than (Max life of TargetStructure)
        • Then - Actions
          • Custom script: call IssueTargetOrderById (GetTriggerUnit(), 852024, udg_TargetStructure)
        • Else - Actions
      • Custom script: else
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in RepairersGroup) Equal to True
        • Then - Actions
          • Lightning - Destroy (Load (Key light) of (Key (Triggering unit)) in RHash)
          • Custom script: call RemoveSavedHandle (udg_RHash, GetHandleId(GetTriggerUnit()), StringHash("target"))
          • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in RHash
        • Else - Actions
      • Unit Group - Add (Triggering unit) to RepairersGroup
      • Custom script: set u = GetTriggerUnit()
      • Custom script: set r[1] = GetUnitX (u)
      • Custom script: set r[2] = GetUnitY (u)
      • Custom script: set r[3] = GetUnitX (udg_TargetStructure)
      • Custom script: set r[4] = GetUnitY (udg_TargetStructure)
      • Custom script: set udg_R_Lightning=AddLightningEx ("DRAM",true,r[1],r[2],20,r[3],r[4],20)
      • Hashtable - Save Handle OfR_Lightning as (Key light) of (Key (Triggering unit)) in RHash
      • Hashtable - Save Handle OfTargetStructure as (Key target) of (Key (Triggering unit)) in RHash
      • Trigger - Turn on Repair check <gen>
      • Custom script: endif
      • Custom script: endif
      • Custom script: set u = null
  • Repair check
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (RepairersGroup is empty) Equal to True
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
          • Unit Group - Pick every unit in RepairersGroup and do (Actions)
            • Loop - Actions
              • Set R_LoadStructure = (Load (Key target) of (Key (Picked unit)) in RHash)
              • Set R_LightLoad = (Load (Key light) of (Key (Picked unit)) in RHash)
              • Custom script: call MoveLightningEx(udg_R_LightLoad,true,GetUnitX(GetEnumUnit()),GetUnitY(GetEnumUnit()),20,GetUnitX(udg_R_LoadStructure),GetUnitY(udg_R_LoadStructure),20)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Life of R_LoadStructure) Equal to (Max life of R_LoadStructure)
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from RepairersGroup
                  • Lightning - Destroy R_LightLoad
                  • Custom script: call RemoveSavedHandle (udg_RHash, GetHandleId(GetEnumUnit()), StringHash("target"))
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in RHash
                • Else - Actions
  • Remove Lightning
    • Events
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • ((Triggering unit) is in RepairersGroup) Equal to True
    • Actions
      • Lightning - Destroy (Load (Key light) of (Key (Triggering unit)) in RHash)
      • Custom script: call RemoveSavedHandle (udg_RHash, GetHandleId(GetTriggerUnit()), StringHash("target"))
      • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in RHash
Hope this is what you want.
 

Attachments

  • Repair with Lightning.w3x
    19.1 KB · Views: 83
Level 4
Joined
Jul 2, 2008
Messages
50
Thank you very much for the help!

However the only bug in your test map is that the lightning is already created between the 2 units before the worker even gets within repairing range.
 
Level 4
Joined
Jul 2, 2008
Messages
50
@wolfman; i tried that but it didn't work out.

Another main big problem is that since the repair is based on Repair(Human) as i wanted it to be, i order my worker to construct a new building and have the others help make it build faster. When the building is complete the lightning still stays there for aslong as they don't move.

This is way lot harder than I thought it would be =_=!
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
I took the liberty to modify Pharaoh_'s system. I hope he doesn't mind.

It should now destroy the lightning when they stop repairing and the lightning only shows when the unit is in repair range. you may have to adjust the distance a bit yourself.

http://www.hiveworkshop.com/forums/pastebin.php?id=dglcsi


  • Order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • ((Triggering unit) is A peon-type unit) Equal to True
    • Actions
      • Custom script: local unit u
      • Custom script: local real array r
      • Custom script: if GetIssuedOrderId() == 852024 or GetIssuedOrderId() == 851971 then
      • Set TargetStructure = (Target unit of issued order)
      • Custom script: if GetIssuedOrderId() == 851971 then
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TargetStructure Not equal to No unit
          • (TargetStructure is A structure) Equal to True
          • (Life of TargetStructure) Less than (Max life of TargetStructure)
        • Then - Actions
          • Custom script: call IssueTargetOrderById (GetTriggerUnit(), 852024, udg_TargetStructure)
        • Else - Actions
      • Custom script: else
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • ((Triggering unit) is in RepairersGroup) Equal to True
        • Then - Actions
          • Lightning - Destroy (Load (Key light) of (Key (Triggering unit)) in RHash)
          • Custom script: call RemoveSavedHandle (udg_RHash, GetHandleId(GetTriggerUnit()), StringHash("target"))
          • Hashtable - Clear all child hashtables of child (Key (Triggering unit)) in RHash
        • Else - Actions
      • Unit Group - Add (Triggering unit) to RepairersGroup
      • Custom script: set u = GetTriggerUnit()
      • Custom script: set r[1] = GetUnitX (u)
      • Custom script: set r[2] = GetUnitY (u)
      • Custom script: set r[3] = GetUnitX (udg_TargetStructure)
      • Custom script: set r[4] = GetUnitY (udg_TargetStructure)
      • Custom script: set bj_lastCreatedLightning=AddLightningEx ("DRAM",true,r[1],r[2],20,r[3],r[4],20)
      • Lightning - Change color of (Last created lightning effect) to (1.00 1.00 1.00) with 0.00 alpha
      • Hashtable - Save Handle Of(Last created lightning effect) as (Key light) of (Key (Triggering unit)) in RHash
      • Hashtable - Save Handle OfTargetStructure as (Key target) of (Key (Triggering unit)) in RHash
      • Trigger - Turn on Repair check <gen>
      • Custom script: endif
      • Custom script: endif
      • Custom script: set u = null
  • Repair check
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RepairersGroup and do (Actions)
        • Loop - Actions
          • Set R_LightLoad = (Load (Key light) of (Key (Picked unit)) in RHash)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (String((Current order of (Picked unit)))) Equal to repair
            • Then - Actions
              • Set RPoints[0] = (Position of (Picked unit))
              • Set RPoints[1] = (Position of TargetStructure)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Distance between RPoints[0] and RPoints[1]) Less than or equal to 500.00
                • Then - Actions
                  • Set TargetStructure = (Load (Key target) of (Key (Picked unit)) in RHash)
                  • Custom script: call MoveLightningEx(udg_R_LightLoad,true,GetUnitX(GetEnumUnit()),GetUnitY(GetEnumUnit()),20,GetUnitX(udg_TargetStructure),GetUnitY(udg_TargetStructure),20)
                  • Lightning - Change color of R_LightLoad to (1.00 1.00 1.00) with 1.00 alpha
                • Else - Actions
            • Else - Actions
              • Unit Group - Remove (Picked unit) from RepairersGroup
              • Lightning - Destroy R_LightLoad
              • Custom script: call RemoveSavedHandle (udg_RHash, GetHandleId(GetEnumUnit()), StringHash("target"))
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in RHash
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (RepairersGroup is empty) Equal to True
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
 
you really want to create a LOCAL array?
that's like 8186 unused slots

They are not pre-defined to take up memory space or something. I create the array and use only four values, I just did it to save time in writing, since I was not in front of my World Editor; but still, I don't think I did something wrong :p Unnecessary doesn't mean inefficient.
 
Level 4
Joined
Jul 2, 2008
Messages
50
Thank you all for helping me with this!

@Maker i tested your version and it's so far so good, thank you very much!

Just one more last thing now. Notice how to lightning is moving from the building To the worker, it's like using siphon mana on a target but instead the target looked as it's stealing your mana instead. How do i change it so it looks like my worker is transfering energy to the building instead?

And how do i change my lightning effect to the green one, used by dark ranger?

Thank you all for comments!
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
To change the colour, use DRAL instead of DRAM when creating the lightning.

To reverse the direction change the place of GetEnumUnit and the target here:
  • Custom script: call MoveLightningEx(udg_R_LightLoad,true,GetUnitX(GetEnumUnit()),GetUnitY(GetEnumUnit()),20,GetUnitX(udg_TargetStructure),GetUnitY(udg_TargetStructure),20)
 
Last edited:
Level 4
Joined
Jul 2, 2008
Messages
50
To change the colour, use DRAL instead of DRAM when creating the lightning.

To reverse the direction change the place of GetEnumUnit and the target here:
  • ustom script: call MoveLightningEx(udg_R_LightLoad,true,GetUnitX(GetEnumUnit()),GetUnitY(GetEnumUnit()),20,GetUnitX(udg_TargetStructure),GetUnitY(udg_TargetStructure),20)

Please helpme out here I have no idea what does the script mean at all =_=!
 
Please helpme out here I have no idea what does the script mean at all =_=!

this line of custom script does the following:
it "call"s a function
the function which is called is called "MoveLightningEx" so it moves a lightning and is the extended version of some other function (which is MoveLightning)
MoveLightningEx takes a few parameters which are:
1. a lightning
2. a boolean (if this is true the lightning won't be shown to players who would be unable to see the lightning because of fog)
3. -8. real values
3. start x of lightning
4. start y of lightning
5. start z of lightning
same for 6-8 but with end instead of start

and the z variable is the z height above mean sea level (or however it is called in wc3)
so as soon as you have different height levels in your map the lightning will look awkward
to fix this you will have take the terrain height into consideration
you get the terrain height by creating (or moving) a location to the point where you want to know the height from and then call the function "GetTerrainZ(location)" which will return the height at this point
in custom script this will look like:
  • Custom script: call MoveLocation(udg_loc, udg_x, udg_y)
  • Custom script: set udg_z = GetLocationZ(udg_loc)
you will have to create the location first because you can't move something which is not there
also you need x and y variables

They are not pre-defined to take up memory space or something. I create the array and use only four values, I just did it to save time in writing, since I was not in front of my World Editor; but still, I don't think I did something wrong :p Unnecessary doesn't mean inefficient.

creating the array is faster than creating 4 local variables
but as soon as the array variables are dereferenced it is slower even including the speed advantage from declaration
 
Status
Not open for further replies.
Top