Page 1 of 1
Lua an only-heal-category
Posted: 13 Mar 2014, 22:02
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?
Re: Lua an only-heal-category
Posted: 13 Mar 2014, 22:13
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
Re: Lua an only-heal-category
Posted: 13 Mar 2014, 22:51
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
Re: Lua an only-heal-category
Posted: 13 Mar 2014, 22:52
by jK
NEVER USE MAGIC NUMBERS
Re: Lua an only-heal-category
Posted: 13 Mar 2014, 23:31
by smoth
What is the name of cmdid 40 azare?
Re: Lua an only-heal-category
Posted: 13 Mar 2014, 23:43
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
Re: Lua an only-heal-category
Posted: 14 Mar 2014, 00:06
by smoth
Code: Select all
if (cmdID == CMD.REPAIR) then
Spring.Echo("WAAAAAAAAAAFLES")
Does waffles get echoed?
Re: Lua an only-heal-category
Posted: 14 Mar 2014, 22:28
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
Re: Lua an only-heal-category
Posted: 15 Mar 2014, 01:53
by SinbadEV
jK wrote:NEVER USE MAGIC NUMBERS
Right, use enums

Re: Lua an only-heal-category
Posted: 15 Mar 2014, 02:35
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)