SorFox
Chieftain
Hi to all Civers,
@JPetroski: I am following your initiative to apply Lua in Civ scenarios with great interest. Hope, you don’t mind if I address my Lua issues here as well? Just as you said:
Basically, I’d like to write the code of Prof. Garfield’s suggestion:
After hundreds of scripting approaches I am kind of stucked. Here’s where I got
The Lua console returns for unit A (id=62) in my example correctly three positions: {77, 209, 0}, {87, 207, 0}, {95, 209, 0}, whereas the only unit B in game is on tile {87, 207, 0}. The point is: That should be a match – but the ‘correctPosition’ query is not firing – still revealing “0”. I also tried to combine it with 'civ.scen.onTurn( function(turn)' with the same result. Please be aware that I do not want to give upfront statically tiles as code’s input. It would be really cool to dynamically read out the positions of the two moving units (A, B) and then – if they are on the same tile – deliberately hit the key (start action).
Any help would be greatly appreciated!
@JPetroski: I am following your initiative to apply Lua in Civ scenarios with great interest. Hope, you don’t mind if I address my Lua issues here as well? Just as you said:
I think it’s a good idea to have individual “scenario creation threads” like your “Over the Reich” on the one hand, and besides that specifically Lua related Q&As threads – therefore I take the liberty to hijack this one. And: I try to be meaningful with my questions, which may help others in practice, too.“First of all, this is a generic lua thread where anyone who knows something about it can help out… Not just TNO, who can either ignore it or join as he sees fit. [#3]”
Basically, I’d like to write the code of Prof. Garfield’s suggestion:
“Depending on what kinds of triggers are possible […] after producing unit "soldiers" and unit "horses" you get them in the same position, trigger something ("key pressed" would be perfect for that), the two individual units are destroyed and a "combined" dragoon unit is created at the same position. [#698]”
After hundreds of scripting approaches I am kind of stucked. Here’s where I got
Code:
local factoryLocations = {x, y, z}
for unit in civ.iterateUnits() do if unit.type.id == 62 then
print (unit.location.x, unit.location.y, unit.location.z)
end
end
local currentUnit = civ.getActiveUnit()
local currentTileCoordinates = { {currentUnit.location.x, currentUnit.location.y, currentUnit.location.z} }
local correctPosition=0
while factoryLocations.x==currentUnit.location.x and factoryLocations.y==currentUnit.location.y and factoryLocations.z==currentUnit.location.z do
--Another try: while factoryLocations[x, y, z] == currentUnit.location[x, y, z] do
correctPosition=1
end
if correctPosition==1 then
civ.ui.text("It works!")
end
The Lua console returns for unit A (id=62) in my example correctly three positions: {77, 209, 0}, {87, 207, 0}, {95, 209, 0}, whereas the only unit B in game is on tile {87, 207, 0}. The point is: That should be a match – but the ‘correctPosition’ query is not firing – still revealing “0”. I also tried to combine it with 'civ.scen.onTurn( function(turn)' with the same result. Please be aware that I do not want to give upfront statically tiles as code’s input. It would be really cool to dynamically read out the positions of the two moving units (A, B) and then – if they are on the same tile – deliberately hit the key (start action).
Any help would be greatly appreciated!
Last edited: