quote: I know how you feel. That's why I am working on developing a widget that will turn input such as |
This will probably help you a lot. You could do:
[quote]
local units = {}
for id,data in pairs(UnitDefs) do
units[string.lower(data.humanname)] = data.name
end -- Reverse lookup
function widget:GotChatMsg(msg, player)
if string.find(string.lower(msg),"givee") ~= nil and player == Spring.GetMyPlayerID() then -- done on purpose so we don't trigger give.
local command = string.gmatch(msg, "%S+") -- Split string into pieces. "/givee 1 glaive 1" results in {"/givee","1","glaive","1"}
local unit = ""
for i=1,#command do
if string.find(command[i],"give") == nil and string.len(command[i]) > 3 then
unit = command[i]
break
end
end
if units[unit] == nil then
Spring.Echo("game_message:Invalid unit! Check spelling!")
end
local str
--reform command--
for i=1,#command do
if string.find(command[i],"givee") == nil then
str = str .. command[i]
else
str = str .. "give"
end
Spring.SendCommands(str)
str,command = nil
end
[/quote]
Other useful links:
Spring Callins ("events") and what they doSpring LUA functions