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

[Help] Vendor script

Infectious

CrazY MoroN
Joined
Sep 8, 2007
Messages
16
Reaction score
0
Hi, i've been trying to modify this code:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end

        if msgcontains(msg, 'gear') or msgcontains(msg, 'eq') then
            selfSay('The only thing i give right now is The corrupted sword.  it has 107 attack and 71 defence with a +14 modifier.')
        elseif msgcontains(msg, 'corrupted') or msgcontains(msg, 'sword') or msgcontains(msg, 'corrupted') or msgcontains(msg, 'sword') then
            selfSay('Do you want to bye the corruptors sword? it will cost you 1000 demon dusts and 250 red dragon scales')
            talk_state = 1
        

        elseif msgcontains(msg, 'yes') and talk_state == 1 then
            if getPlayerItemCount(cid,6530) >= 1 and getPlayerItemCount(cid,2152) >= 100 then
                if doPlayerTakeItem(cid,5882,250) and doPlayerTakeItem(cid,5906,1000) == 0 then
                selfSay('Here you are.')
                    doPlayerAddItem(cid,2447,1)
                end
            else
                selfSay('Sorry, you don\'t have the items i want.')
            end
          

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Ok than.')
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

to allow for multiple items for sale, and im getting errors :,(

this is my modified script:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end

        if msgcontains(msg, 'gear') or msgcontains(msg, 'eq') then
            selfSay('The only thing i sell right now is The corrupted sword.  it has 107 attack and 71 defence with a +14 modifier.')
        elseif msgcontains(msg, 'corrupted') or msgcontains(msg, 'sword') or msgcontains(msg, 'corrupted') or msgcontains(msg, 'sword') then
            selfSay('Do you want to buy the corruptors sword? it will cost you 1000 demon dusts and 250 red dragon scales')
            talk_state = 1
        

        elseif msgcontains(msg, 'yes') and talk_state == 1 then
            if getPlayerItemCount(cid,5882) >= 250 and getPlayerItemCount(cid,5906) >= 1000 then
                if doPlayerTakeItem(cid,5882,250) and doPlayerTakeItem(cid,5906,1000) == 0 then
                selfSay('Here you are.')
                    doPlayerAddItem(cid,7407,1)
                end
            else
                selfSay('Sorry, you don\'t have the items i want.')
            end
          

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Ok than.')
            talk_state = 0
        end
        elseif msgcontains(msg, 'oblivion') or msgcontains(msg, 'shield') or msgcontains(msg, 'oblivion') or msgcontains(msg, 'shield') then
            selfSay('Do you want to buy the oblivion shield? it will cost you 850 demon dusts and 200 red dragon scales')
            talk_state = 2
        

        elseif msgcontains(msg, 'yes') and talk_state == 2 then
            if getPlayerItemCount(cid,5882) >= 200 and getPlayerItemCount(cid,5906) >= 850 then
                if doPlayerTakeItem(cid,5882,200) and doPlayerTakeItem(cid,5906,850) == 0 then
                selfSay('Here you are.')
                    doPlayerAddItem(cid,2523,1)
                end
            else
                selfSay('Sorry, you don\'t have the items i want.')
            end
          

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Ok than.')
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/Warefforts2.lua
data/npc/scripts/Warefforts2.lua:40: 'end' expected (to close 'function' at line 12) near 'elseif'
 
I have no idea what's wrong. I've been trying to figure it out, but I can't see anything wrong.. But I'm not a very experienced scripter either.. Sorry.
 
Warning: [NpcScript::NpcScript] Can not load script. data/npc/scripts/Warefforts2.lua
data/npc/scripts/Warefforts2.lua:40: 'end' expected (to close 'function' at line 12) near 'elseif'

That means you need to add end at line 40 in your script.
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

function creatureSayCallback(cid, type, msg)
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so 

you do not have to take care of that yourself.
    if(npcHandler.focus ~= cid) then
        return false
    end

        if msgcontains(msg, 'offer') or msgcontains(msg, 'eq') or msgcontains(msg, 'equipment') then
            selfSay('The things I am selling are the following: the corrupted sword and the oblivion shield. Which one do you want to purchase?')

        elseif msgcontains(msg, 'corrupted') or msgcontains(msg, 'sword') then
            selfSay('This sword have PUT ITS ATTACK HERE :P attack and PUT DEF HERE XD defense, but it will cost you 1000 demon dusts and 250 red dragon scales. Are you still interested?')
            talk_state = 1
        
        elseif msgcontains(msg, 'yes') or msgcontains(msg, 'sure') or msgcontains(msg, 'of course') and talk_state 

== 1 then
		if doPlayerTakeItem(cid,5882,250) and doPlayerTakeItem(cid,5906,1000) == 0 then
                selfSay('Thank you '..getPlayerName(cid)..'! Use this powerful weapon wisely.')
                    doPlayerAddItem(cid, 7407, 1)
            else
                selfSay('Sorry, but you don\'t have the items I want.')
            end
          
        elseif msgcontains(msg, 'no') and talk_state == 1 then
            selfSay('As you wish '..getPlayerName(cid)..'.')
            talk_state = 0

        elseif msgcontains(msg, 'oblivion') or msgcontains(msg, 'shield') then
            selfSay('This shield have PUT DEF HERE x) of defense points and will cost you 200 red dragon scales and 850 demon dusts. Are you interested?')
            talk_state = 2
        

        elseif msgcontains(msg, 'yes') and talk_state == 2 then
                if doPlayerTakeItem(cid,5882,200) and doPlayerTakeItem(cid,5906,850) == 0 then
                selfSay('Thank you!')
                    doPlayerAddItem(cid, 2523, 1)
                end
            else
                selfSay('Come back when you have all items.')
            end
          

        elseif msgcontains(msg, 'no') and talk_state == 2 then
            selfSay('Your bad.')
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so 

you do not have to take care of that yourself.
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

NOT TESTED -> SHOULD WORK :p
 
Last edited:
Back
Top