How to check if i can to move a unit onto a plot? (Lua)

killmeplease

Mk Z on Steam
Joined
Nov 22, 2007
Messages
2,795
Location
Samara
I have tried CanMoveOrAttackInto(plot) but it always returns false (not working?).
I can check manually all the conditions e.g. if a plot is impassable and if there are another units but maybe theres another function which does all those checks? what function does UI use for example?

thanks!
 
I have tried CanMoveOrAttackInto(plot) but it always returns false (not working?).

It's bugged, Firaxis forget to actually return the C++ result to the Lua API!
 
pUnit:CanMoveOrAttackInto(pPlot) is identical to pUnit:CanMoveThrough(pPlot), but the latter actually returns the result!
 
well... CanMoveThrough determines if a unit can move through a tile but not if it can stay there.
so i have written a lua func not ideal maybe.. at least i think there should be a better way to determine a caravan unit.
Code:
function CanMoveOnto(unit, plot)
	if plot:IsWater() then
		return unit:CanEmbarkOnto(unit:GetPlot(), plot);
	end
	if plot:IsImpassable() then
		return false;
	end
	for i = 0, plot:GetNumUnits() do
		local other = plot:GetUnit(i);
		if other ~= nil and not GameInfo.Units[other:GetUnitType()].Immobile -- caravan
		and (other:IsCombatUnit() == unit:IsCombatUnit() or other:GetOwner() ~= unit:GetOwner()) then
			return false;
		end
	end
	return true;
end

ps: another thing i learned was that if you call JumpToNearestValidPlot on a caravan unit it will brake :) it wont be able to do anything anymore just sitting in the city blocking it for civilians. so dont do this
 
Back
Top Bottom