• 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:
i cba to write up npc stuff atm but basically add something like this into ur script
Code:
if message == temporary then
doremoveitem(...)
setstorage
addEvent(setstorage, 30*60*1000, ...)
elseif message == permanent then
demoremoveitem(...)
setstorage
end
 
Code:
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 buyTicket(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
    return false
end

local storage = 1000
local minutes = 30
local item1, item1_amount = 1111, 1
local item2, item2_amount = 1111, 2

if getPlayerStorageValue(cid, storage) + minutes > os.clock() then
return npcHandler:say("You still have access to the assassins.", cid)
end

if player:getItemCount(item1) >= item1_amount and player:getItemCount(item2) >= item2_amount then
    doPlayerRemoveItem(cid, item1, item1_amount)
    doPlayerRemoveItem(cid, item2, item2_amount)
    setPlayerStorageValue(cid, storage, os.clock())
    npcHandler:say("You now have access to the assassins for "..minutes.." minutes.", cid)
    addEvent(removeAccess, 0, cid)

end
end

function removeAccess(cid)
local storage = 1000
local minutes = 30
local exit_pos = {x = 1000, y = 1000, z = 7}

    if getPlayerStorageValue(storage) + minutes < os.clock() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You'r time has run out.")
         if getTilePzInfo(getPlayerPosition(cid)) then
        doTeleportThing(cid, exit_pos) --Teleports the player out of assassins.
        end
    else
        addEvent(removeAccess, 60 * 1000, cid)
    end
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?'})
local node = keywordHandler:addKeyword({'ticket'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to by a ticket for x price?'}) --buy ticket
    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())
 
Last edited:
Thanks i see code , but can you change SO , if Player HAs X or pz or any skull he gets only message but no Tped. to that direction . but if player is in save zone he gets tped to tht location ? :)
 
how i can buy that Storage ? how i edit xml >? becouse therre is no any words to edit or so ?
 
edited my above code
how can change this

11:12 Alex: Do you want to by a ticket for 30 min to acces next floor for 20 tokens?
11:12 Lbtg : yes
11:12 Alex: You don't have 250 nails , you can get them at War Golems!


how i can recieve that i dont have different items then i use ticket/skip ?

and it ansfer same even if i have items for skip/ticket


lua.
Code:
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 buyTicket(cid, message, keywords, parameters, node)
if(not npcHandler:isFocused(cid)) then
    return false
end

local storage = 6211
local minutes = 1
local item1, item1_amount = 6527, 20
local item2, item2_amount = 8309, 5

if getPlayerStorageValue(cid, storage) + minutes > os.clock() then
return npcHandler:say("You still have access to the assassins.", cid)
end

if player:getItemCount(item1) >= item1_amount and player:getItemCount(item2) >= item2_amount then
    doPlayerRemoveItem(cid, item1, item1_amount)
    doPlayerRemoveItem(cid, item2, item2_amount)
    setPlayerStorageValue(cid, storage, os.clock())
    npcHandler:say("You now have access to the assassins for "..minutes.." minutes.", cid)
    addEvent(removeAccess, 0, cid)

end
end

function removeAccess(cid)
local storage = 6211
local minutes = 1
local exit_pos = {x = 997, y = 997, z = 7}

    if getPlayerStorageValue(storage) + minutes < os.clock() then
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You'r time has run out.")
         if getTilePzInfo(getPlayerPosition(cid)) then
        doTeleportThing(cid, exit_pos) --Teleports the player out of assassins.
        end
    else
        addEvent(removeAccess, 1 * 1000, cid)
    end
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?'})
local node = keywordHandler:addKeyword({'skip'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to by a ticket for 30 min to acces next floor for 20 game tokens?'}) --buy ticket
    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())

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} ? you can aswell {skip} the mission for 30 minutes and pass next floor"/>
    </parameters>
</npc>
 
Another thread to give me cancer.
@Itutorial I realise your trying to help, but give the kid some direction..
In the script posted I see 0.2 scripting, 0.3.x/4 scripting and 1.x scripting.
Yeah it works.. (idk how he isn't getting errors though) but seriously, why not just take 2 minutes and convert the garbage to proper and set him in the right direction?
If your unsure,
here is what a normal npc for 0.3.7 looks like. (Edit #2)
 
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, 'soft') or msgcontains(msg, 'boots')) then
        selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerItemCount(cid, 6530) >= 1) then
            if(doPlayerRemoveMoney(cid, 10000)) then
                local item = getPlayerItemById(cid, true, 6530)
                doTransformItem(item.uid, 6132)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        elseif(getPlayerItemCount(cid, 10021) >= 1) then
            if(doPlayerRemoveMoney(cid, 10000)) then
                local item = getPlayerItemById(cid, true, 10021)
                doTransformItem(item.uid, 6132)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        else
            selfSay('Sorry, you don\'t have the item.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
this is the code of an npc straight from 0.3.6 dist, just edit it to suit ur needs :)
 
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, 'soft') or msgcontains(msg, 'boots')) then
        selfSay('Do you want to repair your worn soft boots for 10000 gold coins?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if(getPlayerItemCount(cid, 6530) >= 1) then
            if(doPlayerRemoveMoney(cid, 10000)) then
                local item = getPlayerItemById(cid, true, 6530)
                doTransformItem(item.uid, 6132)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        elseif(getPlayerItemCount(cid, 10021) >= 1) then
            if(doPlayerRemoveMoney(cid, 10000)) then
                local item = getPlayerItemById(cid, true, 10021)
                doTransformItem(item.uid, 6132)
                selfSay('Here you are.', cid)
            else
                selfSay('Sorry, you don\'t have enough gold.', cid)
            end
        else
            selfSay('Sorry, you don\'t have the item.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
this is the code of an npc straight from 0.3.6 dist, just edit it to suit ur needs :)
this aint helping
 
Back
Top