I have been really curious about how a proper JASS map (not just a system) should be coded, I understand that in the script there is a main function, and when you create a trigger, then convert it, it tells it to call it (in vJASS I believe you can edit any specific part of the script)
I have heard about 1000x times how GUI creates triggers inefficiently, but I have not seen any examples, here is how I did my map, but I would really like somebody to let me know if I'm doing something wrong (or right)
Btw, I don't feel like getting a NewGen upgrade, so all of my globals have the "udg_" tacked on, sorry
Heres the Init trigger (not the main, but is called by the main)
And then here is the script that contains the actions, conditions, and just functions used by the map
Ugh, the jass tags condensed it, I had a really stylistic system going that made it easy to find certain code (I'm kinda new to JASS, so I gotta constantly re-check names + order of parameters and what else)
I have heard about 1000x times how GUI creates triggers inefficiently, but I have not seen any examples, here is how I did my map, but I would really like somebody to let me know if I'm doing something wrong (or right)
Btw, I don't feel like getting a NewGen upgrade, so all of my globals have the "udg_" tacked on, sorry
Heres the Init trigger (not the main, but is called by the main)
JASS:
function Trig_GameStart_Actions takes nothing returns nothing
local integer i = -1
//Starting Game Settings
call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 2000, 0)
call FogEnable(false)
call FogMaskEnable(false)
set udg_SpawnTimer = CreateTimer()
call TimerStart(udg_SpawnTimer, 10.00, true, null)
set udg_EntireMap = GetWorldBounds()
set udg_SpawnRegions[0] = gg_rct_RedSpawn
set udg_SpawnRegions[1] = gg_rct_BlueSpawn
set udg_SpawnRegions[2] = gg_rct_TealSpawn
set udg_SpawnRegions[3] = gg_rct_PurpleSpawn
set udg_SpawnRegions[4] = gg_rct_YellowSpawn
set udg_SpawnRegions[5] = gg_rct_OrangeSpawn
set udg_SpawnRegions[6] = gg_rct_GreenSpawn
set udg_SpawnRegions[7] = gg_rct_PinkSpawn
set udg_SpawnRegions[8] = gg_rct_GraySpawn
set udg_SpawnRegions[9] = gg_rct_LightBlueSpawn
set udg_SpawnRegions[10] = gg_rct_DarkGreenSpawn
set udg_SpawnRegions[11] = gg_rct_BrownSpawn
call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(12) )
call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(13) )
call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(14) )
call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(15) )
//Create Triggers
set udg_trgSpawnTimer = CreateTrigger()
set udg_trgChangeD = CreateTrigger()
set udg_trgChangeRo = CreateTrigger()
set udg_trgBuildatBase = CreateTrigger()
set udg_trgSetBase = CreateTrigger()
set udg_trgKillATrollTent = CreateTrigger()
//Add Trigger Actions
call TriggerAddAction( udg_trgSpawnTimer, function SpawnTimer )
call TriggerAddAction( udg_trgChangeD, function ChangeDistance )
call TriggerAddAction( udg_trgChangeRo, function ChangeRotation )
call TriggerAddAction( udg_trgBuildatBase, function BuildatBase )
call TriggerAddAction( udg_trgSetBase, function SetBase )
call TriggerAddAction( udg_trgKillATrollTent, function KillTrollTents )
//Add Trigger Events
call TriggerRegisterTimerExpireEvent(udg_trgSpawnTimer, udg_SpawnTimer)
//Add Trigger Conditions
call TriggerAddCondition(udg_trgBuildatBase,Condition( function IsUnitABuilder))
call TriggerAddCondition(udg_trgSetBase,Condition( function CheckAncient))
call TriggerAddCondition(udg_trgKillATrollTent,Condition( function CheckTrollTent))
//Loops
loop
set i=i+1
exitwhen i==12
//Add Trigger Events (Looped)
call TriggerRegisterPlayerChatEvent(udg_trgChangeD,Player(i),"-d ",false)
call TriggerRegisterPlayerChatEvent(udg_trgChangeRo,Player(i),"-Ro ",false)
call TriggerRegisterLeaveRectSimple(udg_trgBuildatBase, udg_SpawnRegions[i])
call TriggerRegisterPlayerUnitEvent(udg_trgSetBase, Player(i),EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
call TriggerRegisterPlayerUnitEvent(udg_trgKillATrollTent, Player(i),EVENT_PLAYER_UNIT_DEATH, null)
//Setup (Looped)
call SetPlayerFlagBJ( PLAYER_STATE_GIVES_BOUNTY, true, Player(i) )
//Create Starters
if i < 3 then
call CreateUnit(Player(i),'e001', GetRectCenterX(udg_SpawnRegions[i]), GetRectCenterY(udg_SpawnRegions[i]), bj_RADTODEG * AngleBetweenCoordsRad(GetRectCenterX(udg_SpawnRegions[i]),GetRectCenterY(udg_SpawnRegions[i]),GetRectCenterX(udg_EntireMap),GetRectCenterY(udg_EntireMap)))
elseif i > 2 then
call CreateUnit(Player(i),'e002', GetRectCenterX(udg_SpawnRegions[i]), GetRectCenterY(udg_SpawnRegions[i]), bj_RADTODEG * AngleBetweenCoordsRad(GetRectCenterX(udg_SpawnRegions[i]),GetRectCenterY(udg_SpawnRegions[i]),GetRectCenterX(udg_EntireMap),GetRectCenterY(udg_EntireMap)))
elseif i > 5 then
call CreateUnit(Player(i),'e003', GetRectCenterX(udg_SpawnRegions[i]), GetRectCenterY(udg_SpawnRegions[i]), bj_RADTODEG * AngleBetweenCoordsRad(GetRectCenterX(udg_SpawnRegions[i]),GetRectCenterY(udg_SpawnRegions[i]),GetRectCenterX(udg_EntireMap),GetRectCenterY(udg_EntireMap)))
elseif i > 8 then
call CreateUnit(Player(i),'e000', GetRectCenterX(udg_SpawnRegions[i]), GetRectCenterY(udg_SpawnRegions[i]), bj_RADTODEG * AngleBetweenCoordsRad(GetRectCenterX(udg_SpawnRegions[i]),GetRectCenterY(udg_SpawnRegions[i]),GetRectCenterX(udg_EntireMap),GetRectCenterY(udg_EntireMap)))
endif
endloop
endfunction
//===========================================================================
function InitTrig_GameStart takes nothing returns nothing
set gg_trg_GameStart = CreateTrigger()
call TriggerAddAction( gg_trg_GameStart, function Trig_GameStart_Actions )
endfunction
And then here is the script that contains the actions, conditions, and just functions used by the map
JASS:
//[Useful Functions]=======================================================
function cGroupAddGroupEnum takes nothing returns nothing
call GroupAddUnit(udg_DestGroup, GetEnumUnit())
endfunction
function cGroupAddGroup takes group sourceGroup, group destGroup returns nothing
call ForGroup(sourceGroup, function cGroupAddGroupEnum)
set udg_DestGroup = destGroup
endfunction
function GetPolarCoordX takes real x, real dist, real angle returns real
set x = x + dist * Cos(angle * bj_DEGTORAD)
return x
endfunction
function GetPolarCoordY takes real y, real dist, real angle returns real
set y = y + dist * Sin(angle * bj_DEGTORAD)
return y
endfunction
function AngleBetweenCoordsRad takes real x1, real y1, real x2, real y2 returns real
return Atan2(y2 - y1, x2 - x1)
endfunction
function DistBetweenCoords takes real x1, real y1, real x2, real y2 returns real
return SquareRoot((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))
endfunction
//[Boolean Checks]=========================================================
function IsUnitABuilder takes nothing returns boolean
if GetUnitTypeId(GetTriggerUnit()) == 'e000' then
return true
endif
if GetUnitTypeId(GetTriggerUnit()) == 'e001' then
return true
endif
if GetUnitTypeId(GetTriggerUnit()) == 'e002' then
return true
endif
if GetUnitTypeId(GetTriggerUnit()) == 'e003' then
return true
endif
return false
endfunction
function CheckAncient takes nothing returns boolean
if IsUnitType(GetConstructingStructure(),UNIT_TYPE_ANCIENT) then
return true
endif
return false
endfunction
function CheckTrollTent takes nothing returns boolean
if GetUnitTypeId(GetDyingUnit()) == 'o001' and FirstOfGroup(udg_Tents) != null then
return true
endif
return false
endfunction
//[Trigger Actions]========================================================
function SpawnTimer takes nothing returns nothing
local integer i = -1
local real X
local real Y
local real X2 = GetRectCenterX(udg_EntireMap)
local real Y2 = GetRectCenterY(udg_EntireMap)
loop
set i=i+1
exitwhen i == 12
set X = GetUnitX(udg_Bases[i])
set Y = GetUnitY(udg_Bases[i])
if udg_Bases[i] != null and GetUnitState(udg_Bases[i],UNIT_STATE_LIFE) > 0.0 then
call CreateUnit( Player(i), 'hfoo', X,Y,bj_RADTODEG * AngleBetweenCoordsRad(X,Y,X2,Y2))
endif
endloop
endfunction
function ChangeDistance takes nothing returns nothing
local real distance = S2R(SubString(GetEventPlayerChatString(), 3, StringLength(GetEventPlayerChatString()) ))
call SetCameraFieldForPlayer(GetTriggerPlayer(),CAMERA_FIELD_TARGET_DISTANCE, distance, 0)
endfunction
function ChangeRotation takes nothing returns nothing
local real degrees = S2R(SubString(GetEventPlayerChatString(), 4, StringLength(GetEventPlayerChatString()) ))
call SetCameraFieldForPlayer(GetTriggerPlayer(),CAMERA_FIELD_ROTATION, degrees, 0)
endfunction
function BuildatBase takes nothing returns nothing
local real X = GetRectCenterX(udg_SpawnRegions[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))])
local real Y = GetRectCenterY(udg_SpawnRegions[GetPlayerId(GetOwningPlayer(GetTriggerUnit()))])
call SetUnitPosition(GetTriggerUnit(),X,Y)
endfunction
function SetBase takes nothing returns nothing
local unit u = GetConstructingStructure()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local integer unitid = GetUnitTypeId(u)
local player owner = GetOwningPlayer(u)
local integer i = 0
call KillUnit(u)
set udg_Bases[GetPlayerId(owner)] = CreateUnit(owner, unitid, x,y,270)
if GetUnitTypeId(u) == 'n002' or GetUnitTypeId(u) == 'n002' then
call UnitAddAbility(udg_Bases[GetPlayerId(owner)],'Aro1')
call IssuePointOrder( udg_Bases[GetPlayerId(owner)], "root",GetUnitX(udg_Bases[GetPlayerId(owner)]),GetUnitY(udg_Bases[GetPlayerId(owner)]))
call UnitRemoveAbility(udg_Bases[GetPlayerId(owner)],'Aro1')
endif
if GetUnitTypeId(u) == 'o001' then
loop
exitwhen i==4
set i = i+1
call GroupAddUnit(udg_Tents,CreateUnit(owner, 'n001', GetPolarCoordX(x,300.0, i*90.0 + 45.0), GetPolarCoordY(y,300.0, i*90.0 + 45.0), 270.0))
endloop
endif
set u = null
set owner = null
endfunction
function TentDistance takes nothing returns nothing
if (GetUnitX(GetEnumUnit()) - udg_BaseX) * (GetUnitX(GetEnumUnit()) - udg_BaseX) + (GetUnitY(GetEnumUnit()) - udg_BaseY) * (GetUnitY(GetEnumUnit()) - udg_BaseY) <= 160000 then
call KillUnit(GetEnumUnit())
call GroupRemoveUnit(udg_Tents,GetEnumUnit())
endif
endfunction
function KillTrollTents takes nothing returns nothing
local unit u = GetDyingUnit()
set udg_BaseX = GetUnitX(u)
set udg_BaseY = GetUnitY(u)
call ForGroup(udg_Tents, function TentDistance)
set u = null
endfunction
Ugh, the jass tags condensed it, I had a really stylistic system going that made it easy to find certain code (I'm kinda new to JASS, so I gotta constantly re-check names + order of parameters and what else)