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

Lua My npc doesn't works - Can any1 fix it?

legolas23

New Member
Joined
Jan 8, 2009
Messages
537
Reaction score
3
Hello
I've made an npc script for a huge rpg quest on my server but when i try to speak with this npc it doesn't responds to me for any words

Here's script
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, 'quest') or msgcontains(msg, 'mission') or msgcontains(msg, 'ring') or msgcontains(msg, 'job') or msgcontains(msg, 'parrot') or msgcontains(msg, 'tree')) then
    -- NPC sprawdza, czy nie zrobiles jego pierwszej misji
        if getPlayerStorageValue(cid, 33111) < 1 then
            npcHandler:say("Tak, to prawda, szukam dzielnego podroznika do wykonania niebezpiecznego zadania... Musisz wkrasc sie do siedziby szamanów przez portal niedaleko zamku wapirow w dzungli. Teren wokol portalu moze byc silnie chroniony. Jednak to nie wszystko. Twoim zadaniem jest przekradniecie sie do mojego szpiega Bethura w ich glownym obozie... Wchodzisz w to?", cid)
            talkState[talkUser] = 1
    -- Zalozmy, ze po wykonaniu 1 misji gracz dostal wartosc storage 33111, 2 (setPlayerStorageValue(cid, 33111, 2).
        elseif getPlayerStorageValue(cid, 33111) == 2 then
            npcHandler:say("Wykonales moja pierwsza misje, ale mam dla ciebie kolejna. Idz i porozmawiaj z królem orków obozujacego niedaleko lasu entow.zdobadz storageValue(cid, 33111, 3), zgoda?", cid)
            talkState[talkUser] = 2
        end
    elseif(msgcontains(msg, 'tak') or msgcontains(msg, 'yes')) then
        if talkState[talkUser] == 1 then
            setPlayerStorageValue(cid, 33111, 1)
            npcHandler:say("Wiedzialem, ze podejmiesz sie tego wyzwania. Powodzenia!", cid)
            talkState[talkUser] = 0
        elseif talkState[talkUser] == 2 then
            npcHandler:say("W porzadku. Przyjdz jak wykonasz zadanie mojego brata.", cid)
            talkState[talkUser] = 0
        end
    elseif(msgcontains(msg, 'nie') or msgcontains(msg, 'no') and talkState[talkUser > 0]) then
        npcHandler:say("No to po co marnujesz moj cenny czas? Jazda mi z tad!")
        talkState[talkUser] = 0
    end
return true
end

npc
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Ethan" script="data/npc/scripts/rpg1.lua" walkinterval="2000" floorchange="0">
	<health now="100" max="100"/>
	<look type="57" head="20" body="30" legs="40" feet="50" />
	<parameters>
	<parameter key="message_greet" value="Hello, |PLAYERNAME|." />
	</parameters>
</npc>
 
And you're trying to talk to him with the keywords "Mission" - "Job" etc?

If you're not getting any errors in your console, the case will be very hard to solve and in fact, everything should be working fine.
 
Give this a shot.
PHP:
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, 'quest') or msgcontains(msg, 'mission') or msgcontains(msg, 'ring') or msgcontains(msg, 'job') or msgcontains(msg, 'parrot') or msgcontains(msg, 'tree')) then
    -- NPC sprawdza, czy nie zrobiles jego pierwszej misji
        if getPlayerStorageValue(cid, 33111) < 1 then
            npcHandler:say("Tak, to prawda, szukam dzielnego podroznika do wykonania niebezpiecznego zadania... Musisz wkrasc sie do siedziby szamanów przez portal niedaleko zamku wapirow w dzungli. Teren wokol portalu moze byc silnie chroniony. Jednak to nie wszystko. Twoim zadaniem jest przekradniecie sie do mojego szpiega Bethura w ich glownym obozie... Wchodzisz w to?", cid)
            talkState[talkUser] = 1
    -- Zalozmy, ze po wykonaniu 1 misji gracz dostal wartosc storage 33111, 2 (setPlayerStorageValue(cid, 33111, 2).
        elseif getPlayerStorageValue(cid, 33111) == 2 then
            npcHandler:say("Wykonales moja pierwsza misje, ale mam dla ciebie kolejna. Idz i porozmawiaj z królem orków obozujacego niedaleko lasu entow.zdobadz storageValue(cid, 33111, 3), zgoda?", cid)
            talkState[talkUser] = 2
        end
    elseif(msgcontains(msg, 'tak') or msgcontains(msg, 'yes')) then
        if talkState[talkUser] == 1 then
            setPlayerStorageValue(cid, 33111, 1)
            npcHandler:say("Wiedzialem, ze podejmiesz sie tego wyzwania. Powodzenia!", cid)
            talkState[talkUser] = 0
        elseif talkState[talkUser] == 2 then
            npcHandler:say("W porzadku. Przyjdz jak wykonasz zadanie mojego brata.", cid)
            talkState[talkUser] = 0
        end
    elseif(msgcontains(msg, 'nie') or msgcontains(msg, 'no') and talkState[talkUser > 0]) then
        npcHandler:say("No to po co marnujesz moj cenny czas? Jazda mi z tad!")
        talkState[talkUser] = 0
    end
    return TRUE
end

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