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

Need npc in TFS 0.3 rev. 902

sonanuca

New Member
Joined
Jan 20, 2008
Messages
26
Reaction score
0
I need one npc that he changes an item for another item.

Exemple: a fire sword for 5 ham

i give 5 ham and get a fire sword
 
Here you go,

In npc/scripts/hamforsword.lua:
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, 'trade') or msgcontains(msg, 'ham') or msgcontains(msg, 'fire sword') or msgcontains(msg, 'sword') then
            selfSay('Would you like to trade 5 ham for my firesword?')
            talk_state = 1
 
 
        elseif msgcontains(msg, 'yes') and talk_state == 1 then
            if getPlayerItemCount(cid,[color=blue]2671)[/color] >= 5 then
                if doPlayerTakeItem(cid,[color=blue]2671[/color],5) == 1 then
                    selfSay('Here you are.')
                    doPlayerAddItem(cid,[color=red]2392[/color],1)
                end
            else
                selfSay('Sorry, you don\'t have the item.')
            end
 
 
        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Ok then.')
            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())

The NPC:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Kyle" script="data/npc/scripts/hamforsword.lua" autowalk="1" floorchange="0">
	<health now="100" max="100"/>
	<look type="63" head="20" body="39" legs="45" feet="7" addons="0"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I can give you a firesword for 5 pieces of ham." />
</parameters>
</npc>

Let me know if it works,
Pazzur
 
Code:
        elseif msgcontains(msg, 'yes') and talk_state == 1 then
            [b]if getPlayerItemCount(cid,2671) >= 5 then[/b]
                if doPlayerTakeItem(cid,2671,5) == 1 then
                    selfSay('Here you are.')
                    doPlayerAddItem(cid,2392,1)
                end
            else
                selfSay('Sorry, you don\'t have the item.')
            end

The bold check is not needed, can be like this (shorteeerr :p):
Code:
elseif msgcontains(msg, 'yes') and talk_state == 1 then
    if doPlayerTakeItem(cid,2671,5) == 1 then
        selfSay('Here you are.')
        doPlayerAddItem(cid,2392,1)
        talk_state = 0
    else
        selfSay('Sorry, you don\'t have the item.')
        talk_state = 0
    end

+ added reseting talk_state.
 
Back
Top