smellymummy
King
- Joined
- Jul 31, 2002
- Messages
- 705
edit: figured it out, here's an example on how to do it:
use utrack() to get the civ, unit, and use utrack(civ, unit, x, y) to send the unit somewhere. it's not perfect, can't get the AI to move on the very first turn, but otherwise seems to work okay
Spoiler :
Code:
local trackarg1 = nil;
local trackarg2 = nil;
local trackarg3 = nil;
local trackarg4 = nil;
local moveai = 0;
function dirtyunit ()
--print("GAMETURN: " .. Game.GetGameTurn() );
if ( moveai == 0 ) then return; end
if ( trackarg1 == nil and trackarg2 == nil and trackarg3 == nil and trackarg4 == nil ) then return; end
local player = Players[ trackarg1 ];
local unit = player:GetUnitByID( trackarg2 );
if ( player:IsTurnActive() and unit:GetMoves() > 0 ) then
local hx, hy = ToGridFromHex( arg3, arg4 );
local plot = Map.GetPlot(hx, hy);
unit:PopMission();
unit:PushMission(0, trackarg3, trackarg4, 0, 0, 1, 0, plot, unit);
end
end
Events.SerialEventUnitInfoDirty.Add ( dirtyunit );
function utrack (arg1, arg2, arg3, arg4)
trackarg1 = arg1;
trackarg2 = arg2;
trackarg3 = arg3;
trackarg4 = arg4;
if (arg1 == nil) then
print("Usage: utrack(CIVNUM, UNITID)");
print("Available units:");
for lnum = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
local player = Players[ lnum ];
if( player:IsAlive() and not player:IsMinorCiv() ) then
print("CIVNUM: " .. lnum .. "\t(" .. civstring(player) .. ")");
print("Units:");
for unit in player:Units() do
print("UNITID: " .. unit:GetID() .. "\t( " .. unit:GetName() .. ", x: " .. unit:GetX() .. ", y: " .. unit:GetY() );
end
end
end
else
local player = Players[ arg1 ];
local unit = player:GetUnitByID( arg2 );
if ( player:IsHuman() ) then
local hx, hy = ToGridFromHex( trackarg3, trackarg4 );
local plot = Map.GetPlot(hx, hy);
unit:PopMission();
unit:PushMission(0, trackarg3, trackarg4, 0, 0, 1, 0, plot, unit);
else
moveai = 1;
end
end
end
function civstring (player)
local civinfo;
if ( not player:IsMinorCiv() ) then civinfo = GameInfo.Civilizations[ player:GetCivilizationType() ];
else civinfo = GameInfo.MinorCivilizations[ player:GetMinorCivType() ];
end
local string = "string";
if (civinfo ~= nil) then
string = Locale.ConvertTextKey( civinfo.Description);
end
return string;
end