• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Przepisanie/poprawienie kodu NPC z questem

Xadrian

Active Member
Joined
Feb 24, 2008
Messages
905
Reaction score
26
Location
Poland, Stalowa Wola
Witam.
Po trzeciej nieudanej próbie przepisania NPC zawierającego misję dla gracza postanowiłem spytać się Was jak to w końcu powinno wyglądać. Za każdym razem NPC nie odpowiadał w jakiejś części dialogu.
Starszych wersji nie mam, oto ostatnia, chyba najbardziej rozpisana:
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local quest = {
        storage = 13569,
        state = getPlayerStorageValue(cid, 13569),
    }
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
    if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
        if(quest.state == -1 or quest.state == 0) then
            talkState[talkUser] = 1
            error(liczba1)
        elseif(quest.state == 1) then
            talkState[talkUser] = 10        
        else
            selfSay('I tink you already done all of my missions. Thank you!', cid)
            return true
        end
        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
            
            if(talkState[talkUser] == 2) then
                if(msgcontains(msg, 'yes')) then
                    selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts?}', cid)
                    talkState[talkUser] = 3    
                    
                elseif(msgcontains(msg, 'no')) then                
                    talkState[talkUser] = 1
                    selfSay('Maybe next time.', cid)    
                    npcHandler:resetNpc()    
                end
            elseif(talkState[talkUser] == 3) then
                if(msgcontains(msg, 'yes')) then
                    selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
                    doPlayerSetStorageValue(cid, quest.storage, 1)
                    npcHandler:resetNpc()
                    
                elseif(msgcontains(msg, 'no')) then                
                    selfSay('Maybe next time.', cid)
                    npcHandler:resetNpc()                
                end                
            end
        elseif(talkState[talkUser] == 10) then
            selfSay('Do you want to give me {10 cocounts}?', cid)
            talkState[talkUser] = 11
            
            if(msgcontains(msg, 'yes')) then
                if(getPlayerItemCount(cid, 2678) >= 10) then
                    selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
                    doPlayerSetStorageValue(cid, quest.storage, 2)
                    talkState[talkUser] = 0            
                else
                    selfSay('You dont have {10 cocounts}!', cid)
                    npcHandler:resetNpc()
                end
            elseif(msgcontains(msg, 'no')) then                
                selfSay('So ask me when you are done!', cid)    
                npcHandler:resetNpc()
            end
        end
    end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Code:
http://wklej.org/hash/3f502be656/?zawin=0
Code:
20:22 Lilanne: Hello, Druid Sample. I sell much types of food!
20:22 Druid Sample [98]: mission
<nic>
Przysłowie 'do trzech razy sztuka' mnie się nie trzyma.
W konsoli 0 błędów.

Liczę, że ktoś pomoże,
Xadrian
 
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    
    local quest = {
        storage = 13569,
        state = getPlayerStorageValue(cid, 13569),
    }
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
	if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
        
        if (quest.state < 1) then
			talkState[talkUser] = 1
            -- error(liczba1), wybacz nie wiem do czego to służy ^^
        elseif (quest.state == 1) then
			talkState[talkUser] = 10
        end else
			selfSay('I tink you already done all of my missions. Thank you!', cid)
            return true
        end        
	end
        
        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
		end
		
		if(talkState[talkUser] == 2) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
				talkState[talkUser] = 3    
			elseif(msgcontains(msg, 'no')) then                
				talkState[talkUser] = 1
				selfSay('Maybe next time.', cid)    
				npcHandler:resetNpc()    
			end
		end
			
		if(talkState[talkUser] == 3) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
				doPlayerSetStorageValue(cid, quest.storage, 1)
				npcHandler:resetNpc()
			elseif(msgcontains(msg, 'no')) then     
				talkState[talkUser] == 1
				selfSay('Maybe next time.', cid)
				npcHandler:resetNpc()                
			end                
			
        if(talkState[talkUser] == 10) then
			selfSay('Do you want to give me {10 cocounts}?', cid)
			talkState[talkUser] = 11
            
			if(msgcontains(msg, 'yes')) then            
				if(getPlayerItemCount(cid, 2678) >= 10) then
					selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
					doPlayerSetStorageValue(cid, quest.storage, 2)
					talkState[talkUser] = 0            
				else
					talkState[talkUser] = 1
					selfSay('You dont have {10 cocounts}!', cid)
					npcHandler:resetNpc()
				end
				
			if(msgcontains(msg, 'no')) then                
				selfSay('So ask me when you are done!', cid)    
				npcHandler:resetNpc()
			end            
		end
		
end

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

Nie sprawdzane, nie testowane - pisane moim "zabytkowym LUA" ;o.

Code:
            talkState[talkUser] = 2
            
            if(talkState[talkUser] == 2) then
lol65536

Z ciekawości zapytam, czy działa i jak wygląda switch...case w LUA (w Gugielach jest 5+ "sposobów" na switch'a, a jakiś "pewny i sprawdziony"?) :)?
 
Zapomniałem o paru elementach do usunięcia, właśnie typu error(liczba).

@darqnies
Nadal bez zmian. Po napisaniu mission npc nie odpisuje.
 
Code:
        if (quest.state < 1) then
			talkState[talkUser] = 1
            -- error(liczba1), wybacz nie wiem do czego to służy ^^
        elseif (quest.state == 1) then
			talkState[talkUser] = 10
        end else
			selfSay('I tink you already done all of my missions. Thank you!', cid)
            return true
        end

Zamienić na:
Code:
	action = {
		[-1] = function () talkState[talkUser] = 1 end,
		[0] = function () talkState[talkUser] = 1 end,
		[2] = function () selfSay('I tink you already done all of my missions. Thank you!', cid) end,
		[1] = function () talkState[talkUser] = 1 end,
	}
	action[quest.state]



#edit:

Linia 37:" end"
O jeden za dużo :))

Rep++!

3wjg21yurjwj1xkrskq.png


## WRÓĆ! Ćoś pokręciłem ^^ ##
 
Last edited:
Code:
[05/01/2010 21:27:31] [Error - LuaScriptInterface::loadFile] data/npc/scripts/food.lua:36: '=' expected near 'if'
[05/01/2010 21:27:31] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/food.lua
[05/01/2010 21:27:31] data/npc/scripts/food.lua:36: '=' expected near 'if'

rep++ rup więcej ; s
 
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
		if(not npcHandler:isFocused(cid)) then
			return false
		end
    
		local quest = {
			storage = 13569,
			state = getPlayerStorageValue(cid, 13569),
		}
		local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
		if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
			if (quest.state < 1) then
				talkState[talkUser] = 1
			elseif (quest.state == 1) then
				talkState[talkUser] = 10
			elseif
				selfSay('I tink you already done all of my missions. Thank you!', cid)
				return true
			end
		end        

        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
		end
		
		if(talkState[talkUser] == 2) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
				talkState[talkUser] = 3    
			elseif(msgcontains(msg, 'no')) then                
				talkState[talkUser] = 1
				selfSay('Maybe next time.', cid)    
				npcHandler:resetNpc()    
			end
		end
			
		if(talkState[talkUser] == 3) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
				doPlayerSetStorageValue(cid, quest.storage, 1)
				npcHandler:resetNpc()
			elseif(msgcontains(msg, 'no')) then     
				talkState[talkUser] == 1
				selfSay('Maybe next time.', cid)
				npcHandler:resetNpc()                
			end                
		end
			
        if(talkState[talkUser] == 10) then
			selfSay('Do you want to give me {10 cocounts}?', cid)
			talkState[talkUser] = 11
            
			if(msgcontains(msg, 'yes')) then            
				if(getPlayerItemCount(cid, 2678) >= 10) then
					selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
					doPlayerSetStorageValue(cid, quest.storage, 2)
					talkState[talkUser] = 0            
				end else
					talkState[talkUser] = 1
					selfSay('You dont have {10 cocounts}!', cid)
					npcHandler:resetNpc()
				end
				
			if(msgcontains(msg, 'no')) then                
				selfSay('So ask me when you are done!', cid)    
				npcHandler:resetNpc()
			end     			    
		end		
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Mówiłem, że zabytkowe LUA... :P
Chociaż w zasadzie cały twój problem to brak paru end'ów, niektóre w złych miejscach itd.
 
@up:
możliwe, z pół roku nic nie pisałem ; s

Dochodzę. spróbuję sam poprawić błędy. jeżeli nic z tego - napiszę.
edit: oczywiście jak by to było, jak bym sam poprawił -.-

Kod:
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

    function creatureSayCallback(cid, type, msg)
        if(not npcHandler:isFocused(cid)) then
            return false
        end
    
        local quest = {
            storage = 13569,
            state = getPlayerStorageValue(cid, 13569),
        }
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
        if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
            if (quest.state < 1) then
                talkState[talkUser] = 1
            elseif (quest.state == 1) then
                talkState[talkUser] = 10
            elseif (quest.state == 2) then
                selfSay('I tink you already done all of my missions. Thank you!', cid)
                return true
            end
        end        

        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
        end
        
        if(talkState[talkUser] == 2) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
                talkState[talkUser] = 3    
            elseif(msgcontains(msg, 'no')) then                
                selfSay('Maybe next time.', cid)    
                talkState[talkUser] = 0    
            end
        end
            
        if(talkState[talkUser] == 3) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
                doPlayerSetStorageValue(cid, quest.storage, 1)
                talkState[talkUser] = 0
            elseif(msgcontains(msg, 'no')) then     
                talkState[talkUser] = 1
                selfSay('Maybe next time.', cid)
                talkState[talkUser] = 0                
            end                
        end
            
        if(talkState[talkUser] == 10) then
            selfSay('Do you want to give me {10 cocounts}?', cid)
            talkState[talkUser] = 11
            
            if(msgcontains(msg, 'yes')) then            
                if(getPlayerItemCount(cid, 2678) >= 10) then
                    selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
                    doPlayerSetStorageValue(cid, quest.storage, 2)
                    talkState[talkUser] = 0            
                else
                    selfSay('You dont have {10 cocounts}!', cid)
                    talkState[talkUser] = 0
                end
            end
                
            if(msgcontains(msg, 'no')) then                
                selfSay('So ask me when you are done!', cid)    
                talkState[talkUser] = 0
            end                     
        end        
    end

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

Rozmowa z NPC:
Code:
21:55 Lilanne: Hello, Druid Sample. I sell much types of food!
21:55 Druid Sample [98]: mission
21:55 Lilanne: Do you want to help me in collecting rare types of food? Please, say yes!
21:56 Druid Sample [98]: yes
21:56 Lilanne: Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me 10 cocounts?
21:56 Lilanne: Thanks, again. I expect to you with 10 cocounts. Ask me for mission or quest, when you are done.
21:56 Druid Sample [98]: mission
21:56 Lilanne: Do you want to give me 10 cocounts?
21:56 Druid Sample [98]: yes
 
Last edited:
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
		if(not npcHandler:isFocused(cid)) then
			return false
		end
    
		local quest = {
			storage = 13569,
			state = getPlayerStorageValue(cid, 13569),
		}
		local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
		if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
			if (quest.state < 1) then
				talkState[talkUser] = 1
			elseif (quest.state == 1) then
				talkState[talkUser] = 10
			elseif
				selfSay('I tink you already done all of my missions. Thank you!', cid)
				return true
			end
		end        

        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
		end
		
		if(talkState[talkUser] == 2) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
				talkState[talkUser] = 3    
			elseif(msgcontains(msg, 'no')) then                
				talkState[talkUser] = 1
				selfSay('Maybe next time.', cid)    
				npcHandler:resetNpc()    
			end
		end
			
		if(talkState[talkUser] == 3) then
			if(msgcontains(msg, 'yes')) then
				selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
				doPlayerSetStorageValue(cid, quest.storage, 1)
				npcHandler:resetNpc()
			elseif(msgcontains(msg, 'no')) then     
				talkState[talkUser] == 1
				selfSay('Maybe next time.', cid)
				npcHandler:resetNpc()                
			end                
		end
			
        if(talkState[talkUser] == 10) then
			selfSay('Do you want to give me {10 cocounts}?', cid)
            
			if(msgcontains(msg, 'yes')) then            
				if(getPlayerItemCount(cid, 2678) >= 10) then
					selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
					doPlayerSetStorageValue(cid, quest.storage, 2)
					talkState[talkUser] = 0            
				end else
					talkState[talkUser] = 10 -- nie na 100%
					selfSay('You dont have {10 cocounts}!', cid)
					npcHandler:resetNpc()
				end
				
			if(msgcontains(msg, 'no')) then                
				selfSay('So ask me when you are done!', cid)    
				npcHandler:resetNpc()
			end     			    
		end		
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Sprawdź czy śmiga, ogarne sobie mysql i odpalić spróbuje u siebie :). Jaki TFS :P?
 
Jeszcze bliżej. Teraz tylko dwa błędy, mianowicie niepotrzebny msg po 'yes' oraz dwie wiadomości na raz po zaakceptowaniu questa:
Code:
21:59 Lilanne: Hello, Druid Sample. I sell much types of food!
21:59 Druid Sample [98]: mission
21:59 Lilanne: Do you want to help me in collecting rare types of food? Please, say yes!
21:59 Druid Sample [98]: yes
21:59 Lilanne: Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me 10 cocounts?
21:59 Lilanne: Thanks, again. I expect to you with 10 cocounts. Ask me for mission or quest, when you are done.
22:00 Druid Sample [98]: mission
22:00 Lilanne: Do you want to give me 10 cocounts?
22:00 Druid Sample [98]: yes
22:00 Lilanne: Do you want to give me 10 cocounts?
22:00 Lilanne: Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!
Uzywaj tego kodu, twój ma parę literówek typu '==' zamiast '=':
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
        if(not npcHandler:isFocused(cid)) then
            return false
        end
    
        local quest = {
            storage = 13575,
            state = getPlayerStorageValue(cid, 13575),
        }
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
        if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
            if (quest.state < 1) then
                talkState[talkUser] = 1
            elseif (quest.state == 1) then
                talkState[talkUser] = 10
            elseif (quest.state == 2) then
                selfSay('I tink you already done all of my missions. Thank you!', cid)
                return true
            end
        end        

        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
        end
        
        if(talkState[talkUser] == 2) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
                talkState[talkUser] = 3    
            elseif(msgcontains(msg, 'no')) then                
                talkState[talkUser] = 1
                selfSay('Maybe next time.', cid)    
                npcHandler:resetNpc()    
            end
        end
            
        if(talkState[talkUser] == 3) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
                doPlayerSetStorageValue(cid, quest.storage, 1)
                npcHandler:resetNpc()
            elseif(msgcontains(msg, 'no')) then     
                talkState[talkUser] = 1
                selfSay('Maybe next time.', cid)
                npcHandler:resetNpc()                
            end                
        end
            
        if(talkState[talkUser] == 10) then
            selfSay('Do you want to give me {10 cocounts}?', cid)
            
            if(msgcontains(msg, 'yes')) then            
                if(getPlayerItemCount(cid, 2678) >= 10) then
                    selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
                    doPlayerSetStorageValue(cid, quest.storage, 2)
                    talkState[talkUser] = 0            
                else
                    talkState[talkUser] = 10 -- nie na 100%
                    selfSay('You dont have {10 cocounts}!', cid)
                    npcHandler:resetNpc()
                end
            end
            if(msgcontains(msg, 'no')) then                
                selfSay('So ask me when you are done!', cid)    
                npcHandler:resetNpc()
            end                     
        end        
end

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

edit: używam 0.3.6pl1
 
Last edited:
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

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

function creatureSayCallback(cid, type, msg)
        if(not npcHandler:isFocused(cid)) then
            return false
        end
    
        local quest = {
            storage = 13575,
            state = getPlayerStorageValue(cid, 13575),
        }
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    
        if(msgcontains(msg, 'mission') or msgcontains(msg, 'quest')) then
            if (quest.state < 1) then
                talkState[talkUser] = 1
            elseif (quest.state == 1) then
                talkState[talkUser] = 10
            elseif (quest.state == 2) then
                selfSay('I tink you already done all of my missions. Thank you!', cid)
                return true
            end
        end        

        
        if(talkState[talkUser] == 1) then        
            selfSay('Do you want to help me in collecting rare types of food? Please, say {yes!}', cid)
            talkState[talkUser] = 2
        end
        
        if(talkState[talkUser] == 2) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me {10 cocounts}?', cid)
                talkState[talkUser] = 3   
                return true 
            elseif(msgcontains(msg, 'no')) then                
                talkState[talkUser] = 1
                selfSay('Maybe next time.', cid)    
                npcHandler:resetNpc()    
            end
        end
            
        if(talkState[talkUser] == 3) then
            if(msgcontains(msg, 'yes')) then
                selfSay('Thanks, again. I expect to you with {10 cocounts}. Ask me for mission or quest, when you are done.', cid)
                doPlayerSetStorageValue(cid, quest.storage, 1)
                npcHandler:resetNpc()
            elseif(msgcontains(msg, 'no')) then     
                talkState[talkUser] = 1
                selfSay('Maybe next time.', cid)
                npcHandler:resetNpc()                
            end                
        end
            
        if(talkState[talkUser] == 10) then
		
            if(msgcontains(msg, 'yes')) then            
                if(getPlayerItemCount(cid, 2678) >= 10) then
                    selfSay('Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!', cid)
                    doPlayerSetStorageValue(cid, quest.storage, 2)
                    talkState[talkUser] = 0            
                    return true
                else
                    talkState[talkUser] = 10 -- nie na 100%
                    selfSay('You dont have {10 cocounts}!', cid)
                    npcHandler:resetNpc()
                end
            end
            if(msgcontains(msg, 'no')) then                
                selfSay('So ask me when you are done!', cid)    
                npcHandler:resetNpc()
            end    
            
            selfSay('Do you want to give me {10 cocounts}?', cid)
        end        
end

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

Jeden topic, głupi problem z NPC i Posty+=5 :D

btw. Używaj tabulatora, jak jedziesz na spacjach czasami jedna mniej i Geany mi kod inaczej "łapie"...
 
No, w końcu działa:
Code:
22:14 Lilanne: Hello, Druid Sample. I sell much types of food!
22:14 Druid Sample [98]: mission
22:14 Lilanne: Do you want to help me in collecting rare types of food? Please, say yes!
22:14 Druid Sample [98]: yes
22:14 Lilanne: Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me 10 cocounts?
22:14 Druid Sample [98]: yes
22:14 Lilanne: Thanks, again. I expect to you with 10 cocounts. Ask me for mission or quest, when you are done.
22:14 Druid Sample [98]: mission
22:14 Lilanne: Do you want to give me 10 cocounts?
22:14 Druid Sample [98]: yes
22:14 Lilanne: Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!

I nie wiem, czemu zamieniło tabulatory na spacje - w każdym razie używałem tabulatorów, nie spacji.

Jak się mogę odwdzięczyć?
 
No, w końcu działa:
Code:
22:14 Lilanne: Hello, Druid Sample. I sell much types of food!
22:14 Druid Sample [98]: mission
22:14 Lilanne: Do you want to help me in collecting rare types of food? Please, say yes!
22:14 Druid Sample [98]: yes
22:14 Lilanne: Finally person, who can help me.. Im really tried with collecting this types of food. So, can you take to me 10 cocounts?
22:14 Druid Sample [98]: yes
22:14 Lilanne: Thanks, again. I expect to you with 10 cocounts. Ask me for mission or quest, when you are done.
22:14 Druid Sample [98]: mission
22:14 Lilanne: Do you want to give me 10 cocounts?
22:14 Druid Sample [98]: yes
22:14 Lilanne: Thank you! If you want, to do something more for me, ask me again for mission or quest! However, you now are able to buy exotic types of vegetables and fruits!

I nie wiem, czemu zamieniło tabulatory na spacje - w każdym razie używałem tabulatorów, nie spacji.

Jak się mogę odwdzięczyć?

daj mi pysia :)
 
Back
Top