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

TFS 0.X npc doplayerAddItems

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello guys i use 0.4
i found this npc here
but i need to add items not premium days
my script look like
Lua:
    if msgcontains(msg, "demon horn") and talkState[talkUser] == 2 then
            selfSay('Tell me how much you would like to purchase?', cid)
        talkState[talkUser] = 29

  elseif talkState[talkUser] == 29 and temp ~= nil and temp > 0 then
    selfSay(" " .. msg .. " demon horn will cost you " .. msg*5 .. " power Tokens Do you agree?", cid)
        xmsg[cid] = msg
        talkState[talkUser] = 30


  elseif talkState[talkUser] == 30 and msgcontains(msg, "yes") then
        local tempCount = tonumber(xmsg[cid])
        if getPlayerItemCount(cid, 12372) >= tempCount*5  then
if doPlayerRemoveItem(cid,12372, tempCount*5) == TRUE then
            doPlayerAddItem(cid, 12469, tempCount)
            selfSay("Here you go!", cid)
            end
        else
            selfSay("You don't have enough tokens for " .. xmsg[cid] .. " demon horn.", cid)
            talkState[talkUser] = 0   
    
  end
when tell npc 5 npc add just one demon horn not 5
 
Try use this model:


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 item = 'I\'m sorry, but you do not have the required items for this trade.'
local done = 'Here you are, thank you for your business.'

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if msgcontains(msg, 'items') then
        npcHandler:say('You can here change some items for {spider silk yarn}, {chunk of crude iron}, {draconian steel}, {warrior\'s sweat}, {magic sulphur}, {enchanted chicken wing}, {royal steel}, {hell steel}, {fighting spirit}, {infernal bolts} and {koshei\'s amulet}.', cid)
    elseif msgcontains(msg, 'spider silk yarn') then
        if getPlayerItemCount(cid,5879) >= 10 then
            npcHandler:say('Did you bring me the 10 Giant Spider Silks?', cid)
            talk_state = 1
        else
            npcHandler:say('I need a {10 Giant Spider Silks}, to give you one spider silk yarn. Please come back when you have them.', cid)
            talk_state = 1
        end
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
        talk_state = 1
        if getPlayerItemCount(cid,5879) >= 10 then
            if doPlayerRemoveItem(cid,5879, 10) == TRUE then
                npcHandler:say(done, cid)
                doPlayerAddItem(cid, 5886, 1)
            end
        else
            npcHandler:say(item, cid)
        end
    elseif msgcontains(msg, 'chunk of crude iron') then
        if getPlayerItemCount(cid,2393) >= 1 then
            npcHandler:say('Did you bring me the Giant Sword ?', cid)
            talk_state = 2
        else
            npcHandler:say('I need a {Giant Sword}, to give you the chunk of crude iron. Come back when you have it.', cid)
            talk_state = 2
        end
    elseif msgcontains(msg, 'yes') and talk_state == 2 then
        talk_state = 2
        if getPlayerItemCount(cid,2393) >= 1 then
            if doPlayerRemoveItem(cid,2393,1) == TRUE then
                npcHandler:say(done, cid)
                doPlayerAddItem(cid,5892,1)
            end
        else
            npcHandler:say(item, cid)
        end
            return true
end

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

For each item added, you change the talk state = x
 
Try use this model:


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 item = 'I\'m sorry, but you do not have the required items for this trade.'
local done = 'Here you are, thank you for your business.'

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    if msgcontains(msg, 'items') then
        npcHandler:say('You can here change some items for {spider silk yarn}, {chunk of crude iron}, {draconian steel}, {warrior\'s sweat}, {magic sulphur}, {enchanted chicken wing}, {royal steel}, {hell steel}, {fighting spirit}, {infernal bolts} and {koshei\'s amulet}.', cid)
    elseif msgcontains(msg, 'spider silk yarn') then
        if getPlayerItemCount(cid,5879) >= 10 then
            npcHandler:say('Did you bring me the 10 Giant Spider Silks?', cid)
            talk_state = 1
        else
            npcHandler:say('I need a {10 Giant Spider Silks}, to give you one spider silk yarn. Please come back when you have them.', cid)
            talk_state = 1
        end
    elseif msgcontains(msg, 'yes') and talk_state == 1 then
        talk_state = 1
        if getPlayerItemCount(cid,5879) >= 10 then
            if doPlayerRemoveItem(cid,5879, 10) == TRUE then
                npcHandler:say(done, cid)
                doPlayerAddItem(cid, 5886, 1)
            end
        else
            npcHandler:say(item, cid)
        end
    elseif msgcontains(msg, 'chunk of crude iron') then
        if getPlayerItemCount(cid,2393) >= 1 then
            npcHandler:say('Did you bring me the Giant Sword ?', cid)
            talk_state = 2
        else
            npcHandler:say('I need a {Giant Sword}, to give you the chunk of crude iron. Come back when you have it.', cid)
            talk_state = 2
        end
    elseif msgcontains(msg, 'yes') and talk_state == 2 then
        talk_state = 2
        if getPlayerItemCount(cid,2393) >= 1 then
            if doPlayerRemoveItem(cid,2393,1) == TRUE then
                npcHandler:say(done, cid)
                doPlayerAddItem(cid,5892,1)
            end
        else
            npcHandler:say(item, cid)
        end
            return true
end

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

For each item added, you change the talk state = x
so no way to make like i want ?
 
My English is very bad then use or translator XDDDDDD

Would you be able to summarize in detail what you need?
Post automatically merged:

What items do you want to exchange?
What quantities?
 
It would be necessary to see the entire script to evaluate.
Anyway, the script that sends it does the same thing and is 100%.
Just replace the exchange and reward ids.
 
Back
Top