Unit sleep command & detecting farms

greenlamb

Chieftain
Joined
Jun 24, 2014
Messages
26
A bit of a crosspost from here, but with another roadblock/question which I encountered...

1. What's the Lua command to make an unit sleep? I get that unit:DoCommand can be used, but in CommandTypes there's only a command for wake, not for sleeping! I thought maybe it's interchangeable, but I tried it out; it didn't make the unit sleep.

Code:
unit:DoCommand(CommandType.COMMAND_WAKE);
Edit: Answered in the original post.




2. I have the following code which I modified from bouncymischa's code here, where the aim is basically to make a button that would heal the unit as well as pillage a farm at the same time. However, the button is still not valid when the unit is on a farm, and I can't figure out why it doesn't work.

Code:
function CheckPillageHealButtonValidity(pPlayer, pUnit)
	local iCurrentCulture = pPlayer:GetJONSCulture();
	if (iCurrentCulture > 50) and (pUnit:GetPlot():GetImprovementType() == [COLOR="Red"][B]IMPROVEMENT_FARM[/B][/COLOR]) then
		return true;
	end
	return false;
end


2nd Edit: I found the problem myself... As highlighted in bolded red above, the constant should not be just "IMPROVEMENT_FARM", but as written in the wiki, it should be "GameInfo.Improvements.IMPROVEMENT_FARM.ID". Therefore the correct code is:

Code:
function CheckPillageHealButtonValidity(pPlayer, pUnit)
	local iCurrentCulture = pPlayer:GetJONSCulture();
	if (iCurrentCulture > 50) and (pUnit:GetPlot():GetImprovementType() == GameInfo.Improvements.IMPROVEMENT_FARM.ID) then
		return true;
	end
	return false;
end

*slaps forehead* silly me. We live and learn...
 
Back
Top Bottom