Deleting a Unit With Lua
Posted: Mon Oct 11, 2021 2:20 pm
I'm trying to simulate a constant flow of merchant traffic across a strait by using LUA to create a ship with a certain course every hour and then, when the ship reaches the destination port, destroying it. Unfortunately, while creation is working great, I'm running into some error with removing when that seems like a very simple thing to do.
I've got an event set up that triggers when a unit enters the area in question and then runs a Lua script as its action. The event does trigger, so I've got that set up correctly, but the unit is not removed.
Specifically, my script is:
When the unit enters the target area I get popup boxes for "Test 1" and "Test 2" but nothing else.
Any thoughts?
I've got an event set up that triggers when a unit enters the area in question and then runs a Lua script as its action. The event does trigger, so I've got that set up correctly, but the unit is not removed.
Specifically, my script is:
Code: Select all
unit = ScenEdit_UnitX()
ScenEdit_MsgBox('Test 1' .. unit.name .. unit.guid, 1)
if (string.find(unit.name, 'EW')) then
ScenEdit_MsgBox('Test 2 ' .. unit.name, 1)
if (ScenEdit_KillUnit(unit)) then
ScenEdit_MsgBox('Test 3 ' .. unit.name, 1)
ScenEdit_SetScore('NATO',ScenEdit_GetScore ('NATO')-20,'Chinese Ship Reached Taiwanese Landing Zone')
ScenEdit_MsgBox('Test 4 ' .. unit.name, 1)
else
ScenEdit_MsgBox('Test error ' .. _errmsg_, 1)
end
endWhen the unit enters the target area I get popup boxes for "Test 1" and "Test 2" but nothing else.
Any thoughts?
