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

[Solved] check what is wrong with these jass code please

Status
Not open for further replies.
Level 7
Joined
Nov 18, 2012
Messages
312
Hello, I am making a random portal function, which teleports my unit when entering the right portal which has boolean = true.
Can anyone point out my mistake, it doesn't run in WE
Code:
function RandomPortal takes nothing returns integer
return GetRandomInt(1,4)
endfunction
function SetPortalNumber takes nothing returns nothing
set AccessofPortal[RandomPortal()]=true
set AccessofPortal[5]=false 
endfunction
function RegionofPortal takes boolean b2b returns region
if IsPointInRegion(gg_rct_Region_009,0,0)==b2b then
return gg_rct_Region_009
elseif IsPointInRegion(gg_rct_Region_010,0,0)==b2b then
return gg_rct_Region_010
elseif IsPointInRegion(gg_rct_Region_011,0,0)==b2b then
return gg_rct_Region_011
elseif IsPointInRegion(gg_rct_Region_012,0,0)==b2b then
return gg_rct_Region_012
endif
return null
endfunction
function Trig_RandomGen_Actions takes nothing returns nothing
local unit u=GetEnteringUnit()
if IsUnitInRegion(RegionofPortal(AccessofPortal[RandomPortal()]),u)==true then
call SetUnitPositionLoc(u,GetRectCenter(gg_rct_Region_13))
endif 
set u=null      
endfunction

//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
call SetPortalNumber()
set gg_trg_RandomGen1 = CreateTrigger(  )
call TriggerRegisterEnterRegionSimple(gg_trg_RandomGen1,gg_rct_TrainingGround1)
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
4,994
Your trigger has no event. Only an action

JASS:
function InitTrig_RandomGen1 takes nothing returns nothing
call SetPortalNumber()
set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Is that all of your code? Are you sure the map saves and can be launched with just this trigger disabled? The only thing I see is an errant endglobals at the top of your code:
JASS:
//globals within WE
endglobals

and

JASS:
 returns region @r4r@ //can't do that should just be "returns region"
 
Level 7
Joined
Nov 18, 2012
Messages
312
Is that all of your code? Are you sure the map saves and can be launched with just this trigger disabled?

JASS:
 returns region @r4r@ //can't do that should just be "returns region"
yes it's just this part which causes the not able to launch.
Oh yes the return part.. anddd i fixed this part too, it's still not launching
 
Level 7
Joined
Nov 18, 2012
Messages
312
Code:
//===========================================================================
//
// RPG
//
//   Warcraft III map script
//   Generated by the Warcraft III World Editor
//   Date: Mon Sep 12 06:37:39 2016
//   Map Author: AshleyColton
//
//===========================================================================

//***************************************************************************
//*
//*  Global Variables
//*
//***************************************************************************

globals
    // User-defined
    boolean                 udg_AmITheOnlyOnePlaying   = false
    timer                   udg_DungeonTimer           = null
    boolean array           udg_AccessofPortal

    // Generated
    rect                    gg_rct_RegionFirstArea     = null
    rect                    gg_rct_RegionMaskedStartPoint = null
    rect                    gg_rct_RegionStartCharacters = null
    rect                    gg_rct_SHOP_Spawn_Location = null
    rect                    gg_rct_TrainingGround1     = null
    rect                    gg_rct_TrainingGround1_Portal = null
    rect                    gg_rct_RegionStartMask     = null
    rect                    gg_rct_TrapToMap           = null
    rect                    gg_rct_TrapSpawnArea       = null
    rect                    gg_rct_Region_009          = null
    rect                    gg_rct_Region_010          = null
    rect                    gg_rct_Region_011          = null
    rect                    gg_rct_Region_012          = null
    rect                    gg_rct_Region_013          = null
    camerasetup             gg_cam_Camera_Startloc     = null
    sound                   gg_snd_Wintergatan         = null
    trigger                 gg_trg_RPG_Initialization  = null
    trigger                 gg_trg_Text_Tag            = null
    trigger                 gg_trg_Unit_Selection      = null
    trigger                 gg_trg_Anti_SP             = null
    trigger                 gg_trg_Enter_TG_2          = null
    trigger                 gg_trg_EnterTrainingGround1 = null
    trigger                 gg_trg_SpawnTrainingGround1 = null
    trigger                 gg_trg_Enter_Trap1         = null
    trigger                 gg_trg_SpawnMobAtTrap1     = null
    trigger                 gg_trg_LeaveTrainingGround1 = null
    trigger                 gg_trg_Trap_Enter_TrainingGround1 = null
    trigger                 gg_trg_SpawnMobAtTrap2     = null
    trigger                 gg_trg_SpawnMobAtTrap3     = null
    trigger                 gg_trg_RandomGen1          = null
    trigger                 gg_trg_Randomized_Portal_Loc = null
    trigger                 gg_trg_TeleportonPortal    = null
    trigger                 gg_trg_PlayerDies          = null
    trigger                 gg_trg_Tiles               = null
endglobals

function InitGlobals takes nothing returns nothing
    local integer i = 0
    set udg_AmITheOnlyOnePlaying = false
    set udg_DungeonTimer = CreateTimer()
    set i = 0
    loop
        exitwhen (i > 1)
        set udg_AccessofPortal[i] = false
        set i = i + 1
    endloop

endfunction

//***************************************************************************
//*
//*  Sounds
//*
//***************************************************************************

function InitSounds takes nothing returns nothing
    set gg_snd_Wintergatan = CreateSound( "Wintergatan.mp3", true, false, false, 10, 10, "DefaultEAXON" )
    call SetSoundDuration( gg_snd_Wintergatan, 234344 )
    call SetSoundChannel( gg_snd_Wintergatan, 0 )
    call SetSoundVolume( gg_snd_Wintergatan, 127 )
    call SetSoundPitch( gg_snd_Wintergatan, 1.0 )
endfunction

//***************************************************************************
//*
//*  Unit Creation
//*
//***************************************************************************

//===========================================================================
function CreateBuildingsForPlayer10 takes nothing returns nothing
    local player p = Player(10)
    local unit u
    local integer unitID
    local trigger t
    local real life

    set u = CreateUnit( p, 'n004', -13829.5, 12960.7, 32.521 )
    set u = CreateUnit( p, 'n007', -13690.8, 12864.8, 81.521 )
    set u = CreateUnit( p, 'n003', -13836.1, 13189.9, 342.059 )
    set u = CreateUnit( p, 'n001', -13536.4, 13307.2, 258.110 )
    set u = CreateUnit( p, 'n005', -13709.0, 13307.2, 284.456 )
    set u = CreateUnit( p, 'n009', -13415.9, 13215.2, 148.056 )
    set u = CreateUnit( p, 'n008', -13405.9, 12997.4, 206.978 )
    set u = CreateUnit( p, 'n006', -13498.3, 12894.6, 117.645 )
endfunction

//===========================================================================
function CreatePlayerBuildings takes nothing returns nothing
    call CreateBuildingsForPlayer10(  )
endfunction

//===========================================================================
function CreatePlayerUnits takes nothing returns nothing
endfunction

//===========================================================================
function CreateAllUnits takes nothing returns nothing
    call CreatePlayerBuildings(  )
    call CreatePlayerUnits(  )
endfunction

//***************************************************************************
//*
//*  Regions
//*
//***************************************************************************

function CreateRegions takes nothing returns nothing
    local weathereffect we

    set gg_rct_RegionFirstArea = Rect( -15264.0, 9280.0, -10432.0, 13952.0 )
    set we = AddWeatherEffect( gg_rct_RegionFirstArea, 'MEds' )
    call EnableWeatherEffect( we, true )
    set gg_rct_RegionMaskedStartPoint = Rect( -16384.0, 9824.0, -9984.0, 16320.0 )
    set gg_rct_RegionStartCharacters = Rect( -14816.0, 11968.0, -12448.0, 14176.0 )
    set gg_rct_SHOP_Spawn_Location = Rect( -16096.0, 10656.0, -13600.0, 11840.0 )
    set gg_rct_TrainingGround1 = Rect( -12384.0, 10656.0, -11264.0, 11840.0 )
    set gg_rct_TrainingGround1_Portal = Rect( -14048.0, 10912.0, -13600.0, 11616.0 )
    set gg_rct_RegionStartMask = Rect( -13664.0, 13024.0, -13632.0, 13056.0 )
    set gg_rct_TrapToMap = Rect( -12896.0, 14336.0, -12800.0, 15200.0 )
    set gg_rct_TrapSpawnArea = Rect( -16000.0, 14240.0, -12896.0, 15328.0 )
    set gg_rct_Region_009 = Rect( -12064.0, 10656.0, -11680.0, 10720.0 )
    set gg_rct_Region_010 = Rect( -11328.0, 11072.0, -11264.0, 11488.0 )
    set gg_rct_Region_011 = Rect( -12032.0, 11776.0, -11648.0, 11840.0 )
    set gg_rct_Region_012 = Rect( -12384.0, 11072.0, -12320.0, 11488.0 )
    set gg_rct_Region_013 = Rect( -15808.0, 14752.0, -15776.0, 14784.0 )
endfunction

//***************************************************************************
//*
//*  Cameras
//*
//***************************************************************************

function CreateCameras takes nothing returns nothing

    set gg_cam_Camera_Startloc = CreateCameraSetup(  )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_ZOFFSET, 30.0, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_ROTATION, 90.0, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_ANGLE_OF_ATTACK, 0.0, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_TARGET_DISTANCE, 931.4, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_ROLL, 0.0, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_FIELD_OF_VIEW, 70.0, 0.0 )
    call CameraSetupSetField( gg_cam_Camera_Startloc, CAMERA_FIELD_FARZ, 5000.0, 0.0 )
    call CameraSetupSetDestPosition( gg_cam_Camera_Startloc, -13453.8, 12717.3, 0.0 )

endfunction

//***************************************************************************
//*
//*  Triggers
//*
//***************************************************************************

//===========================================================================
// Trigger: RPG Initialization
//
// Enable vision in start point
// play the music wintergatan
// set the sky to universe model
// set camera bount to start point
// locks any selected unit to unit's perspective
// text tag are beta
// VARIABLES to set stages, if 1 go to area 1 from trap, if 2 go to area 2..
//===========================================================================
function Trig_RPG_Initialization_Actions takes nothing returns nothing
    call CreateLeaderboardBJ( GetPlayersAll(), "TRIGSTR_033" )
    call CreateFogModifierRectBJ( true, Player(0), FOG_OF_WAR_VISIBLE, gg_rct_RegionStartCharacters )
    call PlaySoundAtPointBJ( gg_snd_Wintergatan, 100, GetPlayerStartLocationLoc(Player(0)), 0 )
    call SetSkyModel( "MoonySky.mdx" )
    call SetCameraBoundsToRectForPlayerBJ( Player(0), gg_rct_RegionStartMask )
    call SetCameraTargetControllerNoZForPlayer( Player(0), GetTriggerUnit(), 0, 0, true )
    call SetTimeOfDay( 19.00 )
    call UseTimeOfDayBJ( false )
endfunction

//===========================================================================
function InitTrig_RPG_Initialization takes nothing returns nothing
    set gg_trg_RPG_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RPG_Initialization, function Trig_RPG_Initialization_Actions )
endfunction

//===========================================================================
// Trigger: Text Tag
//===========================================================================
function Trig_Text_Tag_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Text_Tag_Actions takes nothing returns nothing
    call CreateTextTagUnitBJ( GetUnitName(GetFilterUnit()), GetFilterUnit(), 0, 24.00, 100, 100, 100, 60.00 )
    call CreateTextTagLocBJ( "TRIGSTR_035", Location(15200.00, 11540.00), 0, 10, 100, 100, 100, 0 )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetPlayersAll() )
endfunction

//===========================================================================
function InitTrig_Text_Tag takes nothing returns nothing
    set gg_trg_Text_Tag = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Text_Tag, 0.00 )
    call TriggerAddCondition( gg_trg_Text_Tag, Condition( function Trig_Text_Tag_Conditions ) )
    call TriggerAddAction( gg_trg_Text_Tag, function Trig_Text_Tag_Actions )
endfunction

//===========================================================================
// Trigger: Unit Selection
//
// any player selects a unit, if target= true then add unit to player
// conditions:
// region start point has the selected unit
// number of units in region owned by red = 0, cant have more than 1 characters
// selected unit must be a structure(in actions)
// actions:
// creates the unit, at the new location
// lock camera to last created unit
//===========================================================================
function Trig_Unit_Selection_Conditions takes nothing returns boolean
    if ( not ( CountUnitsInGroup(GetUnitsInRectOfPlayer(gg_rct_RegionFirstArea, Player(0))) == 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Unit_Selection_Func002001 takes nothing returns boolean
    return ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_STRUCTURE) == true )
endfunction

function Trig_Unit_Selection_Actions takes nothing returns nothing
    if ( Trig_Unit_Selection_Func002001() ) then
        call CreateNUnitsAtLoc( 1, String2UnitIdBJ(UnitId2StringBJ(GetUnitTypeId(GetTriggerUnit()))), Player(0), Location(-15000.00, 11200.00), bj_UNIT_FACING )
    else
        call DoNothing(  )
    endif
    call SetCameraBoundsToRectForPlayerBJ( Player(0), gg_rct_SHOP_Spawn_Location )
    call SetCameraTargetControllerNoZForPlayer( Player(0), GetLastCreatedUnit(), 0, 0, false )
    call FogModifierStop( GetLastCreatedFogModifier() )
endfunction

//===========================================================================
function InitTrig_Unit_Selection takes nothing returns nothing
    set gg_trg_Unit_Selection = CreateTrigger(  )
    call TriggerRegisterPlayerSelectionEventBJ( gg_trg_Unit_Selection, Player(0), true )
    call TriggerAddCondition( gg_trg_Unit_Selection, Condition( function Trig_Unit_Selection_Conditions ) )
    call TriggerAddAction( gg_trg_Unit_Selection, function Trig_Unit_Selection_Actions )
endfunction

//===========================================================================
// Trigger: EnterTrainingGround1
//
// --working--
// Unit enter TG1 portal
// Move to TG1
// Camerabound to TG1
// Camera on unit from red
// Start DungeonTimer Countdown to be expelled from dungeon
//===========================================================================
function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_TrainingGround1) )
    call SetCameraBoundsToRectForPlayerBJ( Player(0), gg_rct_TrainingGround1 )
    call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(gg_rct_TrainingGround1, Player(0))), 0, 0, false )
    call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
endfunction

//===========================================================================
function InitTrig_EnterTrainingGround1 takes nothing returns nothing
    set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TrainingGround1_Portal )
    call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
endfunction

//===========================================================================
// Trigger: SpawnTrainingGround1
//
// works
//===========================================================================

function Trig_SpawnTrainingGround1_Conditions takes nothing returns boolean
    if ( not ( CountUnitsInGroup(GetUnitsInRectAll(gg_rct_TrainingGround1)) <= 15 ) ) then
        return false
    endif
    if (not (CountUnitsInGroup(GetUnitsInRectAll(gg_rct_TrainingGround1)) > 0)) then
    return false
    endif
    return true
endfunction


function Trig_SpawnTrainingGround1_Actions takes nothing returns nothing
        call TriggerRegisterTimerEventPeriodic( GetTriggeringTrigger(), 5.00 )
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(11), GetRandomLocInRect(gg_rct_TrainingGround1), bj_UNIT_FACING )
endfunction
function InitTrig_SpawnTrainingGround1 takes nothing returns nothing
    set gg_trg_SpawnTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_SpawnTrainingGround1, gg_rct_TrainingGround1 )
    call TriggerAddCondition( gg_trg_SpawnTrainingGround1, Condition( function Trig_SpawnTrainingGround1_Conditions ) )
    call TriggerAddAction( gg_trg_SpawnTrainingGround1, function Trig_SpawnTrainingGround1_Actions )
endfunction
//===========================================================================
// Trigger: SpawnMobAtTrap1
//
// need condition unit is hero, to prevent mob units entering next map
//===========================================================================
function Trig_SpawnMobAtTrap1_Conditions takes nothing returns boolean
    if ( not ( RectContainsUnit(gg_rct_TrapSpawnArea, GetEnteringUnit()) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_SpawnMobAtTrap1_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(11), GetRandomLocInRect(gg_rct_TrapSpawnArea), bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_SpawnMobAtTrap1 takes nothing returns nothing
    set gg_trg_SpawnMobAtTrap1 = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_SpawnMobAtTrap1, 0.50 )
    call TriggerAddCondition( gg_trg_SpawnMobAtTrap1, Condition( function Trig_SpawnMobAtTrap1_Conditions ) )
    call TriggerAddAction( gg_trg_SpawnMobAtTrap1, function Trig_SpawnMobAtTrap1_Actions )
endfunction

//===========================================================================
// Trigger: LeaveTrainingGround1
//
// if leave region, destroy the timer
// destroy units
//===========================================================================
function Trig_LeaveTrainingGround1_Actions takes nothing returns nothing
    call DisableTrigger( gg_trg_SpawnMobAtTrap1 )
endfunction

//===========================================================================
function InitTrig_LeaveTrainingGround1 takes nothing returns nothing
    set gg_trg_LeaveTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterLeaveRectSimple( gg_trg_LeaveTrainingGround1, gg_rct_TrainingGround1 )
    call TriggerAddAction( gg_trg_LeaveTrainingGround1, function Trig_LeaveTrainingGround1_Actions )
endfunction

//===========================================================================
// Trigger: Trap Enter TrainingGround1
//
// //working
//===========================================================================
function Trig_Trap_Enter_TrainingGround1_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_TrainingGround1) )
endfunction

//===========================================================================
function InitTrig_Trap_Enter_TrainingGround1 takes nothing returns nothing
    set gg_trg_Trap_Enter_TrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Trap_Enter_TrainingGround1, gg_rct_TrapToMap )
    call TriggerAddAction( gg_trg_Trap_Enter_TrainingGround1, function Trig_Trap_Enter_TrainingGround1_Actions )
endfunction

//===========================================================================
// Trigger: PlayerDies
//
// if player dies kick player
//===========================================================================
function Trig_PlayerDies_Actions takes nothing returns nothing
endfunction

//===========================================================================
function InitTrig_PlayerDies takes nothing returns nothing
    set gg_trg_PlayerDies = CreateTrigger(  )
    call TriggerAddAction( gg_trg_PlayerDies, function Trig_PlayerDies_Actions )
endfunction

//===========================================================================
// Trigger: Tiles
//===========================================================================
function Trig_Tiles_Actions takes nothing returns nothing
    call SetTerrainTypeBJ( GetRectCenter(GetPlayableMapRect()), 'Ldrt', -1, 5, 0 )
endfunction

//===========================================================================
function InitTrig_Tiles takes nothing returns nothing
    set gg_trg_Tiles = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Tiles, function Trig_Tiles_Actions )
endfunction

//===========================================================================
function InitCustomTriggers takes nothing returns nothing
    call InitTrig_RPG_Initialization(  )
    call InitTrig_Text_Tag(  )
    call InitTrig_Unit_Selection(  )
    call InitTrig_EnterTrainingGround1(  )
    call InitTrig_SpawnTrainingGround1(  )
    call InitTrig_SpawnMobAtTrap1(  )
    call InitTrig_LeaveTrainingGround1(  )
    call InitTrig_Trap_Enter_TrainingGround1(  )
    call InitTrig_PlayerDies(  )
    call InitTrig_Tiles(  )
endfunction

//===========================================================================
function RunInitializationTriggers takes nothing returns nothing
    call ConditionalTriggerExecute( gg_trg_RPG_Initialization )
    call ConditionalTriggerExecute( gg_trg_Tiles )
endfunction

//***************************************************************************
//*
//*  Players
//*
//***************************************************************************

function InitCustomPlayerSlots takes nothing returns nothing

    // Player 0
    call SetPlayerStartLocation( Player(0), 0 )
    call ForcePlayerStartLocation( Player(0), 0 )
    call SetPlayerColor( Player(0), ConvertPlayerColor(0) )
    call SetPlayerRacePreference( Player(0), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(0), false )
    call SetPlayerController( Player(0), MAP_CONTROL_USER )

    // Player 1
    call SetPlayerStartLocation( Player(1), 1 )
    call ForcePlayerStartLocation( Player(1), 1 )
    call SetPlayerColor( Player(1), ConvertPlayerColor(1) )
    call SetPlayerRacePreference( Player(1), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(1), false )
    call SetPlayerController( Player(1), MAP_CONTROL_USER )

    // Player 2
    call SetPlayerStartLocation( Player(2), 2 )
    call ForcePlayerStartLocation( Player(2), 2 )
    call SetPlayerColor( Player(2), ConvertPlayerColor(2) )
    call SetPlayerRacePreference( Player(2), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(2), false )
    call SetPlayerController( Player(2), MAP_CONTROL_USER )

    // Player 3
    call SetPlayerStartLocation( Player(3), 3 )
    call ForcePlayerStartLocation( Player(3), 3 )
    call SetPlayerColor( Player(3), ConvertPlayerColor(3) )
    call SetPlayerRacePreference( Player(3), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(3), false )
    call SetPlayerController( Player(3), MAP_CONTROL_USER )

    // Player 4
    call SetPlayerStartLocation( Player(4), 4 )
    call ForcePlayerStartLocation( Player(4), 4 )
    call SetPlayerColor( Player(4), ConvertPlayerColor(4) )
    call SetPlayerRacePreference( Player(4), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(4), false )
    call SetPlayerController( Player(4), MAP_CONTROL_USER )

    // Player 5
    call SetPlayerStartLocation( Player(5), 5 )
    call ForcePlayerStartLocation( Player(5), 5 )
    call SetPlayerColor( Player(5), ConvertPlayerColor(5) )
    call SetPlayerRacePreference( Player(5), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(5), false )
    call SetPlayerController( Player(5), MAP_CONTROL_USER )

    // Player 6
    call SetPlayerStartLocation( Player(6), 6 )
    call ForcePlayerStartLocation( Player(6), 6 )
    call SetPlayerColor( Player(6), ConvertPlayerColor(6) )
    call SetPlayerRacePreference( Player(6), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(6), false )
    call SetPlayerController( Player(6), MAP_CONTROL_USER )

    // Player 7
    call SetPlayerStartLocation( Player(7), 7 )
    call ForcePlayerStartLocation( Player(7), 7 )
    call SetPlayerColor( Player(7), ConvertPlayerColor(7) )
    call SetPlayerRacePreference( Player(7), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(7), false )
    call SetPlayerController( Player(7), MAP_CONTROL_USER )

    // Player 8
    call SetPlayerStartLocation( Player(8), 8 )
    call ForcePlayerStartLocation( Player(8), 8 )
    call SetPlayerColor( Player(8), ConvertPlayerColor(8) )
    call SetPlayerRacePreference( Player(8), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(8), false )
    call SetPlayerController( Player(8), MAP_CONTROL_USER )

    // Player 9
    call SetPlayerStartLocation( Player(9), 9 )
    call ForcePlayerStartLocation( Player(9), 9 )
    call SetPlayerColor( Player(9), ConvertPlayerColor(9) )
    call SetPlayerRacePreference( Player(9), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(9), false )
    call SetPlayerController( Player(9), MAP_CONTROL_USER )

    // Player 10
    call SetPlayerStartLocation( Player(10), 10 )
    call ForcePlayerStartLocation( Player(10), 10 )
    call SetPlayerColor( Player(10), ConvertPlayerColor(10) )
    call SetPlayerRacePreference( Player(10), RACE_PREF_HUMAN )
    call SetPlayerRaceSelectable( Player(10), false )
    call SetPlayerController( Player(10), MAP_CONTROL_NEUTRAL )

    // Player 11
    call SetPlayerStartLocation( Player(11), 11 )
    call ForcePlayerStartLocation( Player(11), 11 )
    call SetPlayerColor( Player(11), ConvertPlayerColor(11) )
    call SetPlayerRacePreference( Player(11), RACE_PREF_NIGHTELF )
    call SetPlayerRaceSelectable( Player(11), false )
    call SetPlayerController( Player(11), MAP_CONTROL_COMPUTER )

endfunction

function InitCustomTeams takes nothing returns nothing
    // Force: TRIGSTR_016
    call SetPlayerTeam( Player(0), 0 )
    call SetPlayerTeam( Player(1), 0 )
    call SetPlayerTeam( Player(2), 0 )
    call SetPlayerTeam( Player(3), 0 )
    call SetPlayerTeam( Player(4), 0 )
    call SetPlayerTeam( Player(5), 0 )
    call SetPlayerTeam( Player(6), 0 )
    call SetPlayerTeam( Player(7), 0 )
    call SetPlayerTeam( Player(8), 0 )
    call SetPlayerTeam( Player(9), 0 )

    //   Allied
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(0), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(1), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(2), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(3), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(4), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(5), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(6), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(8), true )
    call SetPlayerAllianceStateAllyBJ( Player(7), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(8), Player(9), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(0), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(1), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(2), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(3), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(4), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(5), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(6), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(7), true )
    call SetPlayerAllianceStateAllyBJ( Player(9), Player(8), true )

    //   Shared Vision
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(0), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(1), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(2), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(3), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(4), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(5), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(6), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(8), true )
    call SetPlayerAllianceStateVisionBJ( Player(7), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(8), Player(9), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(0), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(1), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(2), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(3), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(4), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(5), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(6), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(7), true )
    call SetPlayerAllianceStateVisionBJ( Player(9), Player(8), true )

    // Force: TRIGSTR_019
    call SetPlayerTeam( Player(11), 1 )

    // Force: TRIGSTR_023
    call SetPlayerTeam( Player(10), 2 )

endfunction

function InitAllyPriorities takes nothing returns nothing

    call SetStartLocPrioCount( 0, 9 )
    call SetStartLocPrio( 0, 0, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 1, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 2, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 3, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 4, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 0, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 1, 9 )
    call SetStartLocPrio( 1, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 1, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 2, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 3, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 4, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 1, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 2, 9 )
    call SetStartLocPrio( 2, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 2, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 3, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 4, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 2, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 3, 9 )
    call SetStartLocPrio( 3, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 3, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 4, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 3, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 4, 9 )
    call SetStartLocPrio( 4, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 4, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 4, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 5, 9 )
    call SetStartLocPrio( 5, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 4, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 5, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 5, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 6, 9 )
    call SetStartLocPrio( 6, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 4, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 5, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 6, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 6, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 7, 9 )
    call SetStartLocPrio( 7, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 4, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 5, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 6, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 7, 8, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 7, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 8, 9 )
    call SetStartLocPrio( 8, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 4, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 5, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 6, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 7, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 8, 8, 9, MAP_LOC_PRIO_HIGH )

    call SetStartLocPrioCount( 9, 9 )
    call SetStartLocPrio( 9, 0, 0, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 1, 1, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 2, 2, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 3, 3, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 4, 4, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 5, 5, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 6, 6, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 7, 7, MAP_LOC_PRIO_HIGH )
    call SetStartLocPrio( 9, 8, 8, MAP_LOC_PRIO_HIGH )
endfunction

//***************************************************************************
//*
//*  Main Initialization
//*
//***************************************************************************

//===========================================================================
function main takes nothing returns nothing
    call SetCameraBounds( -16128.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), -15872.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM), 16000.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), 15360.0 - GetCameraMargin(CAMERA_MARGIN_TOP), -16128.0 + GetCameraMargin(CAMERA_MARGIN_LEFT), 15360.0 - GetCameraMargin(CAMERA_MARGIN_TOP), 16000.0 - GetCameraMargin(CAMERA_MARGIN_RIGHT), -15872.0 + GetCameraMargin(CAMERA_MARGIN_BOTTOM) )
    call SetDayNightModels( "Environment\\DNC\\DNCLordaeron\\DNCLordaeronTerrain\\DNCLordaeronTerrain.mdl", "Environment\\DNC\\DNCLordaeron\\DNCLordaeronUnit\\DNCLordaeronUnit.mdl" )
    call NewSoundEnvironment( "Default" )
    call SetAmbientDaySound( "NorthrendDay" )
    call SetAmbientNightSound( "NorthrendNight" )
    call SetMapMusic( "Music", true, 0 )
    call InitSounds(  )
    call CreateRegions(  )
    call CreateCameras(  )
    call CreateAllUnits(  )
    call InitBlizzard(  )
    call InitGlobals(  )
    call InitCustomTriggers(  )
    call RunInitializationTriggers(  )

endfunction

//***************************************************************************
//*
//*  Map Configuration
//*
//***************************************************************************

function config takes nothing returns nothing
    call SetMapName( "TRIGSTR_003" )
    call SetMapDescription( "TRIGSTR_005" )
    call SetPlayers( 12 )
    call SetTeams( 12 )
    call SetGamePlacement( MAP_PLACEMENT_TEAMS_TOGETHER )

    call DefineStartLocation( 0, -13632.0, 12992.0 )
    call DefineStartLocation( 1, -13632.0, 12992.0 )
    call DefineStartLocation( 2, -13632.0, 12992.0 )
    call DefineStartLocation( 3, -13632.0, 12992.0 )
    call DefineStartLocation( 4, -13632.0, 12992.0 )
    call DefineStartLocation( 5, -13632.0, 12992.0 )
    call DefineStartLocation( 6, -13632.0, 12992.0 )
    call DefineStartLocation( 7, -13632.0, 12992.0 )
    call DefineStartLocation( 8, -13632.0, 12992.0 )
    call DefineStartLocation( 9, -13632.0, 12992.0 )
    call DefineStartLocation( 10, 1280.0, -6400.0 )
    call DefineStartLocation( 11, 12416.0, -3776.0 )

    // Player setup
    call InitCustomPlayerSlots(  )
    call InitCustomTeams(  )
    call InitAllyPriorities(  )
endfunction

PS: i have no idea how to post in vjass code
 
Level 7
Joined
Nov 18, 2012
Messages
312
No not the war3map.j I just mean whatever is in your RandomGen trigger. The current version of what you posted in your first post. Also you should use [code=jass] tags instead of [code] tags.
JASS:
function RandomPortal takes nothing returns integer
return GetRandomInt(1,4)
endfunction
function SetPortalNumber takes nothing returns nothing
set AccessofPortal[RandomPortal()]=true
set AccessofPortal[5]=false 
endfunction
function RegionofPortal takes boolean b2b returns region
if IsPointInRegion(gg_rct_Region_009,0,0)==b2b then
return gg_rct_Region_009
elseif IsPointInRegion(gg_rct_Region_010,0,0)==b2b then
return gg_rct_Region_010
elseif IsPointInRegion(gg_rct_Region_011,0,0)==b2b then
return gg_rct_Region_011
elseif IsPointInRegion(gg_rct_Region_012,0,0)==b2b then
return gg_rct_Region_012
endif
return null
endfunction
function Trig_RandomGen_Actions takes nothing returns nothing
local unit u=GetEnteringUnit()
if IsUnitInRegion(RegionofPortal(AccessofPortal[RandomPortal()]),u)==true then
call SetUnitPositionLoc(u,GetRectCenter(gg_rct_Region_13))
endif 
set u=null      
endfunction

//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
call SetPortalNumber()
set gg_trg_RandomGen1 = CreateTrigger(  )
call TriggerRegisterEnterRegionSimple(gg_trg_RandomGen1,gg_rct_TrainingGround1)
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
The 0s in IsPointInRegion(gg_rct_Region_009,0,0) and related calls should be 0.00s because the native expects real inputs. Granted ints will work just fine but it won't work the other way around (typecasting reals to ints).

When you want to use JASS to refer a variable you've made in the variable editor, note that you must change all spaces to underscores and append "udg_" to the beginning of it because that's what the WE does for user defined globals. For example you have boolean array udg_AccessofPortal defined but your functions reference AccessofPortal[...] without its prefix.

Array variables DON'T have initialized values unless you set them that way in the variable editor. You can't access one that hasn't been defined, like a local variable:
JASS:
//Causes a crash
    local integer foo
    call BJDebugMsg(I2S(foo)) //'foo' has no value

//No crash
    local integer foo
    set foo = 5 //now it has a value!
    call BJDebugMsg(I2S(foo))

//Causes a crash
    integer array foo //no indices of foo have values
    call BJDebugMsg(I2S(foo[2]))

//No crash
    integer array foo
    set foo[3] = 7 //only foo[3] is defined
    call BJDebugMsg(I2S(foo[3]))

//Crash again
    integer array foo
    set foo[253] = 99 //only foo[253] is defined
    call BJDebugMsg(I2S(foo[1])) //foo[1] isn't defined!


//What you did:
function SetPortalNumber takes nothing returns nothing
    set AccessofPortal[RandomPortal()]=true //call this AccessofPortal[R]
    set AccessofPortal[5]=false
endfunction
//Only AccessofPortal[R] and AcessofPortal[5] are defined, so
//Getting the 'value' of AccessofPortal[2] will cause a crash if R != 2
//This might not happen with booleans-- they could be auto-initialized to true or false, idk

None of these is likely causing the crash, though, and I believe the problem is with rects and regions. What GUI calls a "region" is really a collection of different rect objects (rectangles). Since a rect can only be rectangular (granted, any dimension, but rectangular nonetheless), you can create more complex triggerable areas by combining multiple rects under the grouping of a Region. It was handy you posted the war3map.j because it shows me you have:
JASS:
    rect                    gg_rct_RegionFirstArea     = null
    rect                    gg_rct_RegionMaskedStartPoint = null
    rect                    gg_rct_RegionStartCharacters = null
    rect                    gg_rct_SHOP_Spawn_Location = null
    rect                    gg_rct_TrainingGround1     = null
    rect                    gg_rct_TrainingGround1_Portal = null
    rect                    gg_rct_RegionStartMask     = null
    rect                    gg_rct_TrapToMap           = null
    rect                    gg_rct_TrapSpawnArea       = null
    rect                    gg_rct_Region_009          = null
    rect                    gg_rct_Region_010          = null
    rect                    gg_rct_Region_011          = null
    rect                    gg_rct_Region_012          = null
    rect                    gg_rct_Region_013          = null

//All rects!
But the call you're using takes regions: native IsPointInRegion region whichRegion, real x, real y returns boolean and there isn't an equivalent call for rects. You are left with two options:
  1. Use native CreateRegion takes nothing returns nothing, native RegionAddRect takes region whichRegion, rect r, and native RemoveRegion takes region whichRegion in sequence to create region versions of the rects before you check and return the appropriate region.

    Why not create a global region variable that you only have to set once? You can't make a region variable with the variable editor-- only rects! So unless you have the JNGP installed you won't be able to just make your own
    JASS:
    globals
        region array MoveRegions
    endglobals
  2. Change your method entirely, which I would recommend because option 1. is inefficient and will inevitably leak regions you don't destroy before returning them. You can wildly simplify what you've done by instead getting the unit's x and y coordinates and then checking if they're in the boundaries for each rect.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
What I would do:
JASS:
function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function SetPortalNumber takes nothing returns nothing
    local integer i = 1

    loop
        set udg_AccessofPortal[i] = false
        set i = i+1
        exitwhen i > TOTAL_PORTALS //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
    endloop

    set udg_AccessofPortal[RandomPortal()] = true
endfunction

function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1
    local rect CheckRect

    loop
        if i == 1 then
            set CheckRect = gg_rct_Region_009
        elseif i == 2 then
            set CheckRect = gg_rct_Region_010
        elseif i == 3 then
            set CheckRect = gg_rct_Region_011
        elseif i == 4 then
            set CheckRect = gg_rct_Region_012
        else
            set CheckRect = null //this is a safety call, probably unnecessary
        endif

        set rxMax = GetRectMaxX(CheckRect)
        set rxMin = GetRectMinX(CheckRect)
        set ryMax = GetRectMaxY(CheckRect)
        set ryMin = GetRectMinY(CheckRect)

        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin)
            //If ux and uy are within its boundary then the unit must be inside
            call SetUnitX(GetRectCenterX(gg_rct_Region_13))
            call SetUnitY(GetRectCenterY(gg_rct_Region_13))
            exitwhen true //leave the loop early, no need to do more
        endif

        set i = i+1
        exitwhen i > TOTAL_PORTALS // Probably 4, again
    endloop

    set u = null
    set CheckRect = null
endfunction

//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
    call SetPortalNumber()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerRegisterEnterRegionSimple(gg_trg_RandomGen1,gg_rct_TrainingGround1)
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
The 0s in
IsPointInRegion(gg_rct_Region_009,0,0)
and related calls should be 0.00s because the native expects real inputs.
Automatic type cast... Integers can be mixed with real expressions and they get automatically typecast to real. Reals will never be automatically typecast to integer and instead need to be rounded with functions like R2I.

Array variables DON'T have initialized values unless you set them that way in the variable editor. You can't access one that hasn't been defined, like a local variable:
All JASS arrays have all indices initialized to a default value. I incorrectly stated the opposite in the past but I was wrong. You can access array indices that have never been touched before and they will have default values such as null, 0, 0.0, etc.

It is only non-array variables that must be initialized before first access. Trying to access a non-array variable, either global or local, before it has been initialized will result in a thread crash.

AnonymousPro do you get a syntax error on map save? Or does the trigger not work as intended in game?

If you get a syntax error please post it. As a rough guess the cause will be because you are not using "udg_" prefix for GUI global variables.
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Automatic type cast... Integers can be mixed with real expressions and they get automatically typecast to real. Reals will never be automatically typecast to integer and instead need to be rounded with functions like R2I.
Granted ints will work just fine but it won't work the other way around (typecasting reals to ints).
!
All JASS arrays have all indices initialized to a default value. I incorrectly stated the opposite in the past but I was wrong. You can access array indices that have never been touched before and they will have default values such as null, 0, 0.0, etc.
Good to know I remembered this wrong.
 
Level 7
Joined
Nov 18, 2012
Messages
312
@Pyrogasm thank you for the very detailed explanation, I might need some time to digest.

can region array be used in jass, or is it vjass?
i have never used it in jass before, i need to clarify this because I don't know how to use vjass

@Dr Super Good Thank you for the clarification, that helps me a lot

Most likely it is a syntax error, I don't know how to run syntax check on JNGP, and I didn't run syntax check on war3map.j either.
The syntax error, is most likely udg_AccessofPortal, which made my variable undeclared as I wrote as AccessofPortal

now my solution is
1. fix the syntax error real quick.
2. use a region array for now
 
Level 7
Joined
Nov 18, 2012
Messages
312
guys, as a said note
do not return integer in functions which returns real
JASS:
function a takes nothing returns real
return 1234
endfunction
will fuck you up
JASS:
function a takes nothing returns real
return 1234.
endfunction
is fine
what u said contradicts to @Dr Super Good . He said integers get automatically typecast to reals, so it should be fine.

@Pyrogasm , I have used a lot of locations when I started with GUI, this is my first map so I just happened to learn how to convert code in jass yesterday.

noted
JASS:
 //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)

I am making a dungeon-like game, masking the map, set camera on the character, when character move to portals, there is random chance one of the portal is real.
if it's real, it would send you to the next town, or next dungeon.
if you enter the fake portal you will be sent to trap, a hell flock of monsters and you might die.

so for this area, it has 4 portals, and the rect where the portals are will be the portals that will be used for random teleporting.
 
Last edited:
Level 7
Joined
Nov 18, 2012
Messages
312
@Pyrogasm
I'm using this to remove the leak of the
JASS:
SetTerrainTypeBJ
, by using
JASS:
SetTerrainType
The loop onnly seem to run once, why is that so?
it only set my first rct to the new tiles
JASS:
function Trig_Tiles_Actions takes nothing returns nothing
//Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1

    loop
    exitwhen i>4
        if i == 1 then
            set udg_CheckRect[i] = gg_rct_Area14
        elseif i == 2 then
            set udg_CheckRect[i] = gg_rct_Area15
        elseif i == 3 then
            set udg_CheckRect[i] = gg_rct_Area16
        elseif i == 4 then
            set udg_CheckRect[i] = gg_rct_Area17
        else
            set udg_CheckRect[i] = null //this is a safety call, probably unnecessary
        endif
        set rxMax = GetRectMaxX(udg_CheckRect[i])
        set rxMin = GetRectMinX(udg_CheckRect[i])
        set ryMax = GetRectMaxY(udg_CheckRect[i])
        set ryMin = GetRectMinY(udg_CheckRect[i])
//    call SetTerrainTypeBJ( GetRectCenter(gg_rct_Region_013), 'Ldrt', -1, 8, 1 )

call SetTerrainType(GetRectCenterX(udg_CheckRect[i]),GetRectCenterY(udg_CheckRect[i]), 'Ldrt', -1, 8, 1 )
  set i = i+1

    endloop

    set udg_CheckRect[i] = null 
endfunction



//===========================================================================
function InitTrig_Tiles takes nothing returns nothing
    set gg_trg_Tiles = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Tiles, function Trig_Tiles_Actions )
endfunction
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
ok, did i make any mistake in returning reals?
You have to return the correct type because otherwise the type cast exploit strikes back at you and returns a physical cast as opposed to a logical one. The result is one can create a separate set of I2R and R2I type casts which return values that are kept bit identical, rather than numerically similar.

The loop onnly seem to run once, why is that so?
it only set my first rct to the new tiles
Your loop makes little sense? Try this.
JASS:
function Trig_Tiles_Actions takes nothing returns nothing
//Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1

    set udg_CheckRect[1] = gg_rct_Area14
    set udg_CheckRect[2] = gg_rct_Area15
    set udg_CheckRect[3] = gg_rct_Area16
    set udg_CheckRect[4] = gg_rct_Area17

    loop
    exitwhen i>4
        call SetTerrainType(GetRectCenterX(udg_CheckRect[i]),GetRectCenterY(udg_CheckRect[i]), 'Ldrt', -1, 8, 1 )
        set udg_CheckRect[i] = null 
        set i = i+1
    endloop
endfunction

//===========================================================================
function InitTrig_Tiles takes nothing returns nothing
    set gg_trg_Tiles = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Tiles, function Trig_Tiles_Actions )
endfunction
 
Level 19
Joined
Dec 12, 2010
Messages
2,069
You have to return the correct type because otherwise the type cast exploit strikes back at you and returns a physical cast as opposed to a logical one. The result is one can create a separate set of I2R and R2I type casts which return values that are kept bit identical, rather than numerically similar.
nope, jass thread fall out instead of working with wrong number.
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
nope, jass thread fall out instead of working with wrong number.
Try explaining that to this nonsense...
JASS:
library ReinterpretCast 
     private function realToIndex takes real r returns integer
         loop
             return r
         endloop
         return 0
     endfunction

     private function cleanInt takes integer i returns integer
         return i
     endfunction

     private function indexToReal takes integer i returns real
         loop
             return i
         endloop
         return 0.0
     endfunction

     private function cleanReal takes real r returns real
         return r
     endfunction
     
     function ReinterpretI2R takes integer i returns real
         return cleanReal(indexToReal(i))
     endfunction

     function ReinterpretR2I takes real r returns integer
         return cleanInt(realToIndex(r))
     endfunction
endlibrary
 
Level 7
Joined
Nov 18, 2012
Messages
312
You have to return the correct type because otherwise the type cast exploit strikes back at you and returns a physical cast as opposed to a logical one. The result is one can create a separate set of I2R and R2I type casts which return values that are kept bit identical, rather than numerically similar.


Your loop makes little sense? Try this.
JASS:
function Trig_Tiles_Actions takes nothing returns nothing
//Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1

    set udg_CheckRect[1] = gg_rct_Area14
    set udg_CheckRect[2] = gg_rct_Area15
    set udg_CheckRect[3] = gg_rct_Area16
    set udg_CheckRect[4] = gg_rct_Area17

    loop
    exitwhen i>4
        call SetTerrainType(GetRectCenterX(udg_CheckRect[i]),GetRectCenterY(udg_CheckRect[i]), 'Ldrt', -1, 8, 1 )
        set udg_CheckRect[i] = null
        set i = i+1
    endloop
endfunction

//===========================================================================
function InitTrig_Tiles takes nothing returns nothing
    set gg_trg_Tiles = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Tiles, function Trig_Tiles_Actions )
endfunction
it still only sets the terrain of the first rct
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
can region array be used in jass, or is it vjass?
i have never used it in jass before, i need to clarify this because I don't know how to use vjass
You can have a region array in regular JASS, but it can't be a global region array-- you're limited to local region variables. You don't even have to USE JNGP for anything if you just install it for its ability to declare globals freely, which I think would massively benefit you.
JASS:
//Without JNGP
function a takes nothing returns nothing
    local region array Rarray
    set Rarray[3] = RegionAddRect(...)
endfunction

//With JNGP
globals
    region array RarrayGlobal
endglobals
function b takes nothing returns nothing
    set RarrayGlobal[3] = RegionAddRect(...)
endfunction

Most likely it is a syntax error, I don't know how to run syntax check on JNGP, and I didn't run syntax check on war3map.j either.
With JNGP installed, saving the map will run a syntax check and compile the code if it passes the check. Pressing the Test Map button will not compile the map properly so you must save before pressing that button.

I have used a lot of locations when I started with GUI, this is my first map so I just happened to learn how to convert code in jass yesterday.
Then you're off to a good start! Don't pull your hair out over locations, just avoid them in the future if you can. For ex: GUI is almost entirely dependent on locations but it still works fine, so imagine if you didn't have to think about using RemoveLocation() all the time? Nice, eh?

ok, did i make any mistake in returning reals?
Not that I can see.


I made a mistake and forgot something in this line of my example (I never checked to see if it's the correct portal that will teleport you for real!)
JASS:
function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)    //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1
    local rect CheckRect

    loop
        if i == 1 then
            set CheckRect = gg_rct_Region_009
        elseif i == 2 then
            set CheckRect = gg_rct_Region_010
        elseif i == 3 then
            set CheckRect = gg_rct_Region_011
        elseif i == 4 then
            set CheckRect = gg_rct_Region_012
        else
            set CheckRect = null //this is a safety call, probably unnecessary
        endif

        set rxMax = GetRectMaxX(CheckRect)
        set rxMin = GetRectMinX(CheckRect)
        set ryMax = GetRectMaxY(CheckRect)
        set ryMin = GetRectMinY(CheckRect)


        @HERE@
        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin)
            //If ux and uy are within its boundary then the unit must be inside
            if udg_AccessofPortal[i] then
                //If it's the right portal, move the unit to the safe region
                call SetUnitX(GetRectCenterX(gg_rct_Region_13))
                call SetUnitY(GetRectCenterY(gg_rct_Region_13))
            else
                //If it's the wrong portal, move the unit to HELL
                call SetUnitX(GetRectCenterX(gg_rct_Region_HELL_OMG))
                call SetUnitY(GetRectCenterY(gg_rct_Region_HELL_OMG))
            endif
            exitwhen true //leave the loop early, no need to do more
        endif

        set i = i+1
        exitwhen i > TOTAL_PORTALS // Probably 4, again
    endloop

    set u = null
    set CheckRect = null
endfunction
______________________________
Now, why is yours not working? I'm not sure, but again your trigger has no events (unless you're manually calling Trig_Tiles_Actions() it should never run. My best guess is that some of your arguments to SetTerrainType(... , 'Ldrt', @-1@, 8, 1 ) are invalid. Try playing with the numbers at the end, and I'm pretty sure they can't be less than 0 or thread crash.

Aside from that CheckRect should just be a normal rect, not a rect array. In fact it doesn't HAVE to be global either (in my example it's local) unless you want to store all the possible rects you could be teleported to. While that might help you in the long run if you have lots of these different portal/groups of portals, I think it'll just be easier to keep doing a pseudo-switch/case like I wrote. You could even write a function for it to make it more clear why you only need a local CheckRect:
JASS:
function GetRectToCheck_1 takes integer i returns rect
    local rect r = null

    if i == 1 then
        set CheckRect = gg_rct_Region_009
    elseif i == 2 then
        set CheckRect = gg_rct_Region_010
    elseif i == 3 then
        set CheckRect = gg_rct_Region_011
    elseif i == 4 then
        set CheckRect = gg_rct_Region_012
    endif
    //else no longer needed, safety call taken care of at r declaration

    return r
endfunction
//...
    loop
        set CheckRect = GetRectToCheck_1(i)

        set rxMax = GetRectMaxX(CheckRect)
        set rxMin = GetRectMinX(CheckRect)
        set ryMax = GetRectMaxY(CheckRect)
        set ryMin = GetRectMinY(CheckRect)
//...
 
Level 7
Joined
Nov 18, 2012
Messages
312
You can have a region array in regular JASS, but it can't be a global region array-- you're limited to local region variables. You don't even have to USE JNGP for anything if you just install it for its ability to declare globals freely, which I think would massively benefit you.
I assume JNGP allows me to declare a global region array.. I'll try

With JNGP installed, saving the map will run a syntax check and compile the code if it passes the check. Pressing the Test Map button will not compile the map properly so you must save before pressing that button.
Kinda figured that out after failing some syntax check due to autosave lol :p

So If I were to use locations, do I have to use
JASS:
RemoveLocation()
to avoid mass leak?

Thanks for the awesome number of inputs! I have set CheckRect to array because I want all my map's portal to have randomized teleports, which is more like dungeon. (I hope it work this way)

Setting the Terrain was actually converted from GUI trigger so I think it works that way, since it has changed the first terrain to that tiles
Dr Super Good said:
It should set 1 tile at the centre of every of the 4 rects, as you specified.
I thought it should too, but it didn't. I'll try again.

PS: sorry for late reply, I'm having fun in internship now so I could do more on mapmaking probably on weekends. Cheers!
 
Level 39
Joined
Feb 27, 2007
Messages
4,994
Yeah, you can have everything except a code array. You're correct about the terrain: -1 gives random texture variation, so that can't be the issue. instead of changing the terrain type I would do something like create a footman in the middle of each checked rect because that's a lot more visible and will show you every time it runs rather than only the first time (because after that the terrain is already changed so you won't see change!). Pick your poison, though-- you could use special effects too as easy indicators.

RemoveLocation() is necessary for any location you don't want to keep around and/or use again. Generally speaking: yes, every time a 'new' location is 'gotten' (through GetSpellTargetPoint(), GetUnitLoc(), etc.) it will need to be removed by a subsequent RemoveLocation() call.

Understand that you are removing the location data itself from the game (so it doesn't eat up used memory for no reason, which is why they're considered 'leaks'), not just deleting a variable. See below.
JASS:
//Leak free!
set Loc = GetSpellTargetLoc()
call RemoveLocation(Loc)
set Loc = GetUnitLoc(GetTriggerUnit())
call RemoveLocation(Loc)
set Loc = null //also important to do this for non-basic types in JASS, unless I'm archaic in my methods


//Leaks 1 location!
set Loc = GetSpellTargetLoc()
set Loc = GetUnitLoc(GetTriggerUnit())
call RemoveLocation(Loc)
set Loc = null

I see no reason you code would just stop executing, so perhaps there's a new error in the updated code. Can you post all of your portal-related triggers (if there are indeed more than one, that's unclear to me atm) or upload your map? In general you can use the JNGP's JassHelper syntax checker when you save, but if isn't showing you what the error is you might have to select "JassHelper >> Show previous errors" from the toolbar after it tells you there's one.

To problem-solve myself without understanding or knowing about a particular syntax error, I just start commenting things out and add in BJDebugMsg("part __") calls everywhere until I figure out exactly which lines will compile/are running properly and which are not. you can make multi-line comments in vJASS to quickly comment out stuff
JASS:
call Whatever()
//the line below 'starts' a multiline comment

/*
set i = 0
loop
    set i = i+1
    exitwhen MyFunc(i)
endloop
*/

//the line above ends a multiline comment

call WhateverElse()
 
Level 7
Joined
Nov 18, 2012
Messages
312
JASS:
function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function SetPortalNumber takes nothing returns nothing
    local integer i = 1

    loop
        set udg_AccessofPortal[i] = false
        set i = i+1
        exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
    endloop

    set udg_AccessofPortal[RandomPortal()] = true
endfunction

function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1
    local rect CheckRect

    loop
        if i == 1 then
            set CheckRect = gg_rct_Region_009
        elseif i == 2 then
            set CheckRect = gg_rct_Region_010
        elseif i == 3 then
            set CheckRect = gg_rct_Region_011
        elseif i == 4 then
            set CheckRect = gg_rct_Region_012
        else
            set CheckRect = null //this is a safety call, probably unnecessary
        endif

        set rxMax = GetRectMaxX(CheckRect)
        set rxMin = GetRectMinX(CheckRect)
        set ryMax = GetRectMaxY(CheckRect)
        set ryMin = GetRectMinY(CheckRect)

        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then 
            //If ux and uy are within its boundary then the unit must be inside
            if udg_AccessofPortal[i] then
                //If it's the right portal, move the unit to the safe region
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
            else
                //If it's the wrong portal, move the unit to HELL
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_011))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_011))
            endif
            exitwhen true //leave the loop early, no need to do more
        endif

        set i = i+1
        exitwhen i > 4 // Probably 4, again
    endloop

    set u = null
    set CheckRect=null
endfunction

//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
    call SetPortalNumber()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
this is giving me fatal error somehow :<
 
Level 7
Joined
Nov 18, 2012
Messages
312
At initialization? Or at some other time?

If at some other time you will need to show the events you bind to the trigger. As a rough guess it might be cyclic recurrence due to moving the unit.
Okay test map work at initialization, but i don't get teleported in any of the portals
 
Last edited:
Level 7
Joined
Nov 18, 2012
Messages
312
@Pyrogasm @Dr Super Good
Hello, I have edited slightly, and I feel the code should have no problem.
However, the rects won't teleport my units into the next rect

JASS:
function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function SetPortalNumber takes nothing returns nothing
    local integer i = 1

    loop
        set udg_AccessofPortal[i] = false
        set i = i+1
        exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
    endloop

    set udg_AccessofPortal[RandomPortal()] = true             // udg_AccessofPortal[x] will be true
endfunction

function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1
    local integer ii = 0
    local rect CheckRect                               //local rect checks the rect at portal entrance

    loop
        if i == 1 then
            set CheckRect = gg_rct_Region_009
        elseif i == 2 then
            set CheckRect = gg_rct_Region_010
        elseif i == 3 then
            set CheckRect = gg_rct_Region_011
        elseif i == 4 then
            set CheckRect = gg_rct_Region_012
        else
            set CheckRect = null //this is a safety call, probably unnecessary
        endif

        set rxMax = GetRectMaxX(CheckRect)
        set rxMin = GetRectMinX(CheckRect)
        set ryMax = GetRectMaxY(CheckRect)
        set ryMin = GetRectMinY(CheckRect)

        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then 
            //If ux and uy are within its boundary then the unit must be inside            
            if udg_AccessofPortal[i]==true then
                //if portal is right
               
                set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)               
                call SetUnitX(u,GetRectCenterX(gg_rct_TrainingGround1))
                call SetUnitY(u,GetRectCenterY(gg_rct_TrainingGround1))
                elseif udg_AccessofPortal[i]==true and ii>2 then 
                //if >2 correct count, then set location to Area 2
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_018))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_018))
            else
                //If it's the wrong portal, move the unit to HELL
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
            endif
            exitwhen udg_AccessofPortal[i]==true // leave the loop early, no need to do more
        endif

        set i = i+1
        exitwhen i > 4 // Probably 4, again
    endloop

    set u = null
    set CheckRect=null
endfunction

//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
    call SetPortalNumber()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction

I think my rects are small and the unit cannot be completely bound by the rect, so it won't teleport.
Can that be the reason?
What can I do to make it so that if the unit is touching any part of the rect and will teleport into the next rect?
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
However, the rects won't teleport my units into the next rect
There are no events attached to the trigger?
I think my rects are small and the unit cannot be completely bound by the rect, so it won't teleport.
Can that be the reason?
No it cannot be the reason.

What can I do to make it so that if the unit is touching any part of the rect and will teleport into the next rect?
Maybe change to using regions instead? Regions allow you to detect unit entry to them with a trigger event.
 
Level 7
Joined
Nov 18, 2012
Messages
312
@Dr Super Good
JASS:
globals
region array udg_SaveRegion
endglobals
function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function SetPortalNumber takes nothing returns nothing
    local integer i = 1

    loop
        set udg_AccessofPortal[i] = false
        set i = i+1
        exitwhen i > 4 //I'm guessing this is 4 for your map? Confused by you using 5 since there are only 4 rects you check in.
    endloop

    set udg_AccessofPortal[RandomPortal()] = true             // udg_AccessofPortal[x] will be true
endfunction

function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 5
    local integer ii = 0
                   //local rect checks the rect at portal entrance
    loop
        if i == 5 then
            set udg_CheckRect[i] = gg_rct_Region_009
        elseif i == 6 then
            set udg_CheckRect[i] = gg_rct_Region_010
        elseif i == 7 then
            set udg_CheckRect[i] = gg_rct_Region_011
        elseif i == 8 then
            set udg_CheckRect[i] = gg_rct_Region_012
        else        
        endif
        call RegionAddRect(udg_SaveRegion[1],udg_CheckRect[i])
        set rxMax = GetRectMaxX(udg_CheckRect[i])
        set rxMin = GetRectMinX(udg_CheckRect[i])
        set ryMax = GetRectMaxY(udg_CheckRect[i])
        set ryMin = GetRectMinY(udg_CheckRect[i])

        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then 
            //If ux and uy are within its boundary then the unit must be inside            
            if udg_AccessofPortal[i]==true then
                //if portal is right
               
                set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)               
                call SetUnitX(u,GetRectCenterX(gg_rct_TrainingGround1))
                call SetUnitY(u,GetRectCenterY(gg_rct_TrainingGround1))
                elseif udg_AccessofPortal[i]==true and ii>2 then 
                //if >2 correct count, then set location to Area 2
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_018))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_018))
            else
                //If it's the wrong portal, move the unit to HELL
                call SetUnitX(u,GetRectCenterX(gg_rct_Region_013))
                call SetUnitY(u,GetRectCenterY(gg_rct_Region_013))
           endif
            exitwhen udg_AccessofPortal[i]==true // leave the loop early, no need to do more
        endif

        set i = i+1
        exitwhen i > 4 // Probably 4, again
    endloop

    set u = null
endfunction
function funcfunc takes nothing returns boolean
return true//return is unit a hero
endfunction
//===========================================================================
function InitTrig_RandomGen1 takes nothing returns nothing
    call SetPortalNumber()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[1],Condition(function funcfunc))
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Level 7
Joined
Nov 18, 2012
Messages
312
I am experiencing problem with the unit move to the center of the whole map area when it is suppose to go somewhere else.
I realize if i set this trigger to activate on initialization, it will do the same thing
JASS:
function Trig_Trap_Enter_TrainingGround1_Actions takes nothing returns nothing
local rect r = gg_rct_TrainingGround1
local real mx = GetRectMinX(r)
local real Mx = GetRectMaxX(r)
local real my = GetRectMinY(r)
local real My = GetRectMaxY(r)
    call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(r) )
//    call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My)
    call RemoveRect(r)
endfunction

//===========================================================================
function InitTrig_Trap_Enter_TrainingGround1 takes nothing returns nothing
    set gg_trg_Trap_Enter_TrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Trap_Enter_TrainingGround1, gg_rct_TrapToMap )
    call TriggerAddAction( gg_trg_Trap_Enter_TrainingGround1, function Trig_Trap_Enter_TrainingGround1_Actions )
endfunction
why is that so


okay and i found the problem, it happens when I change this
JASS:
function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
    call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(gg_rct_TrainingGround1) )
 //   call SetCameraBoundsToRectForPlayerBJ( Player(0), gg_rct_TrainingGround1 )
    call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(gg_rct_TrainingGround1, Player(0))), 0, 0, false )
    call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
endfunction

/////////////////////////////////////////INTO THIS
function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
local rect r = gg_rct_TrainingGround1
local real mx = GetRectMinX(r)
local real Mx = GetRectMaxX(r)
local real my = GetRectMinY(r)
local real My = GetRectMaxY(r)
    call SetUnitPositionLoc( GetTriggerUnit(), GetRectCenter(r) )
//call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
    call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
    call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
    call RemoveRect(r)
endfunction

//===========================================================================
function InitTrig_EnterTrainingGround1 takes nothing returns nothing
    set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
    call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
endfunction
okay the GetRectCenter is not defined
Okay I just solved this 2nd part
JASS:
function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
local rect r = gg_rct_TrainingGround1
local real mx = GetRectMinX(r)
local real Mx = GetRectMaxX(r)
local real my = GetRectMinY(r)
local real My = GetRectMaxY(r)
local unit u = GetTriggerUnit()
//call SetUnitPositionLoc(u , GetRectCenter(r) )
//change to
//
//
call SetUnitPosition(u,GetRectCenterX(r),GetRectCenterY(r))
///////////////////////////////////////////////////////////////


//call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
    call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
    call StartTimerBJ( udg_DungeonTimer, false, 600.00 )

set u = null
endfunction

//===========================================================================
function InitTrig_EnterTrainingGround1 takes nothing returns nothing
    set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
    call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
endfunction

I also realized removing the rect would cause it to go to middle of the map the 2nd time entering
okay i solved that as well, just set it below locals, so it will be set again to a value when re-entering
JASS:
function Trig_EnterTrainingGround1_Actions takes nothing returns nothing
local rect r 
local real mx
local real Mx 
local real my 
local real My 
local unit u = GetTriggerUnit()
set r= gg_rct_TrainingGround1
set mx = GetRectMinX(r)
set Mx = GetRectMaxX(r)
set my = GetRectMinY(r)
set My = GetRectMaxY(r) 
//call SetUnitPositionLoc(u , GetRectCenter(r) )
//change to
//
//
call SetUnitPosition(u,GetRectCenterX(r),GetRectCenterY(r))
///////////////////////////////////////////////////////////////


//call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My) //problematic
    call SetCameraTargetControllerNoZForPlayer( Player(0), GroupPickRandomUnit(GetUnitsInRectOfPlayer(r, Player(0))), 0, 0, false )
    call StartTimerBJ( udg_DungeonTimer, false, 600.00 )
//    call RemoveRect(r)
//cannot remove rect or the 2nd time entering will be send to middle
set u = null
endfunction

//===========================================================================
function InitTrig_EnterTrainingGround1 takes nothing returns nothing
    set gg_trg_EnterTrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_EnterTrainingGround1, gg_rct_TG1_Portal )
    call TriggerAddAction( gg_trg_EnterTrainingGround1, function Trig_EnterTrainingGround1_Actions )
endfunction
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
I am experiencing problem with the unit move to the center of the whole map area when it is suppose to go somewhere else.
It is because you are moving it to the centre of a destroyed rect. The variable gg_rct_TrainingGround1 is a constant, so destroying its rect object means that the rect is gone for good and the constant has no meaning anymore.

You also leak a location since you create a location object using GetRectCenter(r) which you never remove.

Try...
JASS:
function Trig_Trap_Enter_TrainingGround1_Actions takes nothing returns nothing
    local rect r = gg_rct_TrainingGround1
    local real mx = GetRectMinX(r)
    local real Mx = GetRectMaxX(r)
    local real my = GetRectMinY(r)
    local real My = GetRectMaxY(r)
    call SetUnitPosition(GetTriggerUnit(), GetRectCenterX(r), GetRectCenterX(r))
    call SetCameraBounds(mx, my, Mx, my, Mx, My, mx, My)
    set r = null
endfunction

//===========================================================================
function InitTrig_Trap_Enter_TrainingGround1 takes nothing returns nothing
    set gg_trg_Trap_Enter_TrainingGround1 = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_Trap_Enter_TrainingGround1, gg_rct_TrapToMap )
    call TriggerAddAction( gg_trg_Trap_Enter_TrainingGround1, function Trig_Trap_Enter_TrainingGround1_Actions )
endfunction
 
Level 7
Joined
Nov 18, 2012
Messages
312
I don't know why, but it always sets the gg_rct_TG1Rdm3 to the right portal, and never changes.
How to make it random every time when ii=ii+1?
JASS:
globals
region array udg_SaveRegion
boolean array Portal
rect array CheckRect
integer ii=0
boolean bb=false
endglobals
function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function SetPortalNumber takes nothing returns nothing
    local integer i = 1


    loop
  
    exitwhen i > 4
  
    //exit when portal > total quantity
        set Portal[i] = false
        set i = i+1
//when it ends i=5      
    endloop
    
set Portal[RandomPortal()] = true
    // Portal[x] will be true
endfunction
function InitRegions takes nothing returns nothing
set udg_SaveRegion[1]=CreateRegion()
set udg_SaveRegion[2]=CreateRegion()
set udg_SaveRegion[3]=CreateRegion()
set udg_SaveRegion[4]=CreateRegion()
endfunction
function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local real ux = GetUnitX(u)     //Always ALWAYS avoid locations wherever you can-- they are the DEVIL in wc3 (memory leaks, slow, not useful, etc.)
    local real uy = GetUnitY(u)
    local real rxMax
    local real rxMin
    local real ryMax
    local real ryMin
    local integer i = 1
                   //local rect checks the rect at portal entrance
loop
exitwhen i > 4
        if i == 1 then
            set CheckRect[i] = gg_rct_TG1Rdm1
        elseif i == 2 then
            set CheckRect[i] = gg_rct_TG1Rdm2          
        elseif i == 3 then
            set CheckRect[i] = gg_rct_TG1Rdm3          
        elseif i == 4 then
            set CheckRect[i] = gg_rct_TG1Rdm4          
        endif
        call RegionAddRect(udg_SaveRegion[i],CheckRect[i])
        set rxMax = GetRectMaxX(CheckRect[i])
        set rxMin = GetRectMinX(CheckRect[i])
        set ryMax = GetRectMaxY(CheckRect[i])
        set ryMin = GetRectMinY(CheckRect[i])

        if (rxMax >= ux and ux >= rxMin) and (ryMax >= uy and uy >= ryMin) then
            //If ux and uy are within its boundary then the unit must be inside           
if Portal[i]==false then
//If it's the wrong portal, move the unit to HELL
call SetUnitX(u,GetRectCenterX(gg_rct_TG1TrapPoint))
call SetUnitY(u,GetRectCenterY(gg_rct_TG1TrapPoint))          
set bb=true
elseif ii==2 then
call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(ii+1)+" times and moved to next district")
//if >2 correct count, then set location to Area 2
call SetUnitX(u,GetRectCenterX(gg_rct_District2Point))
call SetUnitY(u,GetRectCenterY(gg_rct_District2Point))
          else
              
//if Portal[i]==true then
//if portal is right
              
                set ii=ii+1 //If it's the right portal, set correct count to +1, move the unit to the center of TG1 (safe region)              
call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(ii)+" times")
call SetUnitX(u,GetRectCenterX(gg_rct_District1))
call SetUnitY(u,GetRectCenterY(gg_rct_District1))
          endif
            exitwhen Portal[i]==true // leave the loop early, no need to do more
        endif

        set i = i+1
    endloop
//call ExecuteFunc("InitTrig_RandomGen1") //causes leak, but helps in randomizing
//call RegionAddRect(udg_SaveRegion[9],gg_rct_TrainingGround1)

set u = null

//call RegionClearRect(udg_SaveRegion[1],CheckRect[1])
//call RegionClearRect(udg_SaveRegion[2],CheckRect[2])
//call RegionClearRect(udg_SaveRegion[3],CheckRect[3])
//call RegionClearRect(udg_SaveRegion[4],CheckRect[4])
set CheckRect[1]=null
set CheckRect[2]=null
set CheckRect[3]=null
set CheckRect[4]=null
set udg_SaveRegion[1]=null
set udg_SaveRegion[2]=null
set udg_SaveRegion[3]=null
set udg_SaveRegion[4]=null
endfunction
function funcfunc9 takes nothing returns boolean
return true
endfunction

//should return is unit a hero but since it's not even working
//should return is unit in region

//===========================================================================

function InitTrig_RandomGen1 takes nothing returns nothing
    call SetPortalNumber()
    call InitRegions()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[1],Condition(function funcfunc9))
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[2],Condition(function funcfunc9))
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[3],Condition(function funcfunc9))
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1,udg_SaveRegion[4],Condition(function funcfunc9))
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
  
endfunction
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Maybe the following will work? It might have syntax errors as I wrote it without a checker.
JASS:
globals
    region PortalSafeRegion
    region PortalAllRegion
    integer PortalSafePortal
    rect array CheckRect
    integer PortalCorrectCount = 0
endglobals

function RandomPortal takes nothing returns integer
    return GetRandomInt(1,4)
endfunction

function InitPortals takes nothing returns nothing
    local integer i = 1

    set CheckRect[1] = gg_rct_TG1Rdm1
    set CheckRect[2] = gg_rct_TG1Rdm2
    set CheckRect[3] = gg_rct_TG1Rdm3
    set CheckRect[4] = gg_rct_TG1Rdm4

    set PortalSafeRegion = CreateRegion()
    set PortalAllRegion = CreateRegion()

    // add all rects to region for entry event
    loop
        exitwhen i > 4
        call RegionAddRect(PortalAllRegion, CheckRect[i])
        set i = i + 1
    endloop

    // initialize safe region
    set PortalSafePortal = RandomPortal()
    call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
endfunction

function Trig_RandomGen_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()

    if IsUnitInRegion(PortalSafeRegion, u) then
        // correct portal
        set PortalCorrectCount = PortalCorrectCount + 1  
        if PortalCorrectCount < 3 then
            // move to safe area
            call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(PortalCorrectCount)+" times")
            call SetUnitX(u,GetRectCenterX(gg_rct_District1))
            call SetUnitY(u,GetRectCenterY(gg_rct_District1))
        else
            // move to next district
            call DisplayTimedTextToPlayer(Player(0),0,0,0,"You have Passed "+I2S(PortalCorrectCount)+" times and moved to next district")
            call SetUnitX(u,GetRectCenterX(gg_rct_District2Point))
            call SetUnitY(u,GetRectCenterY(gg_rct_District2Point))
        endif

        // setup new random portal
        call RegionClearRect(PortalSafeRegion, CheckRect[PortalSafePortal])
        set PortalSafePortal = RandomPortal()
        call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
    else
        // wrong portal, go to hell
        call SetUnitX(u,GetRectCenterX(gg_rct_TG1TrapPoint))
        call SetUnitY(u,GetRectCenterY(gg_rct_TG1TrapPoint))
    endif

    set u = null
endfunction

function funcfunc9 takes nothing returns boolean
    return true
endfunction

//should return is unit a hero but since it's not even working
//should return is unit in region

//===========================================================================

function InitTrig_RandomGen1 takes nothing returns nothing
    call InitPortals()
    set gg_trg_RandomGen1 = CreateTrigger(  )
    call TriggerRegisterEnterRegion(gg_trg_RandomGen1, PortalAllRegion, Condition(function funcfunc9))
    call TriggerAddAction( gg_trg_RandomGen1, function Trig_RandomGen_Actions )
endfunction
 
Level 7
Joined
Nov 18, 2012
Messages
312
okay in local area it also don't random
It does random the first portal. but not the 2nd or 3rd
The InitPortals() is only called once, so it doesn't random after the first time
and it haunts me every time I want the right portal to random after every entrance to a region

thanks you made me learn that you can just add the region without the array number behind it.
 
Last edited:

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
It does random the first portal. but not the 2nd or 3rd
But it should randomly select after every correct guess...
The InitPortals() is only called once, so it doesn't random after the first time
That is because it sets the initial state. Further randomization is done later.
JASS:
        // setup new random portal
        call RegionClearRect(PortalSafeRegion, CheckRect[PortalSafePortal])
        set PortalSafePortal = RandomPortal()
        call RegionAddRect(PortalSafeRegion, CheckRect[PortalSafePortal])
The above removes the random rect from the safe region, sets the portal to a new random portal and then adds that new portal rect to the safe region.
and it haunts me every time I want the right portal to random after every entrance to a region
After every entrance to a region? But earlier you said only after every correct guess... Which is it?
thanks you made me learn that you can just add the region without the array number behind it.
What was there to learn? Either a variable is an array or not. Does not matter the type, except code array which throws a syntax error for security reasons.
 
Level 7
Joined
Nov 18, 2012
Messages
312
I meant it randoms after every correct entrance.
I'm pretty sure it doesn't set new portal location because I tested it more than 5 times..
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
I'm pretty sure it doesn't set new portal location because I tested it more than 5 times..
I am pretty sure it does because I coded it to do so... Unless of course the natives used are acting in strange unpredictable ways in which case some debugging and changes will be needed. Specifically if RegionClearRect is not clearing properly (a bug with that native) it would not appear random, and as I never used the native before I cannot promise it works properly.

If that is really the case, you will need to provide a map demonstrating the problem for further debugging. This is to rule out other possible errors. The trigger can be extracted and placed into a blank test map if necessary but it must be setup for easy testing.
 
Level 7
Joined
Nov 18, 2012
Messages
312
i checked RandomPortal() it gives random integers accurately.
I think RegionClearRect is not functioning correctly, since the first entry is randomized every time. But the next entry to the same region will be the correct rect
 
Status
Not open for further replies.
Top