• 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 how to fix that lua script?

Mickowy

New Member
Joined
Jul 18, 2009
Messages
4
Reaction score
0
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, 'mission') then
	if getPlayerStorageValue(cid, 10011) == -1 then
		npcHandler:say('If u want to enter my training room you shall find Magic Book and retrieve it to me.', cid)
		talkState[talkUser] = 1
         elseif getPlayerStorageValue(cid, 10010) == 1 then
                npcHandler:say('Have you retrieved it?', cid)
                talkState[talkUser] = 2
        elseif getPlayerStorageValue(cid, 10010) == 2 then
                npcHandler:say('Thank you for the book. I no longer need your further assistance.', cid)
                talkState[talkUser] = 3
        end

    elseif talkState[talkUser] == 2 then
        if msgcontains(msg, 'yes') then
	     if getPlayerItemCount(uid,10546) == 1 then
		    doPlayerRemoveItem(cid,10546,1)
                npcHandler:say('Thank you! now you have acess to enter in my Training Room.', cid)
                setPlayerStorageValue(cid, 10010, 2)
                setPlayerStorageValue(cid,10011,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 want my npc to take book in exchange for entry to training room but it doesnt remove the book.. when I say 'yes' i doesnt do nothing. can any1 help? :/
 
Last edited:
I want my npc to give me quest, So I can retrieve a magic book from a certain place. After I give him the book hes supposed to give me permission (storage value 10011) to his training room. I found this script somewhere on internet but its not working :/
The script stops at the moment when I have the item to give him back and i say 'yes' ,console doesnt show any problems with script though.

btw thx for being interested Scofield :)
 
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 greetCallback(cid)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	talkState[talkUser] = 0
	return true
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") or msgcontains(msg, "quest") or (msgcontains(msg, "book") and getPlayerStorageValue(cid, 10011) > 0) then
		if getPlayerStorageValue(cid, 10011) < 1 then
			npcHandler:say("If you want to enter my training room you will have to find the magic book. Just ask me about your {mission} once you retrive it.", cid)
			setPlayerStorageValue(cid, 10011, 1)
		elseif getPlayerStorageValue(cid, 10010) == 1 then
			npcHandler:say("Have you retrieved the magic book?", cid)
			talkState[talkUser] = 1
		elseif getPlayerStorageValue(cid, 10010) == 2 then
			npcHandler:say("Thank you again for the book. I no longer need your further assistance.", cid)
		end
	elseif talkState[talkUser] == 1 then
		if msgcontains(msg, "yes") then
			if getPlayerItemCount(uid,10546) > 0 then
				doPlayerRemoveItem(cid, 10546, 1)
				npcHandler:say("Thank you! You are now allowed to enter my Training Room.", cid)
				setPlayerStorageValue(cid, 10010, 2)
				setPlayerStorageValue(cid, 10011, 1)
			else
				npcHandler:say("Hm, you don't have it.", cid)
			end
		else
			npcHandler:say("Okay, let me know as soon as you retrive it.", cid)
		end
		talkState[talkUser] = 0
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Hey Cykotitan, actually it doesnt remove the item ( 10546 ) and opens the door.. i just dunno what the hell. im using tfs 0.3.5 still doesnt work :(
also the npc doesnt say anything when you actually dont have a book or still searching for it. is this npc totally useless? :(
 
bump? need help guys :(

EDIT: thanks for nothing, already solved the problem. seems this forums aren't that helpful as i thought :/
 
Last edited:
Back
Top