Lua an only-heal-category

Lua an only-heal-category

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
azaremoth
Cursed Developer
Posts: 549
Joined: 17 Feb 2005, 22:05

Lua an only-heal-category

Post by azaremoth »

So... I want to have a builder unit only healing a certain a type of other units. With "AllowCommand" and a check of "customParams.isinfantry" it is easy to block direct healing orders. Buuut... how can automated healing orders of patrolling units be accesed and blocked?
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Lua an only-heal-category

Post by jK »

azaremoth wrote:With "AllowCommand" and a check of "customParams.isinfantry" it is easy to block direct healing orders. Buuut... how can automated healing orders of patrolling units be accesed and blocked?
All commands go through AllowCommand
And patrolling does nothing else than inserting proper CMD_ATTACKS, CMD_REPAIR, ... cmds
User avatar
azaremoth
Cursed Developer
Posts: 549
Joined: 17 Feb 2005, 22:05

Re: Lua an only-heal-category

Post by azaremoth »

Well - this code is blocking direct heal commands, but the patrol command is still allows automated healing. What am I doing wrong here?

Code: Select all

function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
if (cmdID == 40) then
	  local RepairedUnit = (cmdParams[1])
	  local RepairedUnitDefID = Spring.GetUnitDefID(RepairedUnit)
	  if (UnitDefs[RepairedUnitDefID].customParams.isinfantry) then 
			return false
	  else
			return true
	  end
end
	return true -- allowed
end
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Lua an only-heal-category

Post by jK »

NEVER USE MAGIC NUMBERS
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lua an only-heal-category

Post by smoth »

What is the name of cmdid 40 azare?
User avatar
azaremoth
Cursed Developer
Posts: 549
Joined: 17 Feb 2005, 22:05

Re: Lua an only-heal-category

Post by azaremoth »

That is CMD.REPAIR - but that does not change a thing... So this does exactly same - I am checking the code events with Echos sometimes ;) .

Code: Select all

function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
if (cmdID == CMD.REPAIR) then
	  local RepairedUnit = (cmdParams[1])
	  local RepairedUnitDefID = Spring.GetUnitDefID(RepairedUnit)
	  if (UnitDefs[RepairedUnitDefID].customParams.isinfantry) then 
			return false
	  else
			return true
	  end
end
	return true -- allowed
end
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Lua an only-heal-category

Post by smoth »

Code: Select all

if (cmdID == CMD.REPAIR) then
Spring.Echo("WAAAAAAAAAAFLES")
Does waffles get echoed?
User avatar
azaremoth
Cursed Developer
Posts: 549
Joined: 17 Feb 2005, 22:05

Re: Lua an only-heal-category

Post by azaremoth »

Yes - for manual commands. When units are patrolling the AllowCommand obviously is not called. Is it a bug or just my incodepetence?

Code: Select all

function gadget:AllowCommand(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
	if (cmdID == CMD.REPAIR) then
		  Spring.Echo("WAAAFLES!")
		  local RepairedUnit = (cmdParams[1])
		  local RepairedUnitDefID = Spring.GetUnitDefID(RepairedUnit)
		  if (UnitDefs[RepairedUnitDefID].customParams.isinfantry ~= nil) then 
				Spring.Echo("WITHOUT CREME FOR YOU!")
				return false
		  else
				Spring.Echo("CREME AND CHERRIES!")
				return true
		  end
	end
	return true -- allowed
end
http://azaremoth.supremedesign.org/img/ ... otheal.png
http://azaremoth.supremedesign.org/img/ ... gnores.png
User avatar
SinbadEV
Posts: 6475
Joined: 02 May 2005, 03:56

Re: Lua an only-heal-category

Post by SinbadEV »

jK wrote:NEVER USE MAGIC NUMBERS
Right, use enums :P
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Lua an only-heal-category

Post by jK »

k checked the code patrol cmds aren't passed via AllowCommand, which seems to a missing feature then.
You can pool all units for their to top queue cmd and remove them then, still this will cause the engine to just readd them (eating performance and causing ugly sim behavior)
Post Reply

Return to “Lua Scripts”