• 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!

NPC selling items in say not trade window

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
Hey, im looking for script to npc, for selling items in say not in trade window
sample:

Player: Hi
NPC: Hi, i can sell you TEST AMULET for 10 GI, TEST RING for 10 GI, TEST SWORD for 25 GI, do you wanna buy something?
Player: TEST RING
NPC: Are you sure, you want buy TEST RING for 10 GI?
Player: yes

Someone has it or know where i can get this script?
 
That sounds like basically every NPC ever before the introduction of the shop window.
Just look up like... 8 years old scripts and you'll see how they were made.
 
Okay, i did it, if someone need same script here is it:
(i don't know it's good or no, but it working in my server, but if someone check it im be so grateful

Code:
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 voices = {{text = "Hey! I have items for you!"}}
npcHandler:addModule(VoiceModule:new(voices))

local function greetCallback(cid)
    local player = Player(cid)
    player:setStorageValue(399399, 0)
    return true
end

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "test ring") then
        npcHandler:say("Do you want buy test ring for 10 GI?", cid)
        player:setStorageValue(399399, 1)
    end

    if msgcontains(msg, "yes") and player:getStorageValue(399399) == 1 then
        if player:removeMoney(10000000) then
            npcHandler:say("Nice, there is your test ring! Have a good day!", cid)
            player:addItem(2376, 1, true, 500)
            player:setStorageValue(399399, 0)
        else
            npcHandler:say("You don\'t have enough money!", cid)
            player:setStorageValue(399399, 0)
        end
    end

    if msgcontains(msg, "no") then
        npcHandler:say("Ok.", cid)
        player:setStorageValue(399399, 0)
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. I have items for you, check it:\n>> {Test Ring} for 10 GI')
npcHandler:addModule(FocusModule:new())
 
Okay, i did it, if someone need same script here is it:
(i don't know it's good or no, but it working in my server, but if someone check it im be so grateful

Code:
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 voices = {{text = "Hey! I have items for you!"}}
npcHandler:addModule(VoiceModule:new(voices))

local function greetCallback(cid)
    local player = Player(cid)
    player:setStorageValue(399399, 0)
    return true
end

local function creatureSayCallback(cid, type, msg)
    local player = Player(cid)
    if not npcHandler:isFocused(cid) then
        return false
    end

    if msgcontains(msg, "test ring") then
        npcHandler:say("Do you want buy test ring for 10 GI?", cid)
        player:setStorageValue(399399, 1)
    end

    if msgcontains(msg, "yes") and player:getStorageValue(399399) == 1 then
        if player:removeMoney(10000000) then
            npcHandler:say("Nice, there is your test ring! Have a good day!", cid)
            player:addItem(2376, 1, true, 500)
            player:setStorageValue(399399, 0)
        else
            npcHandler:say("You don\'t have enough money!", cid)
            player:setStorageValue(399399, 0)
        end
    end

    if msgcontains(msg, "no") then
        npcHandler:say("Ok.", cid)
        player:setStorageValue(399399, 0)
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. I have items for you, check it:\n>> {Test Ring} for 10 GI')
npcHandler:addModule(FocusModule:new())
Why in your script you check for storage? 399399
 
@vexler222
You should use some IDE to edit .lua files (IDEA CE or VisualCode). They have auto code formatting.
If you prefer to use text editor, you can use Lua Beautifier - Best Lua Beautifier (https://goonlinetools.com/lua-beautifier/) to format code.

Your code before formatting:
Lua:
   if player:getStorageValue(storageOne) == 1 then
        if player:getStorageValue(language_storage) == 0 then
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
            toPosition:sendMagicEffect(10)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
            toPosition:sendMagicEffect(10)
       return true
   end
end

Your code after formatting:
Lua:
if player:getStorageValue(storageOne) == 1 then
    if player:getStorageValue(language_storage) == 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Pusto.")
        toPosition:sendMagicEffect(10)
    else
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Empty.")
        toPosition:sendMagicEffect(10)
        return true
    end
end
With proper indentation, it's much easier to find what is wrong with IFs.

Why in your script you check for storage? 399399

Because I do not know how to make to, after writing test ring and yes, npc selling the ring and not another item, so I added storage checking, if the player type test ring he will be given a storge 399399 with a value of 1, and so with the next items got value 2, 3 ..
 
Lua:
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 voices = {{text = "Hey! I have items for you!"}}
npcHandler:addModule(VoiceModule:new(voices))

local function greetCallback(cid)
    npcHandler.topic[cid] = 0
    return true
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if msgcontains(msg, "test ring") then
        npcHandler:say("Do you want buy test ring for 10 GI?", cid)
        npcHandler.topic[cid] = 1
    end
    if msgcontains(msg, "yes") and npcHandler.topic[cid] == 1 then
        if player:removeMoney(10000000) then
            npcHandler:say("Nice, there is your test ring! Have a good day!", cid)
            player:addItem(2376, 1, true, 500)
            npcHandler.topic[cid] = 0
        else
            npcHandler:say("You don\'t have enough money!", cid)
            npcHandler.topic[cid] = 0
        end
    end
    if msgcontains(msg, "no") and npcHandler.topic[cid] >= 1 then
        npcHandler:say("Ok.", cid)
        npcHandler.topic[cid] = 0
    end
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|. I have items for you, check it:\n>> {Test Ring} for 10 GI')
npcHandler:addModule(FocusModule:new())[CODE]

As Evil Puncker told.
 
Back
Top