• 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 [TFS 1.3] NPC needs 2-3 items to grant player access

SorketROrk

Well-Known Member
Joined
Oct 14, 2020
Messages
152
Solutions
1
Reaction score
69
Location
Sweden
Hello! :)

I'm looking for a script that will grant player access, so that he/she may pass x tile!

I was thinking something like this:

Player: Hi
NPC: Hello there, I can let you pass for 20x 2160, 30x item2, do you accept?.. something like that xD
Player: Yes

Player would then be able to pass x tile, which is not accessible to those who have not given these items to the NPC.

Hopefully its not a too much to ask, thanks :)

Yours,
SRO
 
NPC:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 talkState = {}
local greetCallbackk = ""
local cfg = {storageTile = 999999, itemId1 = 50016, iCount1 = 20, itemId2 = 50001, iCount2 = 50, ptName = "Big Daddy Tomb" } --7 do 8 proba


local str1 = "Hello adventuer! What can I do for You? Do you want to get access to {"..cfg.ptName.."}?"
local str2 = "Hello |PLAYERNAME|! Sorry but I'm bussy right now, we can talk later...?"   
            
local itemName1 = getItemNameById(cfg.itemId1)
local itemName2 = getItemNameById(cfg.itemId2)
            
local msg = "Give me {"..cfg.iCount1.." "..itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s} then I give you a pass. Do you have it?"
local msgYes = "Let me have look..."
local msgNo = "Come back wehen you change your mind..."
local msgNe = "Hey, you dont have enough items! I need {"..cfg.iCount1.." "..cfg.itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s}. Come back when you get it."
local msgAg = "Thank You my friend, You can go now!"
local msgW = "Stop wasting my time!"

--
function greetCallback(cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
            greetCallbackk = str1
            talkState[talkUser] = 1
    elseif (getPlayerStorageValue(cid, cfg.storageTile) > 0)then   
            greetCallbackk = str2
            talkState[talkUser] = 0   
    end
    
    npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
    
return true
end

function creatureSayCallback(cid, type, msg)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


    if (talkState[talkUser] == 0) then
        npcHandler:unGreet(cid) --reset/unfocus/bye
    elseif (talkState[talkUser] == 1) then -- state 1
        if (msgcontains(msg, cfg.ptName)) then
            selfSay(msg, cid)   
            talkState[talkUser] = 2
        end
    elseif (talkState[talkUser] == 2) then -- state 2   
            if (msgcontains(msg, 'yes')) then
                selfSay(msgYes, cid)   
                --items check
                if getPlayerItemCount(cid, cfg.itemId1) >= cfg.iCount1 and getPlayerItemCount(cid, cfg.iCount2) >= cfg.iCount2 then --access granted
                    doPlayerRemoveItem(cid, cfg.itemId1, cfg.iCount1)
                    doPlayerRemoveItem(cid, cfg.itemId2, cfg.iCount2)
                    doPlayerSetStorageValue(cid, cfg.storageTile, 1)
                    selfSay(msgAg, cid)
                else -- not enough items
                    selfSay(msgNe, cid)   
                end
            elseif (msgcontains(msg, 'no')) then --dont want it?
                selfSay(msgNo, cid)   
            else
                selfSay(msgW, cid)    --npc is bussy
            end
            
        npcHandler:unGreet(cid) --reset anyway   
    end
    
return true

end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
npcHandler:setMessage(MESSAGE_FAREWELL, 'See Ya!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Hmpf...')


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

Tile:
Lua:
function onStepIn(cid, item, position, fromPosition)

local cfg = {storageTile = 999999, pBack = "You have no access to this area."}

    if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, cfg.pBack)
        doTeleportThing(cid, fromPosition, false)
    end
    
    return true
end
 
NPC:

Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 talkState = {}
local greetCallbackk = ""
local cfg = {storageTile = 999999, itemId1 = 50016, iCount1 = 20, itemId2 = 50001, iCount2 = 50, ptName = "Big Daddy Tomb" } --7 do 8 proba


local str1 = "Hello adventuer! What can I do for You? Do you want to get access to {"..cfg.ptName.."}?"
local str2 = "Hello |PLAYERNAME|! Sorry but I'm bussy right now, we can talk later...?"  
           
local itemName1 = getItemNameById(cfg.itemId1)
local itemName2 = getItemNameById(cfg.itemId2)
           
local msg = "Give me {"..cfg.iCount1.." "..itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s} then I give you a pass. Do you have it?"
local msgYes = "Let me have look..."
local msgNo = "Come back wehen you change your mind..."
local msgNe = "Hey, you dont have enough items! I need {"..cfg.iCount1.." "..cfg.itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s}. Come back when you get it."
local msgAg = "Thank You my friend, You can go now!"
local msgW = "Stop wasting my time!"

--
function greetCallback(cid)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

    if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
            greetCallbackk = str1
            talkState[talkUser] = 1
    elseif (getPlayerStorageValue(cid, cfg.storageTile) > 0)then  
            greetCallbackk = str2
            talkState[talkUser] = 0  
    end
   
    npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
   
return true
end

function creatureSayCallback(cid, type, msg)
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid


    if (talkState[talkUser] == 0) then
        npcHandler:unGreet(cid) --reset/unfocus/bye
    elseif (talkState[talkUser] == 1) then -- state 1
        if (msgcontains(msg, cfg.ptName)) then
            selfSay(msg, cid)  
            talkState[talkUser] = 2
        end
    elseif (talkState[talkUser] == 2) then -- state 2  
            if (msgcontains(msg, 'yes')) then
                selfSay(msgYes, cid)  
                --items check
                if getPlayerItemCount(cid, cfg.itemId1) >= cfg.iCount1 and getPlayerItemCount(cid, cfg.iCount2) >= cfg.iCount2 then --access granted
                    doPlayerRemoveItem(cid, cfg.itemId1, cfg.iCount1)
                    doPlayerRemoveItem(cid, cfg.itemId2, cfg.iCount2)
                    doPlayerSetStorageValue(cid, cfg.storageTile, 1)
                    selfSay(msgAg, cid)
                else -- not enough items
                    selfSay(msgNe, cid)  
                end
            elseif (msgcontains(msg, 'no')) then --dont want it?
                selfSay(msgNo, cid)  
            else
                selfSay(msgW, cid)    --npc is bussy
            end
           
        npcHandler:unGreet(cid) --reset anyway  
    end
   
return true

end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)

npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
npcHandler:setMessage(MESSAGE_FAREWELL, 'See Ya!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Hmpf...')


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

Tile:
Lua:
function onStepIn(cid, item, position, fromPosition)

local cfg = {storageTile = 999999, pBack = "You have no access to this area."}

    if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, cfg.pBack)
        doTeleportThing(cid, fromPosition, false)
    end
   
    return true
end
Hey,

Trying out ur script but getting an error about the itemName1 in code, tried with ItemName1 and ItemName and changing some lines but still same error,

Error below is from original script , using TFS 1.3 latest
1614764787901.png
 
Hey,

Trying out ur script but getting an error about the itemName1 in code, tried with ItemName1 and ItemName and changing some lines but still same error,

Error below is from original script , using TFS 1.3 latest
View attachment 55748
Lua:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 talkState = {}
local greetCallbackk = ""
local cfg = {storageTile = 999999, itemId1 = 50016, iCount1 = 20, itemId2 = 50001, iCount2 = 50, ptName = "Big Daddy Tomb" } --7 do 8 proba


local str1 = "Hello adventuer! What can I do for You? Do you want to get access to {"..cfg.ptName.."}?"
local str2 = "Hello |PLAYERNAME|! Sorry but I'm bussy right now, we can talk later...?"   
            
local itemName1 = getItemNameById(cfg.itemId1)
local itemName2 = getItemNameById(cfg.itemId2)
            
local msg = "Give me {"..cfg.iCount1.." "..itemName1.."s} and {"..cfg.iCount2.." "..itemName2.."s} then I give you a pass. Do you have it?"
local msgYes = "Let me have look..."
local msgNo = "Come back wehen you change your mind..."
local msgNe = "Hey, you dont have enough items! I need {"..cfg.iCount1.." "..itemName1.."s} and {"..cfg.iCount2.." "..itemName2.."s}. Come back when you get it."
local msgAg = "Thank You my friend, You can go now!"
local msgW = "Stop wasting my time!"

--
function greetCallback(cid)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
			greetCallbackk = str1
			talkState[talkUser] = 1
	elseif (getPlayerStorageValue(cid, cfg.storageTile) > 0)then   
			greetCallbackk = str2
			talkState[talkUser] = 0   
	end
	
	npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
	
	return true
end

function creatureSayCallback(cid, type, msg)
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	
	if (talkState[talkUser] == 0) then
		npcHandler:unGreet(cid) --reset/unfocus/bye
	elseif (talkState[talkUser] == 1) then -- state 1
		if (msgcontains(msg, cfg.ptName)) then
			selfSay(msg, cid)   
			talkState[talkUser] = 2
		end
	elseif (talkState[talkUser] == 2) then -- state 2   
		if (msgcontains(msg, 'yes')) then
			selfSay(msgYes, cid)   
			--items check
			if getPlayerItemCount(cid, cfg.itemId1) >= cfg.iCount1 and getPlayerItemCount(cid, cfg.itemId2) >= cfg.iCount2 then --access granted
				doPlayerRemoveItem(cid, cfg.itemId1, cfg.iCount1)
				doPlayerRemoveItem(cid, cfg.itemId2, cfg.iCount2)
				doPlayerSetStorageValue(cid, cfg.storageTile, 1)
				selfSay(msgAg, cid)
			else -- not enough items
				selfSay(msgNe, cid)   
			end
		elseif (msgcontains(msg, 'no')) then --dont want it?
			selfSay(msgNo, cid)   
		else
			selfSay(msgW, cid)    --npc is bussy
		end
			
		npcHandler:unGreet(cid) --reset anyway   
	end
    
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
 
npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
npcHandler:setMessage(MESSAGE_FAREWELL, 'See Ya!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Hmpf...')


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