alejandro762
Well-Known Member
- Joined
- Sep 6, 2021
- Messages
- 225
- Reaction score
- 64
Hello,
I Wanted to know if is possible to call a table DB value (numbers) on a Npc in order to sell Items for this currency from Db.
We want change
This is the part, buy/sell, changing getCurrency for example to get local dbTable = db.query.. But is giving an error "player" nil value.
we don't know how to use db.query and manage to try it working,
If someone can explain me please,
Thanks
I Wanted to know if is possible to call a table DB value (numbers) on a Npc in order to sell Items for this currency from Db.
We want change
if player:additem
into calling DB table `account` WHERE `coins`
, following amount* itemsTable[item].sell, amount* itemsTable[item].sell) then
if player:addItem(38840, amount* itemsTable[item].sell, amount* itemsTable[item].sell) then
return player:sendTextMessage(MESSAGE_TRADE,
"Sell "..amount.."x "..itemsTable[item].name.." for "..itemsTable[item].name..".")
end
This is the part, buy/sell, changing getCurrency for example to get local dbTable = db.query.. But is giving an error "player" nil value.
Lua:
local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
local player = Player(cid)
local itemsTable = setNewTradeTable(shop)
if not ignoreCap and player:getFreeCapacity() < ItemType(itemsTable[item].id):getWeight(amount) then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough cap.")
end
if itemsTable[item].buy then
if player:removeItem(Npc():getCurrency(), amount * itemsTable[item].buy) then
if amount > 1 then
currencyName = ItemType(Npc():getCurrency()):getPluralName():lower()
else
currencyName = ItemType(Npc():getCurrency()):getName():lower()
end
player:addItem(itemsTable[item].id, amount)
return player:sendTextMessage(MESSAGE_INFO_DESCR,
"Bought "..amount.."x "..itemsTable[item].name.." for "..itemsTable[item].buy * amount.." "..currencyName..".")
else
return player:sendTextMessage(MESSAGE_INFO_DESCR, "You don't have enough "..currencyName..".")
end
end
end
local function onSell(cid, item, subType, amount, ignoreCap, inBackpacks)
local player = Player(cid)
local itemsTable = setNewTradeTable(shop)
if not ignoreCap and player:getFreeCapacity() < ItemType(itemsTable[item].id):getWeight(amount) then
return player:sendTextMessage(MESSAGE_FAILURE, "You don't have enough cap.")
end
if player:removeItem(item, amount, 1, amount* itemsTable[item].sell) then
end
if player:addItem(38840, amount* itemsTable[item].sell, amount* itemsTable[item].sell) then
return player:sendTextMessage(MESSAGE_TRADE,
"Sell "..amount.."x "..itemsTable[item].name.." for "..itemsTable[item].name..".")
end
return true
end
we don't know how to use db.query and manage to try it working,
If someone can explain me please,
Thanks
Last edited: