I spend a whole day on this bug and still havn't fixed it. I hope you guys can help me.
Sometimes the group of units stops to walk.
The funny thing is when I use these waypoints ({15,15}, {70,15}, {70,20}, {15,20}, {10,10}) only the third wave of attackers stops at the second waypoint. If I use these waypoints ({120,91}, {49,91}, {49,30}, {5,30}) the second wave of attackers stops also at the second waypoint.
<?xml version="1.0" standalone="yes" ?>
<scenario>
<difficulty value="0"/>
<players>
<player control="human" faction="defence" team="1"/>
<player control="cpu" faction="attack" team="2"/>
<player control="closed"/>
<player control="closed"/>
</players>
<map value="TD_like_4"/>
<tileset value="forest"/>
<tech-tree value="td_6"/>
<default-resources value="false"/>
<default-units value="false"/>
<default-victory-conditions value="false"/>
<scripts>
<startup>
----------------------------------------------------------------------------
-- Unit Creation and Group Management --
----------------------------------------------------------------------------
-- creates a unit and puts its id in group
function createAndGroup ( group, type, faction, pos )
createUnit ( type, faction, pos );
group[#group+1] = lastCreatedUnit ();
end
-- create a group of num units of a single unit type
function groupOfType ( group, type, faction, num, pos )
for i=1,num do createAndGroup ( group, type, faction, pos ) end
end
-- create a group of units of different types
function groupFromTypes ( group, types, faction, pos )
for i=1,#types do createAndGroup ( group, types[i], faction, pos ) end
end
-- remove a unit id from a group
function removeFromGroup ( group, unitId )
for i=1,#group do
if ( group[i] == unitId ) then
table.remove ( group, i );
return;
end
end
end
-- checks if unit belongs to group
function unitIsinGroup ( group, unitId )
for i=1,#group do
if ( group[i] == unitId ) then
return true;
end
end
end
----------------------------------------------------------------------------
-- Group Commands --
----------------------------------------------------------------------------
-- give a group of units move commands to location
function groupMoveCommon ( units, location )
for i=1,#units do givePositionCommand ( units[i], "move", location ) end
end
-- give a group of units move commands to distinct locations
function groupMoveSpecific ( units, locations )
for i=1,#units do givePositionCommand ( units[i], "move", locations[i] ) end
end
-- give a group of units attack commands to location
function groupAttack ( units, pos )
for i=1,#units do givePositionCommand ( units[i], "attack", pos ) end
end
----------------------------------------------------------------------------
-- Geometry --
----------------------------------------------------------------------------
-- is pos in rectangle
function pointIsIn ( pos, rectangle )
if ( pos[1] >= rectangle[1] and rectangle[3] > pos[1]
and pos[2] >= rectangle[2] and rectangle[4] > pos[2] ) then
return true;
end
return false;
end
-- returns a rectangle around the point 'pos'
function areaAround ( pos )
return { pos[1]-5, pos[2]-5, pos[1]+5, pos[2]+5 };
end
----------------------------------------------------------------------------
-- Start-Up --
----------------------------------------------------------------------------
-- the patrol table will store the waypoints and regions around them
patrol = {};
patrol.waypoints = {{15,15}, {70,15}, {70,20}, {15,20}, {10,10} };
patrol.regions = {};
for i=1,#patrol.waypoints do
patrol.regions[#patrol.regions+1] = areaAround(patrol.waypoints[i]);
end
-- Make a group of 8 daemons...
disableAi (1);
daemons = {};
daemons.units = {};
groupOfType ( daemons.units, "daemon", 1, 8, patrol.waypoints[1] );
-- start them on their way...
groupMoveCommon ( daemons.units, patrol.waypoints[2] );
-- remember where they are currently going...
daemons.dest = 2; -- index of current target
tickCount = 0;
disableAi(1)
createUnit ( "castle2", 0, {10,30} );
createUnit('worker', 0, {startLocation(0)[1],startLocation(0)[2]});
createUnit('defense_tower', 0, {50,24});
createUnit('defense_tower', 0, {40,24});
createUnit('defense_tower', 0, {53,24});
createUnit('defense_tower', 0, {44,24});
createUnit('defense_tower', 0, {36,24});
createUnit('defense_tower', 0, {50,32});
createUnit('defense_tower', 0, {40,32});
createUnit('defense_tower', 0, {53,32});
createUnit('defense_tower', 0, {44,32});
createUnit('defense_tower', 0, {36,32});
createUnit('defense_tower', 0, {startLocation(0)[1]-4,startLocation(0)[2]});
createUnit ( "initiate", 1, startLocation(1) );
givePositionCommand(lastCreatedUnit(1), 'move', startLocation(0));
createUnit ( "archer", 0, {38,55} );
createUnit ( "victim", 1, {30,55} );
setCameraPosition({30,55});
giveResource('gold', 0, 2000);
giveResource('stone', 0, 100);
giveResource('wood', 0, 2000);
giveResource('food', 0, 500);
startTime = os.time();
a=true;
wave=0;
</startup>
<unitDied>
timeSinceStart = os.time() - startTime;
x=30;
--spawnedgroup;
<!--
a= not a;
if (a==true) then
x=30
else
x=46
end
-->
alone= {};
setDisplayText(#alone)
if(unitIsinGroup ( daemons.units, lastDeadUnit () )) then
--alone= 6;
--setDisplayText(#alone)
--What happens if an unit dies betweeen the line before and the line after this comment (lastDeadUnit!=lastDeadUnit)?
if ((#daemons.units) > 1) then
removeFromGroup ( daemons.units, lastDeadUnit ())
elseif ((#daemons.units) == 1) then
vitality =false;
removeFromGroup ( daemons.units, lastDeadUnit ())
diedat= tickCount;
wave=wave+1;
createUnit ( "summoner", 1, startLocation(1) );
end
giveResource('gold', 0, 500);
giveResource('stone', 0, 50);
giveResource('wood', 0, 50);
giveResource('food', 0, 50);
end
if ( lastDeadUnitName() == "victim" ) then
a = not a;
if (a==true) then
x=30
else
x=46
end
createUnit ( "victim", 1, {x,55} );
tickCount = tickCount + 1;
if( (#daemons.units) >= 1 ) then --check how big the group is because if there are 0 units I will get an error
-- the value has to be 2 because the first unit is created at the 2nd place of the array
-- Check if daemons have reached target...
local cur_pos = unitPosition(daemons.units[1]);
local cur_dest = patrol.regions[daemons.dest];
if ( pointIsIn(cur_pos, cur_dest) ) then
-- we have arrived, set next destination...
daemons.dest = daemons.dest % #patrol.waypoints + 1;
-- and head on out..
groupMoveCommon ( daemons.units, patrol.waypoints[daemons.dest] );
end
-- Do things at particular times here...
if ( tickCount == 10 ) then
--spawnedgroup
elseif ( tickCount == 20 ) then
-- another scripted action...
elseif ( tickCount == 30 ) then
-- etc
end
end
end
if ((vitality==false) ) then
if (((tickCount- diedat) == 10) and (wave==1)) then
groupOfType ( daemons.units, "battlemage", 1, 8, patrol.waypoints[1] );
groupMoveCommon ( daemons.units, patrol.waypoints[2] );
elseif (((tickCount- diedat) == 10) and (wave==2)) then
groupOfType ( daemons.units, "battlemage", 1, 8, patrol.waypoints[1] );
groupMoveCommon ( daemons.units, patrol.waypoints[2] );
elseif (((tickCount- diedat) == 10) and (wave==3)) then
--groupOfType ( daemons.units, "initiate", 1, 8, patrol.waypoints[1] );
--groupMoveCommon ( daemons.units, patrol.waypoints[2] );
end
end
</unitDied>
</scripts>
</scenario>
I guess there is no "unitKill(unid)" command or something similar?