• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Sliding trigger isn't working

Status
Not open for further replies.
Level 10
Joined
Sep 29, 2006
Messages
447
Okay so I'm trying to use an arrow key movement system in my map and it has to slide units, not order them to move. I also need them to be able to cast abilities while sliding, so SetUnitPosition() is out, I tried it. Naturally I decided to use SetUnitX,Y, but that ignores pathing, so I have a function that checks pathing at a location in there. Basically, my trigger doesn't slide the unit and I don't know why, can anyone help?

Please keep in mind that I am new to JASS, and can understand scripts (well, most of them) by reading them, but need help generating them on my own.

JASS:
function IsCar takes nothing returns boolean
    return ( GetFilterUnit() == udg_Car[GetConvertedPlayerId(GetEnumPlayer())] )
endfunction

function Conditions takes nothing returns boolean
    if ( not ( udg_Forward[GetConvertedPlayerId(GetOwningPlayer(GetEnumUnit()))] == true ) ) then
        return false
    endif
    if ( not ( IsUnitType(GetEnumUnit(), UNIT_TYPE_STUNNED) == false ) ) then
        return false
    endif
    return true
endfunction

function IsPositionPathable takes real x, real y returns boolean
    local boolean flag
    local unit PathChecker
    set PathChecker = CreateUnit(Player(15), 'hfoo', x, y, 0)
    set flag = (GetUnitX(PathChecker) == x) and (GetUnitY(PathChecker) ==y)
    call RemoveUnit(PathChecker)
    set PathChecker = null
    return flag
endfunction

function Function2 takes nothing returns nothing
    local location TempPoint = GetUnitLoc(GetEnumUnit())
    local real TempReal = GetUnitFacing(GetEnumUnit())
    local location TempPoint2 = PolarProjectionBJ(TempPoint, 13.00, TempReal)
    local boolean pathable = IsPositionPathable(GetLocationX(TempPoint2), GetLocationY(TempPoint2))
    if ( Conditions() ) then
        if (pathable == true) then
            call SetUnitX(GetEnumUnit(), GetLocationX(TempPoint2))
            call SetUnitY(GetEnumUnit(), GetLocationY(TempPoint2))
        else
        endif
        call RemoveLocation(TempPoint2)
        call RemoveLocation(TempPoint)
    else
    endif
endfunction

function Function1 takes nothing returns nothing
    local group TempUnitGroup = GetUnitsOfPlayerMatching(GetEnumPlayer(), Condition(function IsCar))
    call ForGroupBJ( TempUnitGroup, function Function2 )
    call DestroyGroup(TempUnitGroup)
endfunction

function Trig_move_forward_Copy_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Function1 )
endfunction

//===========================================================================
function InitTrig_move_forward_Copy takes nothing returns nothing
    set gg_trg_move_forward_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_move_forward_Copy, 0.03 )
    call TriggerAddAction( gg_trg_move_forward_Copy, function Trig_move_forward_Copy_Actions )
endfunction



This is game breaking and it needs to be fixed. Thanks in advance and +rep for the help.


Also, I have a Mac, So I don't have JassCraft or any other third party program, because as far as I know, there are none for the Mac.
 
Last edited:
Level 16
Joined
Oct 12, 2008
Messages
1,570
JASS:
function IsCar takes nothing returns boolean
    return ( GetFilterUnit() == udg_Car[GetConvertedPlayerId(GetEnumPlayer())] )
endfunction

Try saving the EnumPlayer() from Function1 in a global, and use that
 
Level 10
Joined
Sep 29, 2006
Messages
447
Okay I've cleaned it up a bit and this is what I have thus far:

JASS:
function IsCar takes nothing returns boolean
    return ( GetFilterUnit() == udg_Car[GetConvertedPlayerId(GetEnumPlayer())] )
endfunction

function IsPositionPathable takes real x, real y returns boolean
    local boolean flag
    local unit PathChecker
    set PathChecker = CreateUnit(Player(15), 'hoof', x, y, 0)
    set flag = (GetUnitX(PathChecker) == x) and (GetUnitY(PathChecker) == y)
    call RemoveUnit(PathChecker)
    set PathChecker = null
    return flag
endfunction

function Function2 takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer i = GetPlayerId(GetOwningPlayer(u))
    local real a = GetUnitFacing(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local boolean pathable
    set x = x + 13 * Cos(a * bj_DEGTORAD)
    set y = y + 13 * Sin(a * bj_DEGTORAD)
    set pathable = IsPositionPathable(x , y)
    if ( (udg_Forward[i] == true) and (IsUnitType(u, UNIT_TYPE_STUNNED) == false) and (pathable == true) ) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
    endif
    set u = null
endfunction

function Function1 takes nothing returns nothing
    local group TempUnitGroup = GetUnitsOfPlayerMatching(GetEnumPlayer(), Condition(function IsCar))
    call ForGroup( TempUnitGroup, function Function2 )
    call DestroyGroup(TempUnitGroup)
endfunction

function TriggerActions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Function1 )
endfunction

//===========================================================================
function InitTrig_move_forward_Copy takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEvent( t, 0.03, true )
    call TriggerAddAction( t, function TriggerActions )
endfunction


However, it's still not sliding the unit, any Ideas why?
 
Level 10
Joined
Sep 29, 2006
Messages
447
Ok so I've found the problem function, it's:

JASS:
function IsPositionPathable takes real x, real y returns boolean
    local boolean flag
    local unit PathChecker
    set PathChecker = CreateUnit(Player(15), 'hfoo', x, y, 0)
    set flag = (GetUnitX(PathChecker) == x) and (GetUnitY(PathChecker) ==y)
    call RemoveUnit(PathChecker)
    set PathChecker = null
    return flag
endfunction

flag always returns false, even when I move x,y far away from any unit. Can anybody see why that would happen?
 
Last edited:
Level 4
Joined
Mar 23, 2008
Messages
87
JASS:
call DisplayTextToForce( GetPlayersAll(), R2S(GetUnitX(PathChecker))+" == "+x+" and "+R2S(GetUnitY(PathChecker))+" =="+y )
 

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,547
Ok so I've found the problem function, it's:

JASS:
function IsPositionPathable takes real x, real y returns boolean
    local boolean flag
    local unit PathChecker
    set PathChecker = CreateUnit(Player(15), 'hoof', x, y, 0)
    set flag = (GetUnitX(PathChecker) == x) and (GetUnitY(PathChecker) ==y)
    call RemoveUnit(PathChecker)
    set PathChecker = null
    return flag
endfunction

flag always returns false, even when I move x,y far away from any unit. Can anybody see why that would happen?

if something is PATHING (true), that means it's BLOCKING for that pathing type.

so try ==false or != true, or check pathing on the opposite movement type.
 
Level 10
Joined
Sep 29, 2006
Messages
447
No, setting it to != true or == false doesn't change anything. Any other ideas?

Besides the function doesn't check to see if the pathing is true, it creates a unit at the coordinates i want to slide to, checks if the created units coordinates are the same as the desired coordinates and then returns true if it is and false if it isn't. since units cant be created on unpathable areas, if the coordinates differ, the area is nonpathable, in theory this checks the pathability of a location. So the pathing = blocking doesn't apply in this situation.
 
Level 10
Joined
Sep 29, 2006
Messages
447
Use the IsTerrainWalkable lib, which will check if it's within x units of the placed distance.

Search for it.

Can't search for it, no JASS programs, I'm on a Mac (I'm starting to think getting a Mac was a bad idea, lol). Can you please tell me how to call that function and what parameters it takes?


EDIT: After checking the coordinates using BJDebugMsg, the unit IS created at the desired coordinates, and it IS a footman, so something else must be wrong. Any ideas?

EDIT2: Here I'll post a picture. As you can see, the coordinates for desired locatio, and footman are the not the same, so that is the problem. I need to know why this happens

The coordinates for each unit come immediately after its name.
IsPathableTest2.jpg


By the way, in case you were wondering, the map is going to be a WarCraft adaptation of battle mode from Mario Kart 64. It will be named WarKart.
 
Last edited:
Level 10
Joined
Sep 29, 2006
Messages
447
Holy shit, I just realized I made a mistake in my text testing and the unit is NOT created the desires coordinates, I need to know why. I updated the picture in the previous post to display the right data.


EDIT: Okay I managed to get a working, yet extremely buggy trigger going. I need help making it move smoothly now. Here's my trigger, minus the BJDebugMsg functions used for testing:

JASS:
function IsCar takes nothing returns boolean
    return ( GetFilterUnit() == udg_Car[GetConvertedPlayerId(GetEnumPlayer())] )
endfunction

function IsPositionPathable takes real x, real y returns boolean
    local boolean flag
    local unit PathChecker = CreateUnit(Player(15), 'hfoo', x, y, 0)
    local real x2 = GetUnitX(PathChecker)
    local real y2 = GetUnitY(PathChecker)
    local real d = SquareRoot((x2-x)*(x2-x)+(y2-y)*(y2-y))
    set flag = (d <= 10)
    call RemoveUnit(PathChecker)
    set PathChecker = null
    return flag
endfunction

function Function2 takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer i = GetConvertedPlayerId(GetEnumPlayer())
    local real a = GetUnitFacing(u)
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    local real x2 = x + 100 * Cos(a * bj_DEGTORAD)
    local real y2 = y + 100 * Sin(a * bj_DEGTORAD)
    local boolean pathable
    set x = x + 25 * Cos(a * bj_DEGTORAD)
    set y = y + 25 * Sin(a * bj_DEGTORAD)
    set pathable = IsPositionPathable(x2 , y2)
    if ( (udg_Forward[i] == true) and (IsUnitType(u, UNIT_TYPE_STUNNED) == false) and (pathable == true) ) then
        call SetUnitX(u, x)
        call SetUnitY(u, y)
    endif
    set u = null
endfunction

function Function1 takes nothing returns nothing
    local group TempUnitGroup = GetUnitsOfPlayerMatching(GetEnumPlayer(), Condition(function IsCar))
    call ForGroup( TempUnitGroup, function Function2 )
    call DestroyGroup(TempUnitGroup)
endfunction

function TriggerActions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Function1 )
endfunction

//===========================================================================
function InitTrig_move_forward_Copy takes nothing returns nothing
    local trigger t = CreateTrigger(  )
    call TriggerRegisterTimerEvent( t, 0.03, true )
    call TriggerAddAction( t, function TriggerActions )
endfunction

Basically what happens is that sometimes flag returns true and other times it doesnt so the movement is very choppy and buggy. I'm attaching the map as well so you guys can have a look, the trigger is under the movement category and is called "move forward copy." the other triggers use an old, and sometimes failed system to move that I will update once I get this one working. Here's the map:
 

Attachments

  • WarKart_v1.0b.w3x
    693.3 KB · Views: 61
Last edited:
Level 10
Joined
Sep 29, 2006
Messages
447
I have that in my new trigger, but it's buggy. If the unit is within 10 of what the designated point is then the unit slides (should I up it to 50?). But its very choppy and the boolean sometimes return false so I need somebody to help me fine tune it. Can anyone help?
 
Level 4
Joined
Mar 23, 2008
Messages
87
Yes you did and now my map is working again, thank you.

Also, I upped the distance to 50 units and it's a little smoother, should I up it even more. I don't know how many units would be too much.

64 points = barrel
128 = guard tower
256 = town hall

128 is also the size of 1 square of texture
JASS:
function MathRoundReal takes real r_number, real r_round returns real
    return  r_number - ModuloReal( r_number , r_round )
endfunction 
function YourFunction takes whatyouwant returns whatyouwant
    local real ux = GetUnitX(GetTriggerUnit())
    local real uy = GetUnitX(GetTriggerUnit())
    set ux = MathRoundReal(ux, 64.00)
    set uy = MathRoundReal(uy, 64.00)
    if ux==number you wanted etc...
endfunction

EDIT: Code monkey is right of course. Town hall is 512, not 256
 
Last edited:

Cokemonkey11

Spell Reviewer
Level 30
Joined
May 9, 2006
Messages
3,547
64 points = barrel
128 = guard tower
256 = town hall

128 is also the size of 1 square of texture
JASS:
function MathRoundReal takes real r_number, real r_round returns real
    return  r_number - ModuloReal( r_number , r_round )
endfunction 
function YourFunction takes whatyouwant returns whatyouwant
    local real ux = GetUnitX(GetTriggerUnit())
    local real uy = GetUnitX(GetTriggerUnit())
    set ux = MathRoundReal(ux, 64.00)
    set uy = MathRoundReal(uy, 64.00)
    if ux==number you wanted etc...
endfunction

Pretty sure town hall is more than 256. But yea, 63 should be a good value just so it doesn't go over barrels.
 
Status
Not open for further replies.
Top