• 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 Fishermans Friend

Virgel

New Member
Joined
Jun 14, 2007
Messages
150
Reaction score
2
This my NewbieQuest! Peoples need to find 50 worms and bring them to Ned to get a fishing rod for 20gp. Ned buys also worms.

Tested with ForgottenServer 0.2.2

fisherman.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) 
    if(npcHandler.focus ~= cid) then 
        return false 
    end 

if msgcontains(msg, 'quest') or msgcontains(msg, 'quests') or msgcontains(msg, 'mission') or msgcontains(msg, 'worms') or msgcontains(msg, 'rod') or msgcontains(msg, 'fishing rod') then

    if getPlayerStorageValue(cid, 10002) == -1 then
    selfSay('Hey, if you bring me 50 Worms for free i will sell you an fishing rod for 20gp. Is this okay for you?')
    talk_state = 1642

elseif getPlayerStorageValue(cid, 10002) == 1 then
    selfSay('Got 50 worms for me?.')
    talk_state = 1643

elseif getPlayerStorageValue(cid, 10002) == 2 then
    selfSay('Do you wish to buy a fishing rod for 20gp now?')
    talk_state = 1644

elseif getPlayerStorageValue(cid, 10002) == 3 then
    selfSay('I have no fishing rods left sorry.')
    talk_state = 0
end

elseif talk_state == 1642 then
if msgcontains(msg, 'yes') then
    selfSay('Thank you. Please look in you QuestLog for more information.')
    setPlayerStorageValue(cid, 10002, 1)
    
elseif msgcontains(msg, 'no') then
    selfSay('Then not.')
end

elseif talk_state == 1643 then
if msgcontains(msg, 'yes') then
    if getPlayerItemCount(cid,3976) >= 50 then
    doPlayerRemoveItem(cid, 3976, 50)
    selfSay('Thank you. I will sell you 1 fishing rod for 20gp.')
    setPlayerStorageValue(cid, 10002, 2)

    else
    selfSay('Sorry, you dont have so many.')
    end
    
elseif msgcontains(msg, 'no') then
    selfSay('Maybe later.')
end
elseif talk_state == 1644 then
if msgcontains(msg, 'yes') then
    if doPlayerRemoveMoney(cid, 20) then
        doPlayerAddItem(cid, 2580, 1)
            selfSay('Here you are!.')
            setPlayerStorageValue(cid, 10002, 3)
    else
    selfSay('Sorry, you dont have enough money.')
    end
    
elseif msgcontains(msg, 'no') then
    selfSay('Maybe later.')
end
talk_state = 0
end
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
ned.xml
Code:
<npc name="Ned" script="data/npc/scripts/fisherman.lua" autowalk="25" floorchange="0" access="5" level="1" maglevel="1">
    <health now="150" max="150"/>
    <look type="128" head="20" body="30" legs="40" feet="50" addons="0"/>
    <parameters>
        <parameter key="module_shop" value="1" />
        <parameter key="message_greet" value="Hello |PLAYERNAME|. I sell fishing rods(150gp) and i buy worms(1gp)." />
        <parameter key="shop_sellable" value="worm,3976,1" />
        <parameter key="shop_buyable" value="fishing rod,2580,150" />
    </parameters>
</npc>
inXML/quests.xml add this
Code:
    <quest name="A favour for a fishing rod[LvL1]" startstorageid="10002" startstoragevalue="1"> 
        <mission name="Bring Ned 50 Worms" storageid="10002" startvalue="1" endvalue="3"> 
            <missionstate id="1" description="Ned is a fisherman, but hes out of worms. If you bring him 50 worms he will sell you a fishing rod for 20gp." /> 
            <missionstate id="2" description="Ned was very happy about your help. You can now buy the fishing rod for 20gp. " /> 
            <missionstate id="3" description="Mission Completed." /> 
        </mission> 
    </quest>
i hope you like it :)

thx you and farewell Virgel
 
Last edited by a moderator:
<missionstate id="2" description="Nes was very happy about your help. You can now buy the fishing rod for 20gp. " />

I like to read this lua scripts carefuly and you should replace Ne"s" for "Ne"d"

it says... Nes was very... bla bla bla, and i think it should be Ned...

neways nice work
 
Belony said:
<missionstate id="2" description="Nes was very happy about your help. You can now buy the fishing rod for 20gp. " />

I like to read this lua scripts carefuly and you should replace Ne"s" for "Ne"d"

it says... Nes was very... bla bla bla, and i think it should be Ned...

neways nice work

done :)
 
Hehe nice i totaly forgot there is an quest.xml to.. i'm going to add this script (change it an bit) and add more quests to my quest.xml
 
thx

Thank you. It really help me to understand LUA NPC scripts. Now i can make my own advanced quests (not stupid open box and get item)!
:p
REP+ :)
 
Back
Top