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 config = {
[1] = {soul = 150,nuggets = 250, PP = 1},
[2] = {soul = 150,nuggets = 250, PP = 5},
[3] = {soul = 150,nuggets = 250, PP = 7},
[4] = {soul = 150,nuggets = 250, PP = 8}
--[5] = {soul needed, nuggets needed, reward premium points}
}
local Storage = 9910
local maxStorage = 4
local itemId = {5550,2157} -- item id of Soul, Item id of nuggets
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
doPlayerSetStorageValue(cid, Storage, getPlayerStorageValue(cid,Storage) <= 0 and 1 or getPlayerStorageValue(cid,Storage))
local s = config[getPlayerStorageValue(cid,Storage)]
if getPlayerStorageValue(cid,Storage) >= 4 then
selfSay("You Can not Trade anymore", cid)
return true
end
if msgcontains(msg, 'trade') then
if s then
selfSay("Do You want to recieve "..s.PP.." Premium Points for "..s.soul.." soul Orb and "..s.nuggets.." Gold nuggets?", cid)
talkState[talkUser] = 2
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 2 then
if s then
if getPlayerItemCount(cid, itemId[1]) >= s.soul and getPlayerItemCount(cid, itemId[2]) >= s.nuggets then
doPlayerRemoveItem(cid, itemId[1],s.soul)
doPlayerRemoveItem(cid, itemId[2],s.nuggets)
selfSay("Congratulation, You now can enjoy your "..s.PP.." Premium Points.", cid)
db.executeQuery("UPDATE `accounts` SET `premium_points` = `premium_points` + '" .. s.PP .. "' WHERE id = '" ..getPlayerAccountId(cid) .. "';")
if getPlayerStorageValue(cid,Storage) < maxStorage then
doPlayerSetStorageValue(cid, Storage, getPlayerStorageValue(cid,Storage) + 1)
end
else
selfSay("You Dont have the needed items..", cid)
end
else
selfSay("You dont have any availability to trade", cid)
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())