• 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 Storage checker NPC "Removedemon"

Jaki Maoh

Member
Joined
Sep 13, 2017
Messages
52
Reaction score
12
Hello community!

I really needed a way to check the player storages and as I could not find a simple way to do that, ended up creating this NPC that has helped me a lot already.
If anyone is interested in doing some quest or really any kind of script that uses storages, this could be handy.

XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Removedemon" script="removedemon.lua" walkinterval="1000" speed ="6666" floorchange="0" speechbubble="1">
    <health now="100" max="100" />
    <look type="35" head="78" body="118" legs="116" feet="114" addons="1" />
    <parameters>
        <parameter key="message_greet" value="Hello {|PLAYERNAME|}, the almighty! How may I be of service? &#13;&#10;-> {check} &#13;&#10;-> {remove} &#13;&#10;or &#13;&#10;-> {set}?" />
        <parameter key="message_walkaway" value="Good to be of help!" />
        <parameter key="message_farewell" value="Keep on the good work!" />
    </parameters>
</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 function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    
local storage = 1000

    if msgcontains(msg, "remove") then
        if Player(cid):getStorageValue(storage) == 0 then
            npcHandler:say("Your ID ("..storage..") is already removed!", cid)
        else
            Player(cid):setStorageValue(storage, -1)
            npcHandler:say("Done! Your ID ("..storage..") was removed!", cid)
        end
    elseif msgcontains(msg, "set") then
        if Player(cid):getStorageValue(storage) ~= 1 then
            Player(cid):setStorageValue(storage, 1)
            npcHandler:say("Your ID ("..storage..") was set to 1!", cid)
        else
            ncHandler:say("Your ID ("..storage..") is already set to 1!", cid)
        end
    elseif msgcontains(msg, "time") then
        Player(cid):setStorageValue(storage, os.time())
        npcHandler:say("Your ID ("..storage..") was set to "..os.time().."!", cid)
    elseif msgcontains(msg, "check") then
        npcHandler:say("Your ID ("..storage..") is "..Player(cid):getStorageValue(storage)..".", cid)
    elseif msgcontains(msg, "add") then
        Player(cid):setStorageValue(storage, Player(cid):getStorageValue(storage) + 1)
        npcHandler:say("Your ID ("..storage..") is now "..Player(cid):getStorageValue(storage).."!", cid)
    elseif msgcontains(msg, "sub") then
        Player(cid):setStorageValue(storage, Player(cid):getStorageValue(storage) - 1)
        npcHandler:say("Your ID ("..storage..") is now "..Player(cid):getStorageValue(storage).."!", cid)   
    end
end

npcHandler:setCallback(CALLBACK_ONADDFOCUS, onAddFocus)
npcHandler:setCallback(CALLBACK_ONRELEASEFOCUS, onReleaseFocus)

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
1635543218569.png

I'd like to say thanks for all the support so far, I learned a lot already and this is my first contribution to all of you:).

PS.: Still if anyone could come up with a better way to simplify or enhance the code it would be great!

Best regards,
Jaki
 
Lua:
local talkaction = TalkAction("!cs")

function talkaction.onSay(player, words, param, type)
    local storage_id = tonumber(param)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "storage value: " .. player:getStorageValue(storage_id))
    return true
end

talkaction:separator(" ")
talkaction:register()

usage: !cs 3123

should work
 
This is a nice contribution good stuff. Hope you learned a heap along the way to create some more :)

Another great way to do this is to use Zbizu's Lua script channel.

Havn't tested it on latest TFS but imagine it would still work.
 
Back
Top