3li Xiber
Active Member
- Joined
- Dec 29, 2014
- Messages
- 395
- Reaction score
- 31
tfs 0.3.6
its Npc Who Take items and give points.
I use script from @Jotran and i need edit it
so every account can make only 4 changes from the npc
its Npc Who Take items and give points.
I use script from @Jotran and i need edit it
so every account can make only 4 changes from the npc
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local t = {}
-- this will allow you to use 1 item or 100 or more items, its good to have flexible code :)
local item = {
{id = 6527, count = 150}, -- 1st item
{id = 6527, count = 150} -- 2nd item
}
local points = 5 -- amount of premium points
function removeItems(cid, item)
if type(item) == "table" then -- make sure item is a table
for index = 1, #item do
if getPlayerItemCount(cid, item[index].id) == item[index].count then
-- do nothing, we want to make sure the player has all the items needed before we remove them
else
return false -- if they don't have the required amount then return false
end
end
for i = 1, #item do -- now remove them
doPlayerRemoveItem(cid, item[i].id, item[i].count)
end
return true -- return true if all the items have been removed
end
end
function getItemsCountAndNames(item)
local names = {}
for i = 1, #item do
names[i] = item[i].count.." of ".. getItemNameById(item[i].id).." "
end
return table.concat(names)
end
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
elseif msgcontains(msg, 'change') then
selfSay('are you sure you want to change '..getItemsCountAndNames(item) ..'for '.. points ..' premium points?', cid)
t[cid] = 1
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if removeItems(cid, item) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. getItemsCountAndNames(item) ..'to recieve '.. points ..' premium points', cid)
end
end
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())