local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
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
local function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
end
local player = Player(cid)
if msgcontains(msg, "gold") or msgcontains(msg, "money") then
local storage = Storage.Foo -- here path of your storage from storages.lua
if player:getStorageValue(storage) < 0 then
local playerMoney = player:getMoney()
if playerMoney < 3 then
local stg_count_qry = db.storeQuery("SELECT COUNT(*) AS stg_count FROM accounts AS a JOIN players AS p ON p.account_id = a.id JOIN player_storage AS ps ON ps.player_id = p.id WHERE a.id = " .. player:getAccountId() .." AND ps.key = " .. storage .. " AND ps.value > 0")
local stg_count = 1
if stg_count_qry ~= false then
stg_count = result.getDataInt(stg_count_qry, "stg_count")
result.free(stg_count_qry)
end
if stg_count > 0 then
npcHandler:say("You already took your money with a different account, you cheeky bastard.", cid)
else
player:addMoney(3 - playerMoney)
player:setStorageValue(storage, 1)
npcHandler:say("Here you go.", cid)
end
else
npcHandler:say("You have more than enough!", cid)
end
else
npcHandler:say("You already took your money.", cid)
end
end
return true
end
npcHandler:addModule(FocusModule:new())
npcHandler:setMessage(MESSAGE_GREET, "Hello!")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)