• 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 Npc "hi" by storage restriction.

nefinoo

Carnage.flv
Joined
Sep 11, 2010
Messages
549
Solutions
1
Reaction score
58
Location
Lo Mochis, Sinaloa
How can I make the player need the storage X > X number, to be able to trade with it
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
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)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkState = {}
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local moeda = 12543
local t = {
      [12396] = {price = 400},
      [12575] = {price = 400},
      [7440] = {price = 200},
      [7443] = {price = 400},
      [8981] = {price = 600},
      [5468] = {price = 250},   
      [2346] = {price = 200}
    }
      
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
  local player = Player(cid)

    if  t[item] and not player:removeItem(moeda, t[item].price) then
          selfSay("Você não tem "..t[item].price.." online tokens.", cid)
             else
        player:addItem(item)
        selfSay("Aqui está.", cid)
       end
    return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') or msgcontains(msg, 'troca') or msgcontains(msg, 'TROCA'))then
            for var, ret in pairs(t) do
                local itemType = ItemType(var)
                local itemName = itemType:getName()
                    table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = itemName})
                end
            openShopWindow(cid, shopWindow, onBuy, onSell)
            end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Solution
@nefinoo

After:
Lua:
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') or msgcontains(msg, 'troca') or msgcontains(msg, 'TROCA'))then

Add:
Lua:
if Player(cid):getStorageValue(STORAGE_ID) ~= VALUE then
selfSay("Desculpe, mas não há nada para negociarmos!")
else

And an end after:
Lua:
            openShopWindow(cid, shopWindow, onBuy, onSell)

Change STORAGE_ID to storage number and VALUE to storage value(1 or 2 or 3...)
@nefinoo

After:
Lua:
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') or msgcontains(msg, 'troca') or msgcontains(msg, 'TROCA'))then

Add:
Lua:
if Player(cid):getStorageValue(STORAGE_ID) ~= VALUE then
selfSay("Desculpe, mas não há nada para negociarmos!")
else

And an end after:
Lua:
            openShopWindow(cid, shopWindow, onBuy, onSell)

Change STORAGE_ID to storage number and VALUE to storage value(1 or 2 or 3...)
 
Last edited:
Solution
@nefinoo

After:
Lua:
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE') or msgcontains(msg, 'troca') or msgcontains(msg, 'TROCA'))then

Add:
Lua:
if player:getStorageValue(STORAGE_ID) ~= VALUE then
selfSay("Desculpe, mas não há nada para negociarmos!")
else

And an end after:
Lua:
            openShopWindow(cid, shopWindow, onBuy, onSell)

Change STORAGE_ID to storage number and VALUE to storage value(1 or 2 or 3...)
Code:
Lua Script Error: [Npc interface]
data/npc/scripts/corium.lua:onCreatureSay
data/npc/scripts/corium.lua:40: attempt to index global 'player' (a nil value)
stack traceback:
        data/npc/scripts/corium.lua:40: in function 'callback'
        data/npc/lib/npcsystem/npchandler.lua:411: in function 'onCreatureSay'
        data/npc/scripts/corium.lua:7: in function <data/npc/scripts/corium.lua:7>
 
Back
Top