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 asimple 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.
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
I really needed a way to check the player storages and as I could not find a
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? -> {check} -> {remove} or -> {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())
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