I added the following LUA functions to the svn version which will be released with 3.4:
destroyUnit(unitId)
morphToUnit(unitId,morphName, ignoreRequirements)
moveToUnit(unitId,destUnitId)
giveAttackStoppedCommand(unitId, valueName,ignoreRequirements)
playStaticSound(playSound)
playStreamingSound(playSound)
stopStreamingSound(playSound)
stopAllSound()
The commands taking ignoreRequirements expect 0 for try to execute the command with requirements and 1 to skip requirements checking.
Below is a sample scenario using some of these methods:
<?xml version="1.0" standalone="yes" ?>
<scenario>
<difficulty value="3"/>
<players>
<player control="human" faction="tech" team="1"/>
<player control="cpu" faction="tech" team="2"/>
<player control="cpu" faction="tech" team="2"/>
<player control="cpu" faction="tech" team="2"/>
</players>
<map value="in_the_forest"/>
<tileset value="forest"/>
<tech-tree value="megapack"/>
<default-resources value="false"/>
<default-units value="false"/>
<default-victory-conditions value="false"/>
<scripts>
<startup>
print( 'Test, START of Capture the flag!' )
--disable AI
disableAi(1)
disableAi(2)
disableAi(3)
disableConsume(0)
unitA = 'guard'
unitB = 'castle'
captureTheFlagSeconds = 90
DisplayFormattedText('You have %s seconds to move the %s into the %s!', captureTheFlagSeconds,unitA, unitB)
for i=0, 3 do
print( 'Is AI enabled for faction index: ' .. i .. ', ' .. tostring( getAiEnabled(i)) )
print( 'Is consume enabled for faction index: ' .. i .. ', ' .. tostring( getConsumeEnabled(i)) )
end
--allied units
--createUnit('farm', 0, startLocation(2))
createUnit(unitB, 1, startLocation(2))
enemyCastle= lastCreatedUnit()
castleUnit= lastCreatedUnit()
createUnit('worker', 1, startLocation(2))
enemyWorker= lastCreatedUnit()
for i=1, 5 do
createUnit('swordman', 1, startLocation(2))
end
giveResource('gold', 0, 1000);
giveResource('wood', 0, 1000);
giveResource('food', 0, 1000);
giveResource('food', 1, 5);
--player units
createUnit('battle_machine', 0, startLocation(1))
battle_machine= lastCreatedUnit()
createUnit(unitA, 0, startLocation(2))
guard= lastCreatedUnit()
moveToUnit(guard,enemyWorker)
createUnit('technician', 0, startLocation(1))
technician= lastCreatedUnit()
moveToUnit(technician,enemyCastle)
createUnit('battle_machine', 0, startLocation(1))
bm2= lastCreatedUnit()
for i=1, 3 do
createUnit('archer', 0, startLocation(2))
test = lastCreatedUnit()
giveAttackCommand(test, castleUnit)
end
for i=1, 10 do
createUnit('swordman', 0, startLocation(1))
givePositionCommand(lastCreatedUnit(), 'attack', startLocation(1))
end
cell_event1 = registerCellTriggerEventForUnitToUnit(guard,castleUnit)
print( 'cell_event1 = ' .. cell_event1 )
cell_event2 = registerCellTriggerEventForUnitToUnit(battle_machine,castleUnit)
print( 'cell_event2 = ' .. cell_event2 )
timer_event1 = startTimerEvent()
print( 'timer_event1 = ' .. timer_event1 )
setCameraPosition(unitPosition(guard))
</startup>
<unitCreated>
</unitCreated>
<unitDied>
enableConsume(0)
enableAi(1)
enableAi(2)
enableAi(3)
for i=0, 3 do
print( 'Is AI enabled for faction index: ' .. i .. ', ' .. tostring( getAiEnabled(i)) )
print( 'Is consume enabled for faction index: ' .. i .. ', ' .. tostring( getConsumeEnabled(i)) )
end
clearDisplayText()
print( 'About to morph unit: ' .. technician )
morphToUnit(technician,'build_air_ballista',1)
destroyUnit(battle_machine);
giveAttackStoppedCommand(bm2,'hold_position',1)
playStreamingSound('/home/softcoder/Code/megaglest/trunk/data/glest_game/techs/megapack/factions/romans_beta/music/romans.ogg')
print( 'Done morphing...' )
</unitDied>
<cellTriggerEvent>
--print('Cell Event ' .. triggeredCellEventId() )
--print( 'In cell event triggeredCellEventId = ' .. triggeredCellEventId() .. ' cell_event1 = ' .. cell_event1 .. ' cell_event2 = ' .. cell_event2 )
if triggeredCellEventId() == cell_event1 or triggeredCellEventId() == cell_event2 then
clearDisplayText()
DisplayFormattedText('You captured the FLAG!')
stopTimerEvent(timer_event1)
unregisterCellTriggerEvent(cell_event1)
unregisterCellTriggerEvent(cell_event2)
end
</cellTriggerEvent>
<timerTriggerEvent>
--print('Timer Event ' .. triggeredTimerEventId() )
--print( 'In timer event triggeredTimerEventId = ' .. triggeredTimerEventId() .. ' timer_event1 = ' .. timer_event1 )
if triggeredTimerEventId() == timer_event1 then
if timerEventSecondsElapsed(triggeredTimerEventId()) >= captureTheFlagSeconds then
print( 'In timer event triggeredTimerEventId = ' .. triggeredTimerEventId() .. ' timer_event1 = ' .. timer_event1 .. ' seconds elapsed = ' .. timerEventSecondsElapsed(triggeredTimerEventId()) )
clearDisplayText()
DisplayFormattedText('Your time ran out of time to capture the FLAG!')
stopTimerEvent(timer_event1)
unregisterCellTriggerEvent(cell_event1)
unregisterCellTriggerEvent(cell_event2)
endGame()
end
end
</timerTriggerEvent>
</scripts>
</scenario>