1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Weave light to take you to your highest hopes - the 6th Special Effect Contest is here!
    Dismiss Notice
  4. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

create and destroy lightning effect MUI HELP!

Discussion in 'World Editor Help Zone' started by constellcreate, May 8, 2011.

  1. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    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!
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,996
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    If it is a channeling ability you can probably get the lightning created via the object editor the same way life steal and such channel moves do.

    Otherwise you will have to use some form of data storage system, eithor hashtable or an array system.
     
  3. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,128
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Why do you create a custom repair?
     
  4. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    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.
     
  5. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,128
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Ok, I made it with the default Repair. Here:
    Triggers
    • 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.
     

    Attached Files:

  6. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    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.
     
  7. wolfman

    wolfman

    Joined:
    May 31, 2008
    Messages:
    696
    Resources:
    0
    Resources:
    0
    If distance between building and builder is less than 200 then
    put all that other stuff here :)
    Make this in the repair check, and just remove the lighnitng under the "else"
    I think that could work
     
  8. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    @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 =_=!
     
  9. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    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

    Trigs

    • 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


     
  10. D4RK_G4ND4LF

    D4RK_G4ND4LF

    Joined:
    Feb 4, 2009
    Messages:
    1,196
    Resources:
    20
    Models:
    3
    Spells:
    15
    Tutorials:
    2
    Resources:
    20
    you really want to create a LOCAL array?
    that's like 8186 unused slots
     
  11. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    No, I don't want to. It's Pharaoh_'s doings. I'd remove the array since it's not needed at all :)
     
  12. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,128
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    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.
     
  13. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    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!
     
  14. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    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: May 11, 2011
  15. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    Please helpme out here I have no idea what does the script mean at all =_=!
     
  16. D4RK_G4ND4LF

    D4RK_G4ND4LF

    Joined:
    Feb 4, 2009
    Messages:
    1,196
    Resources:
    20
    Models:
    3
    Spells:
    15
    Tutorials:
    2
    Resources:
    20
    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

    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
     
  17. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    *Removed the local real array
    *Removed global point array, using two non array variables instead
    *Changed lightning to DRAL (green)
    *Changed the flow direction of the lightning
    *Got rid of leaks
    *Added GetLocationZ to the lightning's height offset so it is at correct height on elevated ground

    http://www.hiveworkshop.com/forums/pastebin.php?id=5ojiht
     
  18. constellcreate

    constellcreate

    Joined:
    Jul 2, 2008
    Messages:
    51
    Resources:
    0
    Resources:
    0
    Thank you so much Maker you really helped me out a lot, I am learning so much from this!

    And thank you everyone else, too!