• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Talkaction with 2 param.

scorpionfight

New Member
Joined
Sep 21, 2008
Messages
111
Reaction score
1
Location
Brazil
Hi, I trying to make a simple talkaction with 2 params, like: !talkaction param1, param2(ex: !talkaction x, 5 or !talkaction x, bla).
And use the number/string(param2) in a variable, like: variable = param2.


But how I can do that?
 
Look this script and what lines have.. params
Lua:
local config = {
fireCost = 10000,
softCost = 10000
}

function onSay(cid, words, param, channel)

    if param == "!recharge" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param! (soft or fire).")
        return TRUE
    end
    
    if param == "soft" then
        if getPlayerItemCount(cid, 6530) >= 1 then
            if doPlayerRemoveMoney(cid, config.softCost) then
                doPlayerRemoveItem(cid, 10021, 1)
                doPlayerAddItem(cid, 6132, 1, FALSE)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recharged your soft boots for "..config.softCost.." coins.")
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need "..config.fireCost.." coins to recharge your soft boots.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need a worn soft boots to recharge it.")
        end
    elseif param == "fire" then        
        if getPlayerItemCount(cid, 9934) >= 1 then
            if doPlayerRemoveMoney(cid, config.fireCost) then
                doPlayerRemoveItem(cid, 10022, 1)
                doPlayerAddItem(cid, 9933, 1, FALSE)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recharged your firewalker boots for "..config.fireCost.." coins.")
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need "..config.fireCost.." coins to recharge your firewalker boots.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need a worn firewalker boots to recharge it.")
        end
    end    
            
    return TRUE
    
end

Lua:
end
    elseif param == "fire" then
 
Look this script and what lines have.. params
Lua:
local config = {
fireCost = 10000,
softCost = 10000
}

function onSay(cid, words, param, channel)

    if param == "!recharge" then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid param! (soft or fire).")
        return TRUE
    end
    
    if param == "soft" then
        if getPlayerItemCount(cid, 6530) >= 1 then
            if doPlayerRemoveMoney(cid, config.softCost) then
                doPlayerRemoveItem(cid, 10021, 1)
                doPlayerAddItem(cid, 6132, 1, FALSE)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recharged your soft boots for "..config.softCost.." coins.")
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need "..config.fireCost.." coins to recharge your soft boots.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need a worn soft boots to recharge it.")
        end
    elseif param == "fire" then        
        if getPlayerItemCount(cid, 9934) >= 1 then
            if doPlayerRemoveMoney(cid, config.fireCost) then
                doPlayerRemoveItem(cid, 10022, 1)
                doPlayerAddItem(cid, 9933, 1, FALSE)
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recharged your firewalker boots for "..config.fireCost.." coins.")
            else
                doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need "..config.fireCost.." coins to recharge your firewalker boots.")
            end
        else
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need a worn firewalker boots to recharge it.")
        end
    end    
            
    return TRUE
    
end

Lua:
end
    elseif param == "fire" then

Re-read the thread.

It's simple just do something like
Lua:
local a = 0
local b = string.explode(param, ',') --the comma is the separator of the params.
a = b[2]
where b[1] is param 1 and b[2] is param 2
 
I would preferto use something like class to make talkactions lets say something like this.

Code:
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

Untested though here is general idea, in my opinion it keeps files more clear and organized.
 
Thank you, guys.

But how I can set for the param[2] must be only words not numbers, its anything like that?
Lua:
local a = 0
local b = string.explode(param, ',') --the comma is the separator of the params.
a = b[2]

if b[2] ~= string then
return doPlayerSendCancel(cid, 'Invalid parameters.')
	end

And its possible to make the string contain no more than 10 letters?
 
Last edited:
Back
Top Bottom