Joined: 22 Feb 2006, 01:02 Location: cheap kitchen
UnitDefs table is read only.
save original speed & turnrate: local mt = Spring.GetUnitMoveTypeData(unitID) local originalspeed = mt.maxSpeed local originalturnrate = mt.turnRate
make immobile: Spring.MoveCtrl.SetGroundMoveTypeData(unitID, "maxSpeed", 0) Spring.MoveCtrl.SetGroundMoveTypeData(unitID, "turnRate",0)
make mobile again: Spring.MoveCtrl.SetGroundMoveTypeData(unitID, "maxSpeed", originalspeed) Spring.MoveCtrl.SetGroundMoveTypeData(unitID, "turnRate",originalturnrate)
0 = in 0.82.7 this worked. In 85.0 it gets you the message: "Warning: Can not assign key "maxSpeed" to GroundMoveType" (it will work though, so that warning is imo a bug) Setting to 0.01 is almost the same as 0 and works without warning.
This is exactly what I need. I tried the following just to test it. I can get the movement values, but an error occurs when the set is called. The error states "attempted to index field 'MoveCtrl' (a nil value)"
for id,unitDef in ipairs(Spring.GetSelectedUnits()) do local mt = Spring.GetUnitMoveTypeData(unitDef) local originalspeed = mt.maxSpeed local originalturnrate = mt.turnRate
Spring.Echo("maxSpeed: "..originalspeed)
Spring.MoveCtrl.SetGroundMoveTypeData(unitDef, "maxSpeed", 0.01) Spring.MoveCtrl.SetGroundMoveTypeData(unitDef, "turnRate",0.01) end
I tried to use both id and unitDef from the Spring.GetSelectedUnits() and only unitDef worked with the getter.
Even if it did work, you would still be in lua "widget space". You want to have widget -> gadget communication (not sure if it can go both ways). You do that by sending messages, f.e : --widget code
Code:
Spring.SendLuaRulesMsg("scenedit|addUnit|" .. unitDef .. "|" .. x .. "|" .. y .. "|" .. z .. "|" .. playerId)
--gadget code
Code:
function gadget:RecvLuaMsg(msg, playerID) pre = "scenedit" --if (msg:find(pre,1,true)) then Spring.Echo ("its a loveNtrolls message") end local data = explode( '|', msg)
if data[1] ~= pre then return end --make sure it's from your widget -- rest of your code end
Now remember when you do stuff in your gadget, it may not be possible to do it in the RecvLuaMsg function (the Gods of Olymp disagree), so you may need to delay the call, f.e:
I am getting a "[string "LuaRules/Gadgets/modifyunitattributes.lua"]:107: Unit does not have a compatible MoveType" error in the gadget when I try to call:
Users browsing this forum: No registered users and 1 guest
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum