How I can force to heal for AI units?

grumblerbear

Chieftain
Joined
Sep 7, 2013
Messages
17
I have

Code:
function SetUnitState (unit, mission_type, target_plot)
    if (target_plot == nil) then
        target_plot = unit:GetPlot();
    end
    unit:PopMission();
    unit:PushMission(mission_type, target_plot:GetX(), target_plot:GetY(), 0, 0, 1, mission_type, target_plot, unit);
--    Game.SelectionListGameNetMessage(GameMessageTypes.GAMEMESSAGE_PUSH_MISSION, mission_type, target_plot:GetX(), target_plot:GetY(), 0, false, false);
end

local mission_type;
if (not player:IsBarbarian()) then
    mission_type = MissionTypes.MISSION_HEAL;
else
    mission_type = MissionTypes.MISSION_HOLD;
end
SetUnitState(unit, mission_type);

It work, but AI ignore this command :(
 
Depends on what "It work, but the AI ignore this command" means.

If you mean that the code works in Fire/LiveTuner but doesn't work in a mod, that's because there's no code to apply it to AI units during the AI's turn.

If you mean that the code works only for the first turn for an AI's unit, that's because at the start of every turn the AI gathers all its units and reassigns them based on what it (ie the C++ code) thinks they are doing - and one of the things the AI does with its units is "wander back and forth aimlessly around my borders", so you'll probably need to re-issue the mission every turn.

If you mean that it doesn't even work for the first turn, you may also need to use up all of the units moves (pUnit:SetMoves(0) and/or whatever the Lua call is tah is the equivalent of the C++ method pUnit->finishMoves())

Or it may mean something else and my crystal ball has failed today.
 
Sorry for the uncertainty of of my explanation - I'll try to explain better.

I have an event

Code:
function DangerousJourneySupply ( player_id )
        [...]
	local player = Players[player_id];
	local team = Teams[player:GetTeam()];

	if ( player:IsAlive() ) then
		for unit in player:Units() do
                       [code here]
                end
        end
end

GameEvents.PlayerDoTurn.Add( DangerousJourneySupply );

PushMission correct work for me (human player, but AI still continues to move units). I try with SetMoves(0), but units just standing and not healed
 
Back
Top Bottom