Area Mex gadget support for multiple mexes

Area Mex gadget support for multiple mexes

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

Moderator: Moderators

Post Reply
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14638
Joined: 17 Nov 2005, 02:43

Area Mex gadget support for multiple mexes

Post 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
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Area Mex gadget support for multiple mexes

Post 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)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14638
Joined: 17 Nov 2005, 02:43

Re: Area Mex gadget support for multiple mexes

Post by Forboding Angel »

Thanks for the help. I got this far, but what do I do about line 121?

http://pastebin.mozilla.org/1837950
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: Area Mex gadget support for multiple mexes

Post 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)
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14638
Joined: 17 Nov 2005, 02:43

Re: Area Mex gadget support for multiple mexes

Post 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.
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Area Mex gadget support for multiple mexes

Post 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
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14638
Joined: 17 Nov 2005, 02:43

Re: Area Mex gadget support for multiple mexes

Post 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
User avatar
knorke
Posts: 7971
Joined: 22 Feb 2006, 01:02

Re: Area Mex gadget support for multiple mexes

Post 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
User avatar
Forboding Angel
Evolution RTS Developer
Posts: 14638
Joined: 17 Nov 2005, 02:43

Re: Area Mex gadget support for multiple mexes

Post 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
Post Reply

Return to “Lua Scripts”

cron