nevix
Tunzodus.net
Hello today I will present my shop system connected with website and modal window.
first we need shop order table
guys I think it's not hard put your item from shop list to database.
Ok let's start:
first picture:
You got all items with your account which one you buyed from website shop.
when you press take it:
and here is the code:
talkactions:
shop.lua
creaturescripts:
Simple and easy.
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:
You got all items with your account which one you buyed from website shop.
when you press take it:
and here is the code:
talkactions:
Code:
<talkaction words="/shop" separator=" " script="tunzodus/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: