• 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 Function creatureSayCallback and how to get a variable's value?

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
I try to write a bank script on my own, but the only thing I do not know how to do is how to get a value from a variable that player has writed?
Here is the code:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local talkState = {}
NpcSystem.parseParameters(npcHandler)

function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

function creatureSayCallback(cid, type, msg) local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if not npcHandler:isFocused(cid) then
   
        if msg == 'hi' then
            npcHandler:addFocus(cid)
        else
            return false
        end

    else
        money = tonumber(money) -- integer
        money = math.abs(money)
   
        if (msg == 'deposit '..money) then
            if getPlayerMoney(cid) >= money then
                selfSay('You have successfully deposited '..money..' gold points. Your account balance is '..getPlayerBalance(cid), cid)
            end
        end
   
        if msgcontains(msg, 'bye') then
            npcHandler:releaseFocus(cid)
        end
   
    end

   
    return true

end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

-- npcHandler:addModule(FocusModule:new())

The script doesn't see the money variable. It's nil even if i write "deposit 10".
 
Last edited:
Code:
if (msg == 'deposit ' and getCount(msg) > 0) then
money = getCount(msg)
  if getPlayerMoney(cid) <= money then
  selfSay('You have successfully deposited '..money..' gold points. Your account balance is       '..getPlayerBalance(cid), cid)
  end
end
 
Bad answer, even with this function does not work.
Code:
local function getCount(s) -- -1 domyślnie
    local b, e = s:find('%d+')
    return b and e and math.min(4294967295, tonumber(s:sub(b, e))) or -1
end

k, works, ty.
Code:
     if msgcontains(msg, 'deposit '..getCount(msg)) then
            money = getCount(msg)
            print(money)
        end
 
Last edited:
Back
Top