• 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.

Z position Jass Help

Status
Not open for further replies.
Level 5
Joined
Jun 13, 2008
Messages
102
I need a trigger that will get the z height of a unit and if its below a certain height it will add it to a unit group and if it moves above that height it will be removed.
In GUI you cannot get z position but ive heard in Jass you can get it... unfortunately I cant do Jass whatsoever :hohum:so I'd much appreciate some help.
 
I need a trigger that will get the z height of a unit and if its below a certain height it will add it to a unit group and if it moves above that height it will be removed.
In GUI you cannot get z position but ive heard in Jass you can get it... unfortunately I cant do Jass whatsoever :hohum:so I'd much appreciate some help.


if you need the Z of a location use this
  • Custom Script - call GetLocationZ(location)
 
Level 5
Joined
Jun 13, 2008
Messages
102
Now ive got the Z position but I would love it if you could tell me how to set the Z postion of a picked unit as a local variable, and if its below a certain value reduce its movement speed. (I could do the movement speed bit myself its just the local variable bit I cant do).
Oh, and thanks for the quick reply.
 
Now ive got the Z position but I would love it if you could tell me how to set the Z postion of a picked unit as a local variable, and if its below a certain value reduce its movement speed. (I could do the movement speed bit myself its just the local variable bit I cant do).
Oh, and thanks for the quick reply.

if the unit isnt flying you can set the locationZ into the local variable (real)
JASS:
set height = GetLocationZ(location)
but if the unit is flying you must add its flying height to the location Z....
JASS:
set height = GetLocationZ(location) + GetUnitFlyHeight(unit)
 
Level 5
Joined
Jun 13, 2008
Messages
102
  • Unit Group - Pick every unit in (Units in (Playable map area)) matching (((Matching unit) is Undead) Equal to True) and do (Actions)
  • Loop - Actions
  • Custom script: call GetLocationZ(GetUnitLoc(GetEnumUnit()))
  • Custom script: set localheight = call GetLocationZ(GetUnitLoc(GetEnumUnit()))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • localheight Less than or equal to 100.00
  • Then - Actions
  • Unit - Set (Picked Unit) movement speed to ((Current movement speed of (Picked unit)) - 100.00)
  • Else - Actions
  • Do nothing
This should work then yeah? Event is every 2 seconds BTW.
 
  • Unit Group - Pick every unit in (Units in (Playable map area)) matching (((Matching unit) is Undead) Equal to True) and do (Actions)
  • Loop - Actions
  • Custom script: call GetLocationZ(GetUnitLoc(GetEnumUnit()))
  • Custom script: set localheight = call GetLocationZ(GetUnitLoc(GetEnumUnit()))
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
  • If - Conditions
  • localheight Less than or equal to 100.00
  • Then - Actions
  • Unit - Set (Picked Unit) movement speed to ((Current movement speed of (Picked unit)) - 100.00)
  • Else - Actions
  • Do nothing

This should work then yeah? Event is every 2 seconds BTW.

yeah, though your trigger leaks location. and I think its better to make the interval smaller like every .03 seconds.
 
Level 5
Joined
Jun 13, 2008
Messages
102
Yeah ive just looked at some tutorials and scraped myself together a JASS version of this which uses local variables AND doesn't crash WE xD. Should do the job fine, again, thanks for your help.

Don't know if you're interested but it looks like this:

JASS:
function Trig_Untitled_Trigger_002_Copy_Func001001002 takes nothing returns boolean
    return ( IsUnitType(GetFilterUnit(), UNIT_TYPE_UNDEAD) == true )
endfunction

function Trig_Untitled_Trigger_002_Copy_Func001Func003001 takes nothing returns boolean
    local real h = GetLocationZ(GetUnitLoc(GetEnumUnit()))
    return ( h == 179.20 )
endfunction

function Trig_Untitled_Trigger_002_Copy_Func001A takes nothing returns nothing
    call DoNothing(  )
    call DoNothing(  )
    if ( Trig_Untitled_Trigger_002_Copy_Func001Func003001() ) then
        call SetUnitMoveSpeed( GetEnumUnit(), ( GetUnitMoveSpeed(GetEnumUnit()) - 150.00 ) )
    else
        call SetUnitMoveSpeed( GetEnumUnit(), GetUnitDefaultMoveSpeed(GetEnumUnit()) )
    endif
endfunction

function Trig_Untitled_Trigger_002_Copy_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition(function Trig_Untitled_Trigger_002_Copy_Func001001002)), function Trig_Untitled_Trigger_002_Copy_Func001A )
endfunction

//===========================================================================
function InitTrig_WaterSlow takes nothing returns nothing
    set gg_trg_WaterSlow = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_WaterSlow, 1 )
    call TriggerAddAction( gg_trg_WaterSlow, function Trig_Untitled_Trigger_002_Copy_Actions )
endfunction

Woo my first full JASS trigger. :D
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well first of all you'll want to add the units with decreased movement speed to a group and filter those units out so that the effect doesn't re-apply itself every second. When you remove it you'll want to remove them from the unit-group as well.
 
Level 5
Joined
Jun 13, 2008
Messages
102
Basically I,m using this trigger to slow movement speed of units on water (thats whats with the height must equal exactly 179.2) and I dont have any triggers or abilities than involve terrain deformations, so im not too worried abou that M0RT (Loving the Pratchett references).

Thanks for the tip Berbanog that'll help performance with lots of units.

Thanks for pointing that out to overload119, even I don't know why those are still there.

*EDIT* Also M0RT, I've downloaded your Space Engineers Beta, it looks great, I had an idea for a map like that once but couldn't figure out how to do it...
 
Level 13
Joined
Apr 15, 2008
Messages
1,063
Well terrain deformations also come from things like Thunderclap and War Stomp.
If you need to know, whether the unit is on water, test the location for pathability:
  • Deep Water
  • Conditions
    • (Terrain pathing at temp_loc of type Floatability is off) Equal to False
    • (Terrain pathing at temp_loc of type Walkability is off) Equal to True
  • Shallow Water
  • Conditions
    • (Terrain pathing at temp_loc of type Floatability is off) Equal to False
    • (Terrain pathing at temp_loc of type Walkability is off) Equal to False
(obviously if you want to test for any water, use only the "Flotability" condition.

Space engineers: glad you like it, I had this idea for like 7 years, and when I saw that space maps are becoming pretty common, I had to make one, too :grin:
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Couldn't "GetLocationZ" be modified so that it returns a different value for each player (if necessary) in an attempt to avoid the desync?

JASS:
function GetLocationZSafe takes location loc returns real
    local real z
    local integer i
    
    set i=0
    loop
        exitwhen i==16
        if GetLocalPlayer()==Player(i) then
            set z=GetLocationZ(loc)
        endif
        set i=i+1
    endloop
    return z
endfunction
 
Level 13
Joined
Apr 15, 2008
Messages
1,063
1) If it DID returned different value for each player, it would definetely cause desync (well not definetely, depends on what you use it for)
2) this function solves nothing, it calls the exact same line for each player
3) GetLocalPlayer() can never be players 12-15, since they are always AI players

The problem is that it might return different values, thats what we are trying to avoid. These situations are quite rare, so only if you use GetLocationZ() often and to decide unsafe code (like if you wanted to destroy all units on hills for some reason), you will need to worry about the terrain deformations.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
What I was failing to show you with my function is a function that synchronizes the values returned so that it returns the same value for all players, kind of like a "standard" player.

M0RT said:
GetLocalPlayer() can never be players 12-15, since they are always AI players

This is besides the point.

M0RT said:
this function solves nothing, it calls the exact same line for each player

May not solve anything right now, but one of the strengths of having a forum thread is for idea brainstorming. I don't sit down at my computer for 30 minutes writing out code before I post here.

Berbanog said:
Couldn't "GetLocationZ" be modified so that it returns a different value for each player (if necessary) in an attempt to avoid the desync?

My example code is entirely besides the point, I don't know why you're putting so much effort into analyzing it. I merely posted the code to provide an example by which my point could be emphasized. I don't care if it has syntax errors when its compiling I asked if its possible that we modify the function to make it "safer".
 
Level 13
Joined
Apr 15, 2008
Messages
1,063
Ok, first, sorry for the tone of my last post, I didn't want to offend you.

My point was that the function imho doesn't synchronize returned value, because in the end, it just calls GetLocationZ(loc) at all computers, and it will still return different values. If you wanted to synchronize values, you would need to use GameCache and call SyncStoredInteger(...), which takes some time, so it's basically useless in most of triggers (since GetLocationZ() is usually called in triggers that somehow handle unit movement, that trigger like 20 times in second)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Well having synchronized values and "synchronizing" the values can be approached differently. For example, if your function only returns the "GetLocationZ" for Player 1 (Red) then where players' games would have crashed before they will simply have safe actions applied.

The problem I was having "expressing" is setting a variable for every player to a specific player's value, an effect that may only be possible through that "SyncStored...". Lamestylez.
 
Status
Not open for further replies.
Top