• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Simple Npc's Quest

iruga

#S¥Ơ'..
Joined
May 18, 2009
Messages
371
Reaction score
4
Location
Brazil
This is one npc of guardian training room, you need complete the mission for use the training's room. ^_^

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, 'mission') then
	if getPlayerStorageValue(cid, 30045) == -1 then
		npcHandler:say('I lost my baby seal dool in my home, can you help me the found dool?', cid)
		talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, 30046) == 1 then
                npcHandler:say('Own. you have a baby seal from me?', cid)
                talkState[talkUser] = 2
        elseif getPlayerStorageValue(cid, 30046) == 2 then
                npcHandler:say('Sorry...but you already have complete my service. Good Bye', cid)
                talkState[talkUser] = 3
        end
        
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Great. you have acess to enter in my home, report your mission afterwards..', cid)
                setPlayerStorageValue(cid,30045,1)
		        local chave = doCreateItemEx(2092, 1)
		        doSetItemActionId(chave, 4849)
		        doPlayerAddItemEx(cid, chave, 1)
                talkState[talkUser] = 2
                else
                selfSay('You already have the service. Come back have them...', cid)
        end

    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Thank you! now you have acess to enter in my Training Room.', cid)
	            if doPlayerRemoveItem(cid,7183,1) == TRUE then
                setPlayerStorageValue(cid,30046,2)
                setPlayerStorageValue(cid,60034,1)
                talkState[talkUser] = 3
                else
                npcHandler:say('Sorry...but you dont have item. Come back have them', cid)
            end
            end
            end
    return true
end

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


This is one simple mission of PostmanQuest, I need help for to grow the script to let it equal to RL. I could not for more than 3 talkstate without the bug between missions.

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, 'mission') then
	if getPlayerStorageValue(cid, 30120) == -1 then
		npcHandler:say('I have many missions for the postman quest..you can help me?', cid)
		talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, 30121) == 1 then
                npcHandler:say('Own..you have my feedback?!', cid)
                talkState[talkUser] = 2
        elseif getPlayerStorageValue(cid, 30121) == 2 then
                npcHandler:say('Sorry...but you already have complete my service.', cid)
                talkState[talkUser] = 3
        end
        
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Great...delivery this letter for my girlfriend in depot of Name your City.', cid)
                doPlayerAddItem(cid,2333,1)
                setPlayerStorageValue(cid,30120,1)
                talkState[talkUser] = 2
                else
                selfSay('You already have the delivery...Come back have them...', cid)
        end

    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Thanks officer! Now you have the acess to enter in MailBox Room\'s...Remember in future come here for more missions to have discount buying parcel and letters.', cid)
	            if doPlayerRemoveItem(cid,2665,1) == TRUE then
                setPlayerStorageValue(cid,30121,2)
                setPlayerStorageValue(cid,60035,1)
                talkState[talkUser] = 3
                else
                npcHandler:say('Sorry...but you dont have item. Come back have them', cid)
            end
            end
            end
    return true
end

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

I am accepting help fix some errors that the script has it. :thumbup:
 
@up

Oh! finally someone said here ... Thank you and if you can help improve the script, I am accepting. :D
 
Thanks for base script - I can use for some of my NPCs

Question: How would I make it so I can do mission and trade with him...
 
@up and the missions work in tfs 0.3.5.

Oh man, do not really understand your question, the more I try to solve.
Here is an example, the NPC of parcel with the mission of the postman.


Here the npc for quest and buy parcel's and letter. "npc.xml"

Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Junior" script="data/npc/scripts/postmanquest.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="132" head="58" body="114" legs="78" feet="0" addons="1"/>
	<parameters>
		<parameter key="module_shop" value="1"/>
		<parameter key="message_greet" value="Welcome, |PLAYERNAME|! Say {trade} and I can help you."/>
		<parameter key="shop_buyable" value="label,2599,10;letter,2597,10;parcel,2595,15"/>
	</parameters>
</npc>


Here, the script of the quest. "postmanquest.lua"

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, 'mission') then
	if getPlayerStorageValue(cid, 30120) == -1 then
		npcHandler:say('I have many missions for the postman quest..you can help me?', cid)
		talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, 30121) == 1 then
                npcHandler:say('Own..you have my feedback?!', cid)
                talkState[talkUser] = 2
        elseif getPlayerStorageValue(cid, 30121) == 2 then
                npcHandler:say('Sorry...but you already have complete my service.', cid)
                talkState[talkUser] = 3
        end
        
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Great...delivery this letter for my girlfriend in depot of Seyriu City.', cid)
                doPlayerAddItem(cid,2333,1)
                setPlayerStorageValue(cid,30120,1)
                talkState[talkUser] = 2
                else
                selfSay('You already have the delivery...Come back have them...', cid)
        end

    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
                npcHandler:say('Thanks officer! Now you have the acess to enter in MailBox Room\'s...Remember in future come here for more missions to have discount buying parcel and letters.', cid)
	            if doPlayerRemoveItem(cid,2665,1) == TRUE then
                setPlayerStorageValue(cid,30121,2)
                setPlayerStorageValue(cid,60035,1)
                talkState[talkUser] = 3
                else
                npcHandler:say('Sorry...but you dont have item. Come back have them', cid)
            end
            end
            end
    return true
end

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

Example fast:
*you say hi*
*after, say mission, to begin mission. say trade for buy parcel's and letter's*

This is my complete npc :)
 
The training room script what unqie id should i take on the teleport?
 
@up

use this storage Unique ID:60034 in your quest door, you dont have the storage , you dont enter in trainer room. :p
 
Back
Top