8408323
Hoster
- Joined
- Mar 6, 2009
- Messages
- 432
- Reaction score
- 26
I would like to have some help with a npc.
To be able to buy things from it, you need premiumpoints, which I have added in phpmyadmin
I have made a function for it. I do also have a npc script. The problem that I've encountered is that
when you buy a thing from the npc you don't lost any premiumpoints nor gain any when you sell an item..
Here's the error when you buy a thing from the npc.
Here's the error when you sell a thing to the npc.
Here's the npc script.
Here's function from the "050-function"
If anyone could solve this I would be very grateful! Thanks in advice!
To be able to buy things from it, you need premiumpoints, which I have added in phpmyadmin
I have made a function for it. I do also have a npc script. The problem that I've encountered is that
when you buy a thing from the npc you don't lost any premiumpoints nor gain any when you sell an item..
Here's the error when you buy a thing from the npc.
Code:
[03/05/2012 22:11:43] [Error - Npc interface]
[03/05/2012 22:11:43] (Unknown script file)
[03/05/2012 22:11:43] Description:
[03/05/2012 22:11:43] data/lib/050-function.lua:713: attempt to call field 'query' (a nil value)
[03/05/2012 22:11:43] stack traceback:
[03/05/2012 22:11:43] data/lib/050-function.lua:713: in function 'doAccountRemovePremiumPoints'
[03/05/2012 22:11:43] data/npc/scripts/donation shop.lua:101: in function <data/npc/scripts/donation shop.lua:89>
Here's the error when you sell a thing to the npc.
Code:
[03/05/2012 22:12:07] [Error - Npc interface]
[03/05/2012 22:12:07] (Unknown script file)
[03/05/2012 22:12:07] Description:
[03/05/2012 22:12:07] data/lib/050-function.lua:709: attempt to call field 'query' (a nil value)
[03/05/2012 22:12:07] stack traceback:
[03/05/2012 22:12:07] data/lib/050-function.lua:709: in function 'doAccountAddPremiumPoints'
[03/05/2012 22:12:07] data/npc/scripts/donation shop.lua:122: in function <data/npc/scripts/donation shop.lua:113>
Here's the npc script.
Lua:
local focuses = {}
local function isFocused(cid)
for i, v in pairs(focuses) do
if(v == cid) then
return true
end
end
return false
end
local function addFocus(cid)
if(not isFocused(cid)) then
table.insert(focuses, cid)
end
end
local function removeFocus(cid)
for i, v in pairs(focuses) do
if(v == cid) then
table.remove(focuses, i)
break
end
end
end
local function lookAtFocus()
for i, v in pairs(focuses) do
if(isPlayer(v)) then
doNpcSetCreatureFocus(v)
return
end
end
doNpcSetCreatureFocus(0)
end
local itemWindow = {
{id=2157, subType=0, buy=1, sell=0, name="Goldnuggets Buyprice:5P", Bpoints = 5, Spoints = 0},
{id=7958, subType=0, buy=1, sell=0, name="Donation Wand Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7958, subType=0, buy=0, sell=1, name="Donation Wand Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7426, subType=0, buy=1, sell=0, name="Donation Rod Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7426, subType=0, buy=0, sell=1, name="Donation Rod Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7427, subType=0, buy=1, sell=0, name="Donation Club Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7427, subType=0, buy=0, sell=1, name="Donation Club Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7438, subType=0, buy=1, sell=0, name="Donation Bow Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7438, subType=0, buy=0, sell=1, name="Donation Bow Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7435, subType=0, buy=1, sell=0, name="Donation Axe Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7435, subType=0, buy=0, sell=1, name="Donation Axe Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7416, subType=0, buy=1, sell=0, name="Donation Sword Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7416, subType=0, buy=0, sell=1, name="Donation Sword Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=7461, subType=0, buy=1, sell=0, name="Donation Helmet Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=7461, subType=0, buy=0, sell=1, name="Donation Helmet Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=2507, subType=0, buy=1, sell=0, name="Donation Legs Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=2507, subType=0, buy=0, sell=1, name="Donation Legs Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=5907, subType=0, buy=1, sell=0, name="Donation Slingshot Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=5907, subType=0, buy=0, sell=1, name="Donation Slingshot Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=9932, subType=0, buy=1, sell=0, name="Donation Fire Boots Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=9932, subType=0, buy=0, sell=1, name="Donation Fire Boots Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=2505, subType=0, buy=1, sell=0, name="Donation Armor Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=2505, subType=0, buy=0, sell=1, name="Donation Armor Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=2352, subType=0, buy=1, sell=0, name="Donation Arrow Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=2352, subType=0, buy=0, sell=1, name="Donation Arrow Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=2358, subType=0, buy=1, sell=0, name="Donation Speed Boots Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=2358, subType=0, buy=0, sell=1, name="Donation Speed Boots Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=3975, subType=0, buy=1, sell=0, name="Donation Shield Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=3975, subType=0, buy=0, sell=1, name="Donation Shield Sellprice:10P", Bpoints = 20, Spoints = 10},
{id=6529, subType=0, buy=1, sell=0, name="Donation Bolt Buyprice:20P", Bpoints = 20, Spoints = 10},
{id=6529, subType=0, buy=0, sell=1, name="Donation Bolt Sellprice:10P", Bpoints = 20, Spoints = 10}
}
--{id=5785, subType=0, buy=1, sell=0, name="10P", Bpoints = 10, Spoints = 5},
--{id=5785, subType=0, buy=0, sell=1, name="5P", Bpoints = 10, Spoints = 5}
local items = {}
for _, item in ipairs(itemWindow) do
items[item.id] = {
buyPrice = item.buy,
sellPrice = item.sell,
subType = item.subType,
realName = item.name,
Bpoints = item.Bpoints or 0,
Spoints = item.Spoints or 0
}
end
local function getPlayerMoney(cid)
return getAccountPremiumPoints(cid)
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if(items[item] == nil) then
selfSay("Ehm.. sorry... this shouldn't be there, I'm not selling it.", cid)
return
end
if(getPlayerMoney(cid) >= amount * items[item].Bpoints) then
if(getPlayerFreeCap(cid) >= getItemWeightById(item,amount)) then
local new_item = doCreateItemEx(item, amount)
local received_item = doPlayerAddItemEx(cid, new_item)
if received_item == RETURNVALUE_NOERROR then
selfSay("Thanks for the money!", cid)
doAccountRemovePremiumPoints(cid, amount * items[item].Bpoints)
else
selfSay("You have no space for this item!", cid)
end
else
selfSay("You can't carry this!", cid)
end
else
selfSay("Buy more premium points at {www.goblinsfoe.no-ip.org}", cid)
end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if(items[item] == nil) then
selfSay("Ehm.. sorry... this shouldn't be there, I'm not buying it.", cid)
end
if(subType < 1) then
subType = -1
end
if(doPlayerRemoveItem(cid, item, amount, subType)) then
doAccountAddPremiumPoints(cid, items[item].Spoints * amount)
selfSay("Here you are.", cid)
else
selfSay("No item, no deal.", cid)
end
end
function onCreatureAppear(cid)
end
function onCreatureDisappear(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
removeFocus(cid)
if(isPlayer(cid)) then --Be sure he's online
closeShopWindow(cid)
end
end
end
function onCreatureSay(cid, type, msg)
if((msg == "hi") and not (isFocused(cid))) then
selfSay("Welcome, ".. getCreatureName(cid) ..".", cid, true)
selfSay("Do you want to see my {wares}?", cid)
addFocus(cid)
elseif((isFocused(cid)) and (msg == "wares" or msg == "trade")) then
selfSay("Pretty nice, right?", cid)
openShopWindow(cid, itemWindow, onBuy, onSell)
elseif((isFocused(cid)) and (msg == "bye" or msg == "goodbye" or msg == "cya")) then
selfSay("Goodbye!", cid, true)
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerCloseChannel(cid)
if(isFocused(cid)) then
selfSay("Hmph!")
closeShopWindow(cid)
removeFocus(cid)
end
end
function onPlayerEndTrade(cid)
selfSay("It was a pleasure doing business with you.", cid)
end
function onThink()
for i, focus in pairs(focuses) do
if(not isCreature(focus)) then
removeFocus(focus)
else
local distance = getDistanceTo(focus) or -1
if((distance > 4) or (distance == -1)) then
selfSay("Hmph!")
closeShopWindow(focus)
removeFocus(focus)
end
end
end
lookAtFocus()
end
Here's function from the "050-function"
Lua:
-- Premium Points
function getAccountPremiumPoints(cid)
local res = db.getResult('select `premium_points` from accounts where name = \''..getPlayerAccount(cid)..'\'')
if(res:getID() == -1) then
return 0
end
local ret = res:getDataInt("premium_points")
res:free()
return tonumber(ret)
end
function doAccountAddPremiumPoints(cid, count)
return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPremiumPoints(cid) + count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end
function doAccountRemovePremiumPoints(cid, count)
return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPremiumPoints(cid) - count .."' WHERE `name` ='"..getPlayerAccount(cid).."'")
end
If anyone could solve this I would be very grateful! Thanks in advice!