TalkactionHandler = {}
function TalkactionHandler:new(command)
local obj = {}
self.__index = self
obj.command = command
obj.params = {}
setmetatable(obj,self)
return obj
end
function TalkactionHandler:addParam(param,neededparams, callback) --arg means additional arguments here.
--lets assume callback gets all parameters given by onSay
self.params[param].callback = callback
self.params[param].neededparams = neededparams
end
function TalkactionHandler:execute(cid, words, param, channel)
local s = string.explode(param, ",")
if table.maxv(s) < self.params[s[1]].neededparams then
doPlayerSendCancel(cid,"You need "..self.params[s[1]].neededparams.." parameters."
return false
end
self.params[s[1]].callback(cid,words,param,channel, s) --Execute added parameter and params
end
--Sample command
Multicomand = TalkactionHandler:new("/mycoand")
Multicomand:addParam("money", 1, function(cid, words, param, channel, parsedparams)
doCreatureSay(cid," I was given with 100cc",1)
end)
Multicomand:addParam("die",2, function(cid, words, param, channel, parsedparams)
doCreatureSay(cid," I wanna kill player with name "..parsedparams[2],1)
end)
function onSay(cid, words, param, channel)
Multicomand:execute(cid, words, param, channel)
end