• 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 Npc need 1 more option

Lbtg

Intermediate OT User
Joined
Nov 22, 2008
Messages
2,324
Reaction score
136
Hello so i got this npc with gives Storage for xxxx items.
i use 0.4

i want that npc can aswell Sell ticket with Same storage for lets say 30 min and after 30 min remove storage from player . and player again can buy Ticket for 30 min for xxxx items.
So player can bring items to npc to have 4eever storage or buy tickets to have storage for 30 min.

npc.lua
PHP:
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

function AssassinFirst(cid, message, keywords, parameters, node)

    if(not npcHandler:isFocused(cid)) then
        return false
    end

  
        if getPlayerItemCount(cid,8309) >= 250 then
        if doPlayerRemoveItem(cid,8309,250) then
            npcHandler:say('You can now pass next floor!', cid)
            setPlayerStorageValue(cid,6211,1)
        end
        else
            npcHandler:say('You don\'t have 250 nails , you can get them at War Golems!', cid)
        end
    end

keywordHandler:addKeyword({'help'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = "Bring me 250 nails from War golems, and bring them to me."})

local node = keywordHandler:addKeyword({'m'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you already collected 250 nails to pass next floor?'})
    node:addChildKeyword({'yes'}, AssassinFirst, {npcHandler = npcHandler, onlyFocus = true, reset = true})
    node:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Alright then. Come back when you got the neccessary items.', reset = true})
npcHandler:addModule(FocusModule:new())

npc.xml
PHP:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Alex" script="1floor.lua" walkinterval="2000" floorchange="0">
    <health now="100" max="100"/>
    <look type="326" head="110" body="133" legs="54" feet="45" addons="2"/>
    <parameters>
        <parameter key="message_greet" value="Hello |PLAYERNAME|, wanna make {mission} to pass next floor? Or do you need {help} ?"/>
    </parameters>
</npc>

Thanks in advance :)
 
Last edited:
can someone please fix that my npc , i can't even script simple script or fix it good so not even talking about npc.
haters keep hating with bumps :D
 
can someone please fix that my npc , i can't even script simple script or fix it good so not even talking about npc.
haters keep hating with bumps :D
We are not hating on you, we just want to see you make an effort, you posted like 4 scripts in 1 day...

Learning the language is also translated in other languages
Whatever your native tongue is, I am quite sure there is a variation of it, not everything is exclusively english.
 
We are not hating on you, we just want to see you make an effort, you posted like 4 scripts in 1 day...

Learning the language is also translated in other languages
Whatever your native tongue is, I am quite sure there is a variation of it, not everything is exclusively english.
Well we are on forum with is for helping so lets leave chatting in different place please, it wont drive us to ant good target ^^
and mostly you say true, MOSTLY :p
 
Well we are on forum with is for helping so lets leave chatting in different place please, it wont drive us to ant good target ^^
and mostly you say true, MOSTLY :p
You might not like the "help" you receive because it isn't the expected solution, but it is a solution none the less.
 
You might not like the "help" you receive because it isn't the expected solution, but it is a solution none the less.
well i need atlist help to give me good cordinates what to do with explaining, somtimes you explain something but i get like 2% from 100% so im like wtf he meant , its hard to figure out if you don't explain good , im newbiesh why ? since i was making alot of brakes and i got seriuos problems with memory , so if i have 3-5 brake i might forget mostly stuff i did...
 
up , can someone please make this script :) i can gift some rl tibia acc for some script help :)
 
I think the main issue, is the temporary storage.
I realize you want it all inside the npc, but it's simply not practical.
You'll want to create a login script as well, in case the server turns off, or the player logs out.

The way I'm creating it, makes it so the timer will only count-down while the player is online.

As always, untested.. made in a normal notepad at work from memory.

login script
Code:
local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
end

function onLogin(cid)
    if getPlayerStorageValue(cid, storage) > 1 then
        addEvent(tempStorage, 1000, cid)
    end
    return true
end

npc 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 greet(cid)     talkState[cid] = 0     return true   end
function getNpcName()     return getCreatureName(getNpcId())   end

local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
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, "job") then
        selfSay("My job is to show the world how fashionable they can be!", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getNpcName() .. ".", cid)
        talkState[talkUser] = 0

    elseif msgcontains(msg, "ticket") then
        if getPlayerStorageValue(cid, storage) < 1 then
            selfSay("Do you want a thirty minute {temporary} ticket or a {permanent} ticket?", cid)
            talkState[talkUser] = 1
        elseif getPlayerStorageValue(cid, storage) > 1 then
            selfSay("Your temporary ticket is still active.", cid)
            talkState[talkUser] = 0
        elseif getPlayerStorageValue(cid, storage) == 1 then
            selfSay("You already own a permanent ticket! No need to get another.", cid)
            talkState[talkUser] = 0
        end

    elseif msgcontains(msg, "temporary") and talkState[talkUser] == 1 then
        selfSay("Thirty minute temporary tickets require 5 diamonds to purchase. Do you have 5 diamonds?", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
        if getPlayerItemCount(cid, 2145) >= 5 then
            doPlayerRemoveItem(cid, 2145, 5)
            setPlayerStorageValue(cid, storage, 1801)
            addEvent(tempStorage, 1000, cid)
            selfSay("Wonderful. I have equipped you with a temporary ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 5 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "permanent") and talkState[talkUser] == 1 then
        selfSay("Permanent tickets require 500 diamonds to purchase. Do you have 500 diamonds?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 then
        if getPlayerItemCount(cid, 2145) >= 500 then
            doPlayerRemoveItem(cid, 2145, 500)
            setPlayerStorageValue(cid, storage, 1)
            selfSay("Wonderful. I have equipped you with a permanent ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 500 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "") and talkState[talkUser] >= 1 then
        selfSay("Useless. Next!", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)

    else
        selfSay("Hmm? I wasn't listening.", cid)
        talkState[talkUser] = 0
    end

    return true
end

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

-- Edit

Note: There is multiple ways to make an npc / function.
This is just 1 way.

Generally when checking storage, check if players storage is >= 1
 
Last edited:
I think the main issue, is the temporary storage.
I realize you want it all inside the npc, but it's simply not practical.
You'll want to create a login script as well, in case the server turns off, or the player logs out.

The way I'm creating it, makes it so the timer will only count-down while the player is online.

As always, untested.. made in a normal notepad at work from memory.

login script
Code:
local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
end

function onLogin(cid)
    if getPlayerStorageValue(cid, storage) > 1 then
        addEvent(tempStorage, 1000, cid)
    end
    return true
end

npc 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 greet(cid)     talkState[cid] = 0     return true   end
function getNpcName()     return getCreatureName(getNpcId())   end

local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
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, "job") then
        selfSay("My job is to show the world how fashionable they can be!", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getNpcName() .. ".", cid)
        talkState[talkUser] = 0

    elseif msgcontains(msg, "ticket") then
        if getPlayerStorageValue(cid, storage) < 1 then
            selfSay("Do you want a thirty minute {temporary} ticket or a {permanent} ticket?", cid)
            talkState[talkUser] = 1
        elseif getPlayerStorageValue(cid, storage) > 1 then
            selfSay("Your temporary ticket is still active.", cid)
            talkState[talkUser] = 0
        elseif getPlayerStorageValue(cid, storage) == 1 then
            selfSay("You already own a permanent ticket! No need to get another.", cid)
            talkState[talkUser] = 0
        end

    elseif msgcontains(msg, "temporary") and talkState[talkUser] == 1 then
        selfSay("Thirty minute temporary tickets require 5 diamonds to purchase. Do you have 5 diamonds?", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
        if getPlayerItemCount(cid, 2145) >= 5 then
            doPlayerRemoveItem(cid, 2145, 5)
            setPlayerStorageValue(cid, storage, 1801)
            addEvent(tempStorage, 1000, cid)
            selfSay("Wonderful. I have equipped you with a temporary ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 5 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "permanent") and talkState[talkUser] == 1 then
        selfSay("Permanent tickets require 500 diamonds to purchase. Do you have 500 diamonds?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 then
        if getPlayerItemCount(cid, 2145) >= 500 then
            doPlayerRemoveItem(cid, 2145, 500)
            setPlayerStorageValue(cid, storage, 1)
            selfSay("Wonderful. I have equipped you with a permanent ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 500 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "") and talkState[talkUser] >= 1 then
        selfSay("Useless. Next!", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)

    else
        selfSay("Hmm? I wasn't listening.", cid)
        talkState[talkUser] = 0
    end

    return true
end

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

-- Edit

Note: There is multiple ways to make an npc / function.
This is just 1 way.

Generally when checking storage, check if players storage is >= 1
is it for 0.4 ? :) will try it soon :) need eat breakfast so i can eat medicine ;)
 
I think the main issue, is the temporary storage.
I realize you want it all inside the npc, but it's simply not practical.
You'll want to create a login script as well, in case the server turns off, or the player logs out.

The way I'm creating it, makes it so the timer will only count-down while the player is online.

As always, untested.. made in a normal notepad at work from memory.

login script
Code:
local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
end

function onLogin(cid)
    if getPlayerStorageValue(cid, storage) > 1 then
        addEvent(tempStorage, 1000, cid)
    end
    return true
end

npc 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 greet(cid)     talkState[cid] = 0     return true   end
function getNpcName()     return getCreatureName(getNpcId())   end

local storage = 45001

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
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, "job") then
        selfSay("My job is to show the world how fashionable they can be!", cid)
        talkState[talkUser] = 0
    elseif msgcontains(msg, "name") then
        selfSay("My name is " .. getNpcName() .. ".", cid)
        talkState[talkUser] = 0

    elseif msgcontains(msg, "ticket") then
        if getPlayerStorageValue(cid, storage) < 1 then
            selfSay("Do you want a thirty minute {temporary} ticket or a {permanent} ticket?", cid)
            talkState[talkUser] = 1
        elseif getPlayerStorageValue(cid, storage) > 1 then
            selfSay("Your temporary ticket is still active.", cid)
            talkState[talkUser] = 0
        elseif getPlayerStorageValue(cid, storage) == 1 then
            selfSay("You already own a permanent ticket! No need to get another.", cid)
            talkState[talkUser] = 0
        end

    elseif msgcontains(msg, "temporary") and talkState[talkUser] == 1 then
        selfSay("Thirty minute temporary tickets require 5 diamonds to purchase. Do you have 5 diamonds?", cid)
        talkState[talkUser] = 2
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 then
        if getPlayerItemCount(cid, 2145) >= 5 then
            doPlayerRemoveItem(cid, 2145, 5)
            setPlayerStorageValue(cid, storage, 1801)
            addEvent(tempStorage, 1000, cid)
            selfSay("Wonderful. I have equipped you with a temporary ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 5 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "permanent") and talkState[talkUser] == 1 then
        selfSay("Permanent tickets require 500 diamonds to purchase. Do you have 500 diamonds?", cid)
        talkState[talkUser] = 3
    elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 then
        if getPlayerItemCount(cid, 2145) >= 500 then
            doPlayerRemoveItem(cid, 2145, 500)
            setPlayerStorageValue(cid, storage, 1)
            selfSay("Wonderful. I have equipped you with a permanent ticket. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        else
            selfSay("You don't have 500 diamonds on you. Come back when you have the required payment. Next!", cid)
            talkState[talkUser] = 0
            npcHandler:releaseFocus(cid)
        end

    elseif msgcontains(msg, "") and talkState[talkUser] >= 1 then
        selfSay("Useless. Next!", cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)

    else
        selfSay("Hmm? I wasn't listening.", cid)
        talkState[talkUser] = 0
    end

    return true
end

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

-- Edit

Note: There is multiple ways to make an npc / function.
This is just 1 way.

Generally when checking storage, check if players storage is >= 1
what i do i put on creaturescripts.xml and what about login.lua do regisier as event ?
 
can you please explain what this line means , the numbers
setPlayerStorageValue(cid, storage, 1801)
3600 seconds = 1 hour
1800 seconds = 30 minutes

Added 1 to the time, because '1' I reserved for the permanent storage.
 
3600 seconds = 1 hour
1800 seconds = 30 minutes

Added 1 to the time, because '1' I reserved for the permanent storage.
okey atm it looks working well . Thanks alot Xikini , if i could help you somehow gimme hint
 
3600 seconds = 1 hour
1800 seconds = 30 minutes

Added 1 to the time, because '1' I reserved for the permanent storage.

hey adding alot of scripts like this

PHP:
local storage = 6211

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
end

function onLogin(cid)
    if getPlayerStorageValue(cid, storage) > 1 then
        addEvent(tempStorage, 1000, cid)
    end
    return true
end

i need change only Storage id and thats it ? i can leave all other parts on all other npc ? :)
 
hey adding alot of scripts like this

PHP:
local storage = 6211

local function tempStorage(cid)
    if not isPlayer(cid) then
        return true
    end

    if getPlayerStorageValue(cid, storage) > 1 then
        if getPlayerStorageValue(cid, storage) == 2 then
            setPlayerStorageValue(cid, storage, 0)
            return true
        else
            setPlayerStorageValue(cid, storage, getPlayerStorageValue(cid, storage) - 1)
        end
    end

    addEvent(tempStorage, 1000, cid)
end

function onLogin(cid)
    if getPlayerStorageValue(cid, storage) > 1 then
        addEvent(tempStorage, 1000, cid)
    end
    return true
end

i need change only Storage id and thats it ? i can leave all other parts on all other npc ? :)
I suppose so?
 
can you explain please?
I don't know how or why your using it. I can't justify an actual answer if the operation may be unnecessary.
But the way it's scripted, should cause little to no server strain, so it shouldn't be an issue.
 
Back
Top