- Joined
- Jan 24, 2011
- Messages
- 5,004
Can someone please give me a hand here? I've been tinkering with @McMonkey's "Philip of Macedon" events today and making really good progress, honestly. I've been able to accomplish quite a bit on my own and tweak some events to get them firing the way I want them to. We have one event that is giving me some trouble. Basically, after a certain city is conquered by Macedon, a state is set. The next turn, a dialogue option comes up with a choice of honoring an alliance and turning cities over to your ally or dissolving the alliance and keeping the cities for yourself. I'm trying to get the event to delete Macedonian units within the city if they are turned over to the Ally, but I can't get it to work.
I have all the potential unit types that could be in the city here:
I have this (copied and adjusted from Knighttime's code in Napoleon) and have confirmed the coordinates are correct.
I am trying to get this to fire and delete the unit. I can get the dialogue box to show up. I can also get the cities to transfer. But I can't get the Macedonian units to delete. No error messages are being thrown. There is also nothing being printed regarding the deletion of units as the event is not firing.
I appreciate the help!
Edit - this event is under the civ.scen.onTurn(function (turn) and there is another for unit in civ sequence above the one I can't get to work... I'm curious if this is what is causing the error?
for unit in civ.iterateUnits() do
for _, typeToBeDeleted in pairs(unitTypesToBeDeletedEachTurn) do
if unit.type.id==typeToBeDeleted then
civ.deleteUnit(unit)
end
end
end
I have all the potential unit types that could be in the city here:
Code:
local MacedonianUnitTypesToBeDestroyed = {14, 15, 23, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 119, 110, 112, 114, 9, 93, 94, 95, 96, 97, 98, 90, 91, 92, 34, 22, 21, 106, 107, 99, 101, 102, 103, 100, 105, 104, 108, 109, 86, 88, 51, 14, 63, 64, 17, 26, 65, 24, 19, 20, 16, 50, 52, 121, 122, 123, 0, 1, 2, 3, 4, 8, 13, 40, 46, 47, 48, 49, 120, 124, 125, 126}
I have this (copied and adjusted from Knighttime's code in Napoleon) and have confirmed the coordinates are correct.
Code:
local function cityTileWithinChalcidia (tile)
if tile.z ~= 0 or tile.terrainType & 0x0a == 0x0a then
return false
else
if (tile.x == 73 and tile.y == 57) or
(tile.x == 71 and tile.y == 49) then
return true
else
return false
end
end
end
I am trying to get this to fire and delete the unit. I can get the dialogue box to show up. I can also get the cities to transfer. But I can't get the Macedonian units to delete. No error messages are being thrown. There is also nothing being printed regarding the deletion of units as the event is not firing.
Code:
if state.cityTaken_PotidaeaDecision==1 then
local ChalcidianCityToReturn = {"Potidaea", "Anthemus"}
--g -A - Honour agreement with Chalcideans.= Potidaea & Anthemus transferred to Chalcidians
dialog = civ.ui.createDialog()
dialog.title = "Alliance!"
dialog.width = 300
dialog:addText("King Philipp honors the treaty with the Chalcideans. Potidaea and Anthemus are returned to Chalcidian control!")
--dialog:addImage("PicEvents_Option1.bmp")
dialog:show()
for _, cityName in pairs(ChalcidianCityToReturn) do
local city = findCityByName(cityName)
if city.owner ~= Chalcidia then
city.owner = Chalcidia
print("Gave ownership of " .. cityName .. " to Chalcidia")
end
end
for unit in civ.iterateUnits() do
if unit.owner == Macedon and unit.type.domain == 0 and (cityTileWithinChalcidia(unit.location))then
for _, typeToBeDestroyed in pairs(MacedonianUnitTypesToBeDestroyed) do
if unit.type == typeToBeDestroyed then
print("Destroyed " .. unit.type.name .. " at " .. unit.x .. "," .. unit.y .. "," .. unit.z)
civ.deleteUnit(unit)
end
end
end
end
I appreciate the help!
Edit - this event is under the civ.scen.onTurn(function (turn) and there is another for unit in civ sequence above the one I can't get to work... I'm curious if this is what is causing the error?
for unit in civ.iterateUnits() do
for _, typeToBeDeleted in pairs(unitTypesToBeDeletedEachTurn) do
if unit.type.id==typeToBeDeleted then
civ.deleteUnit(unit)
end
end
end
Last edited: