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

How to add Z to lightning effects

Status
Not open for further replies.
Level 28
Joined
Jan 26, 2007
Messages
4,789
The native for this is native AddLightningEx takes string codeName, boolean checkVisibility, real x1, real y1, real z1, real x2, real y2, real z2 returns lightning

So if you want to create a lightning somewhere, you'd need to so something like:
JASS:
function YourFunction takes unit caster, unit target returns nothing
    local real x1 = GetUnitX(caster)
    local real y1 = GetUnitY(caster)
    local real z1 = GetUnitFlyHeight(caster)
    local real x2 = GetUnitX(target)
    local real y2 = GetUnitY(target)
    local real z2 = GetUnitFlyHeight(target)
    
    set udg_Lightning = AddLightningEx("SPLK", true, x1, y1, z1, x2, y2, z2) 
endfunction

In custom scripts it's basically the same.
Just copy the very last line (not counting "endfunction"), change the variables first (you'd best do this in notepad or somewhere, because editing it inside the custom script is tedious).
The variables speak for themselves I suppose, "SPLK" just means "SPirit LinK" (it's the lightning type), if the second value is "true", then the lightning cannot be seen when fogged. The rest are coordinates.
Copy it in the custom script and you're done.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
^You have to add the locatio's z value to the height and one could add some offset height:

JASS:
function YourFunction takes unit caster, unit target returns nothing
    local real x1 = GetUnitX(caster)
    local real y1 = GetUnitY(caster)
    local real x2 = GetUnitX(target)
    local real y2 = GetUnitY(target)
    local location l1 = GetUnitLoc(caster)
    local location l2 = GetUnitLoc(target)
    local real z1 = GetLocationZ(l1) + GetUnitFlyHeight(caster) + 60
    local real z2 = GetLocationZ(l2) + GetUnitFlyHeight(target) + 60
    
    set udg_Lightning = AddLightningEx("SPLK", true, x1, y1, z1, x2, y2, z2)

    call RemoveLocation(l1)
    call RemoveLocation(l2) 
    set l1 = null
    set l2 = null
endfunction
 
Just copy the very last line (not counting "endfunction"), change the variables first (you'd best do this in notepad or somewhere, because editing it inside the custom script is tedious).

Well, based on what he said you just use custom script to set up local variables then call the function (you can only use more than one local in the same function it is called in, I think)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
get the locations of a point using locals
I believe you mean "get the coordinates of a point"?

Well, you don't HAVE to use locals to set the variables.
You can use globals as well and use those in the custom script that creates the lightning.

But if you really wish to know:
JASS:
local real x = GetLocationX(udg_tempLoc)
local real y = GetLocationY(udg_tempLoc)

Where tempLoc is a global point variable.

what is the function for spawning a unit at a point with x,y and z?

There is no direct function for that.
You'll have to spawn the unit first and then set the flying height.

JASS:
set bj_lastCreatedUnit = CreateUnit(Player(0), 'hpea', x, y, 0.) // Player(0) is red, 'hpea' is the raw ID of the unit type, 0. is the facing of the unit
call UnitAddAbility(bj_lastCreatedUnit, 'Amrf') // ONLY use this if the unit type is NOT a 'flying' unit!
call SetUnitFlyHeight(bj_lastCreatedUnit, 500., 0.) // 500. is the fly height, 0. is the time it takes to reach that height

You can see the raw ID of the unit by pressing CTRL + D inside the object editor (the name will turn into the raw ID, it's always 4 characters long).
The AddAbility is because only flying units can increase their flying height (stupid blizzard...), so we make the unit flying by adding that ability.

This snippet will create a peasant for red at x, y (you can use the functions seen above to set these coordinates) and it will instantly make the unit fly to a height of 500.
I have used "bj_lastCreatedUnit" so you can access the unit easily by using the GUI-equivalent "Last Created Unit" (no extra variables required).


Note: I'm not on my own PC right now, so I don't have Warcraft installed. I hope everything is correct.
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
There's no difference. The reason that Jass is often faster (although not noticeably so for almost any purpose) is because it has access to better functions and less convoluted methods of doing things, but in that case the second line compiles down into the first--in fact, if you were to enter the second into a trigger and select Edit -> Convert to Custom Text you'd get the first, character for character.
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
I used GetLocationZ to calculate the Z-offset, but it always returns a null (0) value meaning, the lightning will still appear from the ground to ground, but when I used the GetUnitFlyHeight, it works perfectly, wonder what's the actual use of GetLocationZ eh ?

Here's my actual trigger (the broken ones):
JASS:
           local unit Caster = GetTriggerUnit()
           local unit Target = GetSpellTargetUnit()
           local location CasterLoc = GetUnitLoc(Caster)
           local location TargetLoc = GetUnitLoc(Target)
           local real x1 = GetUnitX(Caster)
           local real y1 = GetUnitY(Caster)
           local real z1 = GetLocationZ(CasterLoc)
           local real x2 = GetUnitX(Target)
           local real y2 = GetUnitY(Target)
           local real z2 = GetLocationZ(TargetLoc)
           call SetUnitFlyHeight(Caster, 500, 0)
           call UnitAddAbility(Caster, 'Amrf')
           call UnitRemoveAbility(Caster, 'Amrf')
           call AddLightningEx("DRAB", true, x1, y1, z1, x2, y2, z2)
           set Caster = null
           set Target = null
           set CasterLoc = null
           set TargetLoc = null
           call RemoveLocation(CasterLoc)
           call RemoveLocation(TargetLoc)

This is fixed version:
JASS:
       local unit Caster = GetTriggerUnit()
       local unit Target = GetSpellTargetUnit()
       local real x1 = GetUnitX(Caster)
       local real y1 = GetUnitY(Caster)
       local real z1 = GetUnitFlyHeight(Caster)
       local real x2 = GetUnitX(Target)
       local real y2 = GetUnitY(Target)
       local real z2 = GetUnitFlyHeight(Target)
       call SetUnitFlyHeight(Caster, 500, 0)
       call UnitAddAbility(Caster, 'Amrf')
       call UnitRemoveAbility(Caster, 'Amrf')
       call AddLightningEx("DRAB", true, x1, y1, z1, x2, y2, z2)
       set Caster = null
       set Target = null

Also, thanks to panda-avatar guy here for opening this thread, this solves my problem :)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
Hmmm you can experiment it by yourself (it won't hurt, just 5 minutes or so :D)
Use GetLocationZ instead of GetUnitFlyHeight
The result will return null, meaning the lightning will be spawned/created from ground to ground (the location is correct, but the Z value is 0, meaning it is ground level)
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
What I meant was, height from ground (ground = the location is where a gravity stops pulling us down further)
If you're saying the height of the unit is 0, why when I do the GetUnitFlyHeight and it works ? (the lightning goes from air (Z-offset of the Caster) to ground (Z-offset of the Target))

So what does this GetLocationZ really does
If it is meant for different level of cliffs, that, I can understand
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
What I meant was, height from ground (ground = the location is where a gravity stops pulling us down further)
If you're saying the height of the unit is 0, why when I do the GetUnitFlyHeight and it works ? (the lightning goes from air (Z-offset of the Caster) to ground (Z-offset of the Target))

So what does this GetLocationZ really does
If it is meant for different level of cliffs, that, I can understand
Gravity always pulls us. The thing is that you can't move down anymore since ground is reacting to your weight. (Weight being the force with which you interact with ground)

As i've said for GetLocZ, it returns location height, not only for cliffs, but for any kind of raised terrain (you can raise terrain by raise tool).
If you want to connect one lightning's end to a unit, it's best to, for Z, use GetLocationZ(Unit'sLoc) + GetUnitHeight(Unit).
attachment.php
 

Attachments

  • pic.jpg
    pic.jpg
    25.2 KB · Views: 165
Status
Not open for further replies.
Top