[Solved] Add road or improvment through LUA.

cromcrom

Cernu
Joined
Nov 11, 2005
Messages
268
Location
Chateauroux
Hi all,

I would like to improve my mod, and give a little random chance that a unit, while moving, will create a road. Are you aware of a way to do this through LUA ? I know there is a "create" for units, but I didn't see anything for roads or improvments, or else.

Any ideas please ?
 
Route:

WorldBuilder.MapManager():SetRouteType( plot, entry.Type.Index, Controls.RoutePillagedCheck:IsChecked() )

to be more precise:

WorldBuilder.MapManager():SetRouteType( plot, entry.Type.Index, false )

Improvement:

WorldBuilder.MapManager():SetImprovementType( plot, entry.Type.Index, Map.GetPlotByIndex( m_SelectedPlot ):GetOwner() );

Event Hook

function OnUnitMoved (UnitID, UnitX, UnitY, Unknown (boolean), Unknown (-1))
-- do stuff here
end
Events.UnitMoved.Add(OnUnitMoved);

PER LeeS:

  1. Events.UnitMoved(iPlayer, iUnitID, iPlotX, iPlotY, bMoveIsVisibleToHuman, iUnknownInteger)
    • fires for each unit's individual moves

(a) You'd get the plot from UnitX/UnitY;
(b) entry.Type.Index should be self-explanatory, as in, for instance:
GameInfo.Routes["ROUTE_ANCIENT_ROAD"].Index

You can find a sampling of these WorldBuilder functions in WorldBuilderPlacement.lua
 
Last edited:
Or use this one, per @LeeS:

Events.UnitMoveComplete(iPlayer, iunitID, iPlotX, iPlotY)
  • fires for the plot the unit's movements terminated in
  • fires when you tell the unit to skip rest of moves
  • appears to fire when a builder does a build, because this is the completion of the unit's moves for that turn. (note: need to re-confirm)
 
Back
Top Bottom