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

[JASS] Teleport back and forth

Status
Not open for further replies.
Level 6
Joined
Feb 6, 2015
Messages
266
I searched for a JASS system/code here that allows teleportation of units from place to place (like a gate-way) but couldn't find any, if anyone can direct me to it, I'd be thankful.

If not, can anyone of the JASS gurus check if there is anything wrong with this trigger then ? its purpose is what the title says

JASS:
function Warps_Actions takes nothing returns nothing
    //from 0 to 2 because there are 3 regions that transport back and forth (3 entrances and 3 exits) 
    set iLoop[1] = 0
    set iLoopEnd[1] = 2
    loop
        exitwhen iLoop[1] > iLoopEnd[1]
        //if on entering side
        if RectContainsUnit( Entrance[iLoop[1]], GetEnteringUnit() ) then
            //Camera adjustments and teleportation
            call IssueImmediateOrderBJ( GetEnteringUnit(), "stop" )
            call SetUserControlForceOff( bj_FORCE_PLAYER[0] )
            call SetCameraTargetControllerNoZForPlayer( Player(0), GetEnteringUnit(), 0, 0, false )
            call SetUnitPositionLocFacingBJ( GetEnteringUnit(), Point[iLoop[1]], 90.00 )
            call TriggerSleepAction( 0.50 )
            call SetCameraBoundsToRectForPlayerBJ( Player(0), Visibility[iLoop[1]] )
            call TriggerSleepAction( 0.50 )
            call ResetToGameCameraForPlayer( Player(0), 1.00 )
            call SetUserControlForceOn( bj_FORCE_PLAYER[0] )
            call CreateFogModifierRectBJ( true, Player(0), FOG_OF_WAR_VISIBLE, Visibility[iLoop[1]] )
        //if on exiting side
        elseif RectContainsUnit( Exit[iLoop[1]], GetEnteringUnit() ) then
            //Camera adjustments and teleportation
            call SetUserControlForceOff( bj_FORCE_PLAYER[0] )
            call SetCameraTargetControllerNoZForPlayer( Player(0), GetEnteringUnit(), 0, 0, false )
            call SetUnitPositionLocFacingLocBJ( GetEnteringUnit(), Another_Point[iLoop[1]], Direction[iLoop[1]] )
            call TriggerSleepAction( 0.50 )
            call SetCameraBoundsToRectForPlayerBJ( Player(0), GetPlayableMapRect() )
            call TriggerSleepAction( 0.50 )
            call ResetToGameCameraForPlayer( Player(0), 1.00 )
            call SetUserControlForceOn( bj_FORCE_PLAYER[0] )
        endif
        set iLoop[1] = iLoop[1] + 1
    endloop
endfunction

//===========================================================================
function InitTrig_iWarp takes nothing returns nothing
    local trigger iWarps = CreateTrigger(  )
    //== Trigger Variables ==//
    // Points
    set Point[0] = Location(-5960, 1493)
    set Point[1] = Location(-5380, -7730)
    set Point[2] = Location(-7560, -4500)
    // Other Points
    set Another_Point[0] = Location(-2230,-2663)
    set Another_Point[1] = Location(-4307,-2652)
    set Another_Point[2] = Location(-3430,-1341)
    // Directions
    set Direction[0] = GetDestructableLoc(gg_dest_LTlt_0801)
    set Direction[1] = GetDestructableLoc(gg_dest_DTlv_8311)
    set Direction[2] = GetDestructableLoc(gg_dest_LTlt_6603)
    // Exits
    set Exit[0] = gg_rct_Mardenhole_Keep
    set Exit[1] = gg_rct_Tirion_House
    set Exit[2] = gg_rct_Stable
    // Entrances
    set Entrance[0] = gg_rct_Mardenhole_Keep_Entrance
    set Entrance[1] = gg_rct_Tirion_House_Entrance
    set Entrance[2] = gg_rct_Stable_Entrance
    // Visiblity
    set Visibility[0] = gg_rct_Keep_Visibility
    set Visibility[1] = gg_rct_House_Visibility
    set Visibility[2] = gg_rct_Stable_Visibility
    //===================//
    call TriggerRegisterEnterRectSimple( iWarps, Entrance[0] )
    call TriggerRegisterEnterRectSimple( iWarps, Entrance[1] )
    call TriggerRegisterEnterRectSimple( iWarps, Entrance[2] )
    call TriggerRegisterEnterRectSimple( iWarps, Exit[0] )
    call TriggerRegisterEnterRectSimple( iWarps, Exit[1] )
    call TriggerRegisterEnterRectSimple( iWarps, Exit[2] )
    call TriggerAddAction( iWarps, function Warps_Actions )
endfunction
 
What happens when you run your current trigger? Does it run? Does it crash?

First focus on registering when a unit enters the the region. Try to display a game message (e.g. call BJDebugMsg("Entered!")), it'll be an easy way to check that the trigger event is working just fine.

Next, try porting the unit instantly to the other location. However, there is a catch. If you move the unit to the other region, then that will fire the "entered rect" event.

Let's say you have region A and region B. When a unit enters region A, he'll be moved to region B. When a unit enters region B, he'll be moved to region A. If you aren't careful, this can infinitely loop. The fix is to disable the trigger before moving the unit, and enable it afterward:
JASS:
call DisableTrigger(GetTriggeringTrigger())
call SetUnitPositionLocFacingBJ( GetEnteringUnit(), Point[iLoop[1]], 90.00 )
call EnableTrigger(GetTriggeringTrigger())

Once you get the teleportation down, try working on the camera movement/etc. Let us know what works and what doesn't, and we'll help you get it functional. :)
 
Status
Not open for further replies.
Top