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

NPC Script with storage time

adamox223

New Member
Joined
Oct 21, 2017
Messages
99
Reaction score
4
Hello! I am looking for script npc:

- When we have item 9999 then npc remove item 9999 and will teleport us on pos x=4242 y= 1412 z=7 and give storage xxxx for 5 minutes, after 5 minutes of end storage we will back to npc - pos x= 2204 x= 1069 z=6
(back teleport)

can anyone help me? :/
 
Solution
if you can put on this script:

- when we dont have item: xxxx then npc dont teleport us
and when we have item: xxxx, then remove this item from backpack and teleport, can you? because i am begginer ;/
Sorry my eyes glossed over that part. :rolleyes:
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()...
Hello! I am looking for script npc:

- When we have item 9999 then npc remove item 9999 and will teleport us on pos x=4242 y= 1412 z=7 and give storage xxxx for 5 minutes, after 5 minutes of end storage we will back to npc - pos x= 2204 x= 1069 z=6
(back teleport)

can anyone help me? :/
What happens if the player dies or logs out within thoae 5 minutes?
What tfs?
 
a base that can help you ;D
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

    local giveTimeToStorage = 60000 * 5
    local storageReturnTime = 50000
    local nextPosition = { x = 0, y = 0, z = 0, stackpos = 0 }
    local returnPosition = { x = 0, y = 0, z = 0, stackpos = 0 }

    local playerReturnPosition = function(cid)
    doTeleportThing(cid.uid, returnPosition)
    doSendMagicEffect(returnPosition, CONST_ME_TELEPORT)
    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') then
        selfSay('Do you want to start the mission?', cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
    if msgcontains(msg, 'yes') then
        doTeleportThing(cid.uid, nextPosition)
        doSendMagicEffect(nextPosition, CONST_ME_TELEPORT)
        setPlayerStorageValue(cid, storageReturnTime, (os.time() + (giveTimeToStorage / 1000)))
        addEvent(playerReturnPosition, giveTimeToStorage, cid)
        selfSay('after 5 minutes we see each other again!', cid)
    else
        talkState[talkUser] = -1
        selfSay('come back later if you want a mission.', cid)
    end
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
help with the code if it's wrong, instead of criticizing the things of others.
¿? Im not saying anything to you. Im just asking the OP why he thinks he needs the timer. I guess you added it to your script because he asked for a timer in a storage, but that's the point for timed events.

Take it easy
 
This script with timer can be too! :/

5y7yty.png
 
Try this. I reworked the code abit.
I'm assuming that you need them to have a storage value within the quest area to complete something special, so I left that part in.
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

local timer = 5 -- minutes
local temp_storage = 45001
local nextPosition = {x = 0, y = 0, z = 0}
local returnPosition = {x = 0, y = 0, z = 0}

-- Teleport Player with Simple Storage Assign/Deassign
local function TPwSSAD(cid, position, storage)
    if isPlayer(cid) then
        if getPlayerStorageValue(cid, storage) == 1 then
            setPlayerStorageValue(cid, storage, 0)
        else
            setPlayerStorageValue(cid, storage, 1)
        end
        doTeleportThing(cid, position)
        doSendMagicEffect(position, CONST_ME_TELEPORT)
    end
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
        selfSay("Do you want to start the mission?", cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, "yes") then
            addEvent(TPwSSAD, 0, cid, nextPosition, temp_storage)
            addEvent(TPwSSAD, 1000 * 60 * timer, cid, returnPosition, temp_storage)
            selfSay("After 5 minutes we see each other again!", cid)
        else
            talkState[talkUser] = 0
            selfSay("Come back later if you want a mission.", cid)
        end
    end
 
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
if you can put on this script:

- when we dont have item: xxxx then npc dont teleport us
and when we have item: xxxx, then remove this item from backpack and teleport, can you? because i am begginer ;/
 
if you can put on this script:

- when we dont have item: xxxx then npc dont teleport us
and when we have item: xxxx, then remove this item from backpack and teleport, can you? because i am begginer ;/
Sorry my eyes glossed over that part. :rolleyes:
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

local item_required_for_teleport = 9999
local item_count_required_for_teleport = 1
local timer = 5 -- minutes
local temp_storage = 45001 
local nextPosition = {x = 0, y = 0, z = 0}
local returnPosition = {x = 0, y = 0, z = 0}

-- Teleport Player with Simple Storage Assign/Deassign
local function TPwSSAD(cid, position, storage)
    if isPlayer(cid) then
        if getPlayerStorageValue(cid, storage) == 1 then
            setPlayerStorageValue(cid, storage, 0)
        else
            setPlayerStorageValue(cid, storage, 1)
        end
        doTeleportThing(cid, position)
        doSendMagicEffect(position, CONST_ME_TELEPORT)
    end
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
        selfSay("Do you want to start the mission?", cid)
        talkState[talkUser] = 1
    elseif talkState[talkUser] == 1 then
        if msgcontains(msg, "yes") then
            if getPlayerItemCount(cid, item_required_for_teleport) >= item_count_required_for_teleport then
                doPlayerRemoveItem(cid, item_required_for_teleport, item_count_required_for_teleport)
                addEvent(TPwSSAD, 0, cid, nextPosition, temp_storage)
                setPlayerStorageValue(cid, storage, 1)
                addEvent(TPwSSAD, 1000 * 60 * timer, cid, returnPosition, temp_storage)
                selfSay("After " .. timer .. " minutes we see each other again!", cid)
            else
                talkState[talkUser] = 0
                selfSay("Come back later when you have the required item.", cid)
            end
        else
            talkState[talkUser] = 0
            selfSay("Come back later if you want a mission.", cid)
        end
    end
   
    return true
end

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