- Joined
- Jun 15, 2016
- Messages
- 472
In order to do map stuff I'm trying to create a creep summoning system which works like this:
Each time a periodic timer ends, a group of creeps spawn in a certain location. The creeps are supposed to patrol though some locations of the map, and to avoid cluttering I limited them to 3 patrol groups. The system checks to see if the patrol groups are empty, and if no group is empty it will create smaller groups that will attack the player directly. If there is a vacant patrol group the newly created units will be assigned to it and will be ordered to their starting location.
The problem is all units accumulate to one group instead of being assigned to a different group.
I know, the trigger isn't optimized at all and I use BJ functions and I should be burned at the stake as a witch and all. You can say that I know very little about JASS so all criticism and advice is welcome.
Each time a periodic timer ends, a group of creeps spawn in a certain location. The creeps are supposed to patrol though some locations of the map, and to avoid cluttering I limited them to 3 patrol groups. The system checks to see if the patrol groups are empty, and if no group is empty it will create smaller groups that will attack the player directly. If there is a vacant patrol group the newly created units will be assigned to it and will be ordered to their starting location.
The problem is all units accumulate to one group instead of being assigned to a different group.
JASS:
function Attack_Squad takes rect r, integer i returns group //Attack Squad creation function
local location tempPoint = GetRectCenter(r)
if i <= 2 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
elseif i == 3 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n002', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n002', tempPoint, 90.0)
elseif i == 4 then
call CreateUnitAtLoc(Player(4), 'n003', tempPoint, 90.0)
else
call BJDebugMsg("Faulty switch result: attack group selector")
endif
//Cleanup
call RemoveLocation(tempPoint)
set tempPoint = null
return GetUnitsInRectOfPlayer(r, Player(4))
endfunction
function Attack_Pattern takes nothing returns nothing //Attack Squad order function
call IssueTargetOrderBJ( GetEnumUnit(), "attack", gg_unit_H002_0107 )
endfunction
function Patrol_Squad takes rect r, integer i returns group //Patrol Squad creation
local location tempPoint = GetRectCenter(r)
if i == 1 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
elseif i == 2 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n002', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n002', tempPoint, 90.0)
elseif i == 3 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n003', tempPoint, 90.0)
elseif i == 4 then
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'uske', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n002', tempPoint, 90.0)
call CreateUnitAtLoc(Player(4), 'n004', tempPoint, 90.0)
else
call BJDebugMsg("Faulty switch result: patrol group selector")
endif
//Cleanup
call RemoveLocation(tempPoint)
set tempPoint = null
return GetUnitsInRectOfPlayer(r, Player(4))
endfunction
function Patrol_Check takes nothing returns integer
//This function checks which of the patrol groups are empty, with accordence to their priority.
//If tests are correct, skeletons are removed from groups shortly after their death.
if (FirstOfGroup(udg_patrolRoad) == null) then
return 1
elseif (FirstOfGroup(udg_patrolForest1) == null) then
return 2
elseif (FirstOfGroup(udg_patrolForest2) == null) then
return 3
else
return 4
endif
endfunction
function Spawn_System takes nothing returns nothing
//Local variable decleration.
local integer selector
local rect downpourRect
local group tempGroup
//Generates the downpour point from which the units will be spawned.
set selector = GetRandomInt(1,4)
//call BJDebugMsg("Downpour point " + I2S(selector)) //Debug Statement
if selector == 1 then
set downpourRect = gg_rct_DownpourPoint1
elseif selector == 2 then
set downpourRect = gg_rct_DownpourPoint2
elseif selector == 3 then
set downpourRect = gg_rct_DownpourPoint3
elseif selector == 4 then
set downpourRect = gg_rct_DownpourPoint4
else
call BJDebugMsg("Faulty switch result: location selector")
endif
set selector = GetRandomInt(1,4)
//call BJDebugMsg("Group number " + I2S(selector)) //Debug Statement
if (Patrol_Check() == 4) then
//If no patrol group is empty, the units will instead be sent to attack the captain.
//If sent to another unit they might kill it then be stuck there not furthering the gameplay mechanic.
set tempGroup = Attack_Squad(downpourRect,selector)
call ForGroupBJ(tempGroup, function Attack_Pattern)//Attack function
else
//Patrol groups: temp group is set to global variable and the group is not removed, for future patrol orders.
//The unit group will be assigned to the proper global group then sent to their start location and receive further orders.
if (Patrol_Check() == 1) then
set udg_patrolRoad = Patrol_Squad(downpourRect,selector)
call GroupPointOrder(udg_patrolRoad, "attack", 7150.0, 1530.0)
call DestroyGroup(tempGroup)
set downpourRect = null
set tempGroup = null
return
elseif (Patrol_Check() == 2) then
set udg_patrolForest1 = Patrol_Squad(downpourRect,selector)
call GroupPointOrder(udg_patrolForest1, "attack", -2950.0, -300.0)
call DestroyGroup(tempGroup)
set downpourRect = null
set tempGroup = null
return
elseif (Patrol_Check() == 3) then
set udg_patrolForest2 = Patrol_Squad(downpourRect,selector)
call GroupPointOrder(udg_patrolForest2, "attack", -2950.0, -300.0)
call DestroyGroup(tempGroup)
set downpourRect = null
set tempGroup = null
return
else
call BJDebugMsg("Faulty switch result: patrol assignment")
endif
endif
call DestroyGroup(tempGroup)
set downpourRect = null
set tempGroup = null
endfunction
//===== SPAWN SYSTEM END =====\\
function Spawn_Timer takes nothing returns nothing
set udg_spawnTimer = CreateTimer()
call TimerStart(udg_spawnTimer, 15.0, true, function Spawn_System)
endfunction
//===========================================================================
function InitTrig_Spawn_system takes nothing returns nothing
set gg_trg_Spawn_system = CreateTrigger( )
call TriggerAddAction( gg_trg_Spawn_system, function Spawn_Timer)
endfunction
I know, the trigger isn't optimized at all and I use BJ functions and I should be burned at the stake as a witch and all. You can say that I know very little about JASS so all criticism and advice is welcome.