• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Tfs 1.2] Shop system MODAL window

nevix

Tunzodus.net
Joined
Mar 31, 2010
Messages
356
Reaction score
62
Location
Lithuanian
Hello today I will present my shop system connected with website and modal window.

first we need shop order table

Code:
CREATE TABLE `shop_orders` (
`id` int(11) NOT NULL,
  `account_id` int(11) NOT NULL,
  `type` int(11) NOT NULL,
  `itemid` int(11) NOT NULL,
  `count` int(11) NOT NULL,
  `time` int(11) NOT NULL DEFAULT '0'
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

guys I think it's not hard put your item from shop list to database.

Ok let's start:

first picture:
jTSyGiARj.png


You got all items with your account which one you buyed from website shop.
when you press take it:

ii4QGGay0.png


and here is the code:
talkactions:
Code:
<talkaction words="/shop" separator=" " script="tunzodus/shop.lua" />
shop.lua
Code:
function onSay(player, words, param)
local function ucfirst(str)
  return (str:gsub("^%l", string.upper))
end
local my_db = db.storeQuery("SELECT `id`, `type`, `itemid`, `count` FROM `shop_orders` WHERE `account_id` = " .. player:getAccountId() .. "")
player:registerEvent('shop')

local title = "- SHOP LIST -"
local townas = player:getTown()
local name = townas:getName()

local message = "----------------------------------------\nYou have some items from website shop, when you press\ntake it you will get a parcel in your town ("..name..").\n\n----------------------------------------\n"
local my_window = ModalWindow(4, title, message)

if my_db == false then
return player:sendTextMessage(MESSAGE_INFO_DESCR,"You don't have any orders.")
end

if my_db ~= false then
local suma = 0
repeat

local id = result.getDataInt(my_db, "itemid")
local choiceid = result.getDataInt(my_db, "id")
suma = suma + 1

if (ItemType(id):getAttack() > 0) and (ItemType(id):getDefense() > 0) then

my_window:addChoice(choiceid,''..suma..'. '..ucfirst(ItemType(id):getName())..'  (Atk: '..ItemType(id):getAttack()..'  |  Def: '..ItemType(id):getDefense()..')')
elseif ItemType(id):getArmor() then
my_window:addChoice(choiceid,''..suma..'. '..ucfirst(ItemType(id):getName())..'  (Arm: '..ItemType(id):getArmor()..')')
else
my_window:addChoice(choiceid,''..suma..'. '..ucfirst(ItemType(id):getName()))
end

until not result.next(my_db)
result.free(my_db)

my_window:addButton(1,'Take it')
my_window:addButton(2,'Exit')
my_window:sendToPlayer(player)
end
end

creaturescripts:
Code:
<event type="modalwindow" name="shop" script="tunzodus/shop.lua"/>

Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
local function ucfirst(str)
return (str:gsub("^%l", string.upper))
end
if modalWindowId == 4 then
player:unregisterEvent('shop')

if buttonId == 1 then
local my_db = db.storeQuery("SELECT `id`, `account_id`, `type`, `itemid`, `count` FROM `shop_orders` WHERE `id` = " .. choiceId .. "")
local id = result.getDataInt(my_db, "itemid")
local acc_id = result.getDataInt(my_db, "account_id")
local count = result.getDataInt(my_db, "count")

if my_db ~= false and player:getAccountId() == acc_id then
local townas = player:getTown()
local name = townas:getName()
player:sendTextMessage(MESSAGE_INFO_DESCR,'You got a parcel with: '..ucfirst(ItemType(id):getName())..', it is in ('..name..') depot.')
local container = Game.createItem(2595, 1)
local label = container:addItem(2599, 1)
container:addItem(id, count)
label:setAttribute(ITEM_ATTRIBUTE_TEXT, ''..player:getName()..'\n'..name..'')
container:moveTo(Position(32350,32222,7))
db.query("DELETE FROM `shop_orders` WHERE `id` = " .. choiceId .. ";")
end
--BUTTON ID END
end
--
if buttonId == 2 then
return false
end
--MODAL ID END
end
--
end

Simple and easy.
 
Last edited:
Which shop does it support, and how is it suppose to get items into your db table, since there's no connection to any of the AAC's ?
 
Gesior ACC, ZNOTE ACC, its simple configure everywhere
 
Last edited:
So basicly, to make it work properly, we need to disable the normal (gesior) sending-item script ?
 
item bought on site -> added to database -> conversion from db entry to item -> removing db entry

Yes, you need to change default script to this.
Make sure it's compatible with your aac shop system.
 
what purpose does the database have?
Isn't it better to simply make metatable?
 
oh now I get it xD

Kinda weird.
So player has to buy item from shop and then confirm that he bough the item in game to get it. Why just not send the parcel to mailbox already?
 
oh now I get it xD

Kinda weird.
So player has to buy item from shop and then confirm that he bough the item in game to get it. Why just not send the parcel to mailbox already?
Shouldn't the players have the option of choosing with which character wants to claim the item?
 
Shouldn't the players have the option of choosing with which character wants to claim the item?
Hmm, I see, well would have been much easier to choose the character to send item to in the webshop.
Or propably a TFS part to make mailbox global troughout the account.
 
Back
Top