Page 1 of 1

Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 04:24
by Forboding Angel
local mexBuildCommandID = -UnitDefNames["emetalextractor"].id

I want to add water mexes to it as well (in particular "euwmetalextractor"), but I'm not sure how because the way it seems to be set up with the way the commands are issued, I don't know how to add another type of mex to it.

Can someone help me out?
cmd_area_mex.lua
(3.96 KiB) Downloaded 22 times

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 10:56
by Niobium
That gadget is absolutely atrocious, it really should be deleted and rewritten for scratch.

However, if you are after a quick fix. I'd replace the lines that look like this:

Code: Select all

spGiveOrderToUnit(unitID, mexBuildCommandID, {data.mex[i].x,0,data.mex[i].z} , {"shift"})
With an appropriate call to a function like:

Code: Select all

function TellUnitToBuildMexAt(uId, x, z)
	local y = Spring.GetGroundHeight(x, z)
	if y < 0 then
		spGiveOrderToUnit(uId, UNDERWATERMEXID, {x, y, z}, {"shift"})
	else
		spGiveOrderToUnit(uId, LANDMEXID, {x, y, z} , {"shift"})
	end
end
e.g.

Code: Select all

TellUnitToBuildMexAt(unitID, data.mex[i].x, data.mex[i].z)

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 13:12
by Forboding Angel
Thanks for the help. I got this far, but what do I do about line 121?

http://pastebin.mozilla.org/1837950

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 14:02
by Niobium
Same pattern as the other

Code: Select all

spGiveOrderToUnit(unitID, mexBuildCommandID, {orderedCommands[i].x,0,orderedCommands[i].z} , {"shift"})
Becomes

Code: Select all

TellUnitToBuildMexAt(unidID, orderedCommands[i].x, orderedCommands[i].z)

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 21:13
by Forboding Angel
Ahh thanks.

Ok, hopefully last hurdle...

http://pastebin.com/YXxpv1xB

Errors with 56: bad unit id, so obviously I'm not giving it the right information in the declared locals, but I'm not sure what it needs?

I assume I need to call the unit names differently.

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 23:22
by knorke
Forboding Angel wrote: Errors with 56: bad unit id, so obviously I'm not giving it the right information in the declared locals, but I'm not sure what it needs
its in real time so the visual basic gui is tracing the wrong ip adress.

line 119 unidID :arrow: unitID

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 23:37
by Forboding Angel
Changed. Still errors on 56 or 54 (depending on where I draw the circle -> water/land). Difference is instead of bad unit id, now it's bad command id.

Code: Select all

[f=0001125] Error: LuaRules::RunCallIn: error = 2, AllowCommand, [string "LuaRules/Gadgets/cmd_area_mex.lua"]:56: GiveOrderToUnit(): bad command ID

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 23:46
by knorke
Niobium wrote UNDERWATERMEXID and LANDMEXID as placeholders for your unitnames.

you have

Code: Select all

local underWaterMexID = euwmetalextractor
local landMexID = emetalextractor
Assuming that are your mex names, change to:
change to

Code: Select all

local landMexID = -UnitDefNames["emetalextractor"].id
local underWaterMexID = -UnitDefNames["euwmetalextractor"].id
^- that is how you get unitdefid to a unitname

Or if you want to have it "more right" remove the "-" sign from the above and add it in all the spGiveOrderToUnit

Re: Area Mex gadget support for multiple mexes

Posted: 23 Sep 2012, 23:55
by Forboding Angel
Derp. Thanks :-)

I had actually set those unitnames like that, but when I started getting bad unitID errors I reverted them (thinking that I wasn't understanding what nio was saying correctly). Thanks for clearing it up for me and thanks a ton Niobium for helping me out :-) <3