• 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 Soft Boots Repair NPC

kokorec

Tavon Online - Soon
Joined
May 3, 2008
Messages
287
Reaction score
0
Location
Turkey
Hi,
Here is my soft boots repair npc.it is work perfectly.

data>npc>scripts>name.lua

name.lua

Code:
local focus = 0
local talk_start = 0
local target = 0
local following = false
local attacking = false

function onThingMove(creature, thing, oldpos, oldstackpos)

end


function onCreatureAppear(creature)

end


function onCreatureDisappear(cid, pos)
  	if focus == cid then
          selfSay('Good bye then.')
          focus = 0
          talk_start = 0
  	end
end


function onCreatureTurn(creature)

end


function msgcontains(txt, str)
  	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

function onCreatureSay(cid, type, msg)
  	msg = string.lower(msg)

if (msgcontains(msg, 'hi') and focus == 0) and getDistanceToCreature(cid) < 4 then
selfSay('Hello ' .. getCreatureName(cid) .. '! I Repair "Soft Boots" for 10k.')
focus = cid
talk_start = os.clock()

elseif msgcontains(msg, 'hi') and (focus ~= cid) and getDistanceToCreature(cid) < 4 then
selfSay('Sorry, ' .. getCreatureName(cid) .. '! I talk with you in one minute.')


elseif msgcontains(msg, 'soft boots') then
selfSay('Do you really want repair your Soft Boots for 10k?')
talk_state = 1
talk_start = os.clock()

elseif talk_state == 1 and msgcontains(msg, 'yes') then
if getPlayerItemCount(cid,6530) >= 1 and getPlayerItemCount(cid,2160) >= 1 then
if doPlayerRemoveItem(cid,6530,1) and doPlayerRemoveItem(cid,2160,1) then
selfSay('Owned! Here its your Soft Boots.')
doPlayerAddItem(cid,6132,1)
end
else
selfSay('Sorry, you don't have enough money!')
end


        elseif msgcontains(msg, 'bye') and getDistanceToCreature(cid) < 4 then
            selfSay('Bye ' .. getCreatureName(cid) .. ', Come back.')
            focus = 0
            talk_start = 0

    elseif msgcontains(msg, 'kashfeioyorgheklçguyio') then
            selfSay('What?')
            talk_state = 0
        end
end

function onCreatureChangeOutfit(creature)
end

function onThink()
    doNpcSetCreatureFocus(focus)
    if (os.clock() - talk_start) > 30 then
        if focus > 0 then
            selfSay('Next...')
        end
        focus = 0
        talk_start = 0
    end
    if focus ~= 0 then
        if getDistanceToCreature(focus) > 5 then
            selfSay('Good Bye')
            focus = 0
            talk_start = 0
        end
    end
end

data>npc>yourname.xml

yourname.xml

Code:
<npc name=[COLOR="Red"]"Yourname[/COLOR]" script="data/npc/scripts/[COLOR="Red"]name.lua[/COLOR]" floorchange="0" walkinterval="25" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
        <look type="146" head="114" body="88" legs="88" feet="0" addons="3" corpse="2212"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|. i am specialised in boots" />		
	</parameters>
</npc>

You change with red colours words.

Thanks.
 
nice script, tks

edit : just 1 little bug. at line 59 => selfSay('Sorry, you don't have enough money!')


the ' of don't make the script end in middle of sentence :eek:... i guess theres a code to remplace it but i dunno it :p
 
Last edited:
@cire;

Why not use TFS default one?
Code:
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'soft') or msgcontains(msg, 'boots')) then
		selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 6530) >= 1) then
			if(doPlayerRemoveMoney(cid, 10000) == TRUE) then
				doPlayerRemoveItem(cid, 6530, 1)
				doPlayerAddItem(cid, 2640)
				selfSay('Here you are.', cid)
			else
				selfSay('Sorry, you don\'t have enough gold.', cid)
			end
		else
			selfSay('Sorry, you don\'t have the item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

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

... and about the bug:
selfSay('Sorry, you don't have enough money!') -> selfSay("Sorry, you don't have enough money!")
 
ye tfs have default npc for that. But anyway thx for script.
It working fine.

The one who dont know just delete the ' by don't at line 59
 
@cire;

Why not use TFS default one?
Code:
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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'soft') or msgcontains(msg, 'boots')) then
        selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerItemCount(cid, 6530) >= 1) then
            if(doPlayerRemoveMoney(cid, 10000) == TRUE) then
                doPlayerRemoveItem(cid, 6530, 1)
                doPlayerAddItem(cid, 2640)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        else
            selfSay('Sorry, you don\'t have the item.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    return true
end

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

... and about the bug:
selfSay('Sorry, you don't have enough money!') -> selfSay("Sorry, you don't have enough money!")
This work great! :)
 
I managed to import the npc into editor but doesn't appear in my server. What am I missing?



XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Bootsy" script="bootsy.lua" walkinterval="2000" floorchange="0">
    <health now="150" max="150" />
    <look type="146" head="114" body="88" legs="88" feet="0" addons="3" />
</npc>

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'soft') or msgcontains(msg, 'boots')) then
        selfSay('Do you want to repair your worn soft boots for 20000 gold coins?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerItemCount(cid, 6530) >= 1) then
            if(doPlayerRemoveMoney(cid, 20000) == TRUE) then
                doPlayerRemoveItem(cid, 6530, 1)
                doPlayerAddItem(cid, 2640)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        else
            selfSay('Sorry, you don\'t have the item.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I managed to import the npc into editor but doesn't appear in my server. What am I missing?



XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Bootsy" script="bootsy.lua" walkinterval="2000" floorchange="0">
    <health now="150" max="150" />
    <look type="146" head="114" body="88" legs="88" feet="0" addons="3" />
</npc>

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 talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if(msgcontains(msg, 'soft') or msgcontains(msg, 'boots')) then
        selfSay('Do you want to repair your worn soft boots for 20000 gold coins?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerItemCount(cid, 6530) >= 1) then
            if(doPlayerRemoveMoney(cid, 20000) == TRUE) then
                doPlayerRemoveItem(cid, 6530, 1)
                doPlayerAddItem(cid, 2640)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        else
            selfSay('Sorry, you don\'t have the item.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Remove the : in the first line of your npc.lua.
 
Back
Top