ich Release mal meinen Ingame-Voteshop den man auch ganz easy durchs umbenennen als einen normalen Itemshop nutzen kann.
Vorteile :
-Falls die Homepage down ist kann man den Itemshop immer noch nutzen
-Live änderbar da es mit MySQL fungiert
Quest :
PHP Code:
quest user_vote_shop begin
state start begin
when 9005.chat."Ingame Vote-Shop" begin
say_title(string.format("Vote-Shop(%d Coins)", GetVoteCoins()))
say()
say("Was möchtest du bei mir kaufen?")
say()
local a = select_table(LoadVoteShopCat())
if a == table.getn(LoadVoteShopCat()) then return end
local tab_items, tab_price = {5}, {}
local query01 = mysql_query("SELECT vnum, price FROM account.vote_shop WHERE art= "..a..";")
for b = 1, table.getn(query01) do
table.insert(tab_items, tostring(item_name(query01[b][1]).." Preis("..query01[b][2]..")"))
end
table.insert(tab_items, "Abbrechen")
say_title(string.format("Vote-Shop(%d Coins)", GetVoteCoins()))
say()
say("Wähle nun das Item aus:")
say()
local c = select2(tab_items)
if c == table.getn(tab_items) then return end
say_title(string.format("Vote-Shop(%d Coins)", GetVoteCoins()))
say()
say("Du möchtest also:")
say_item_vnum(query01[c][1])
say()
say()
if select("Ja für "..query01[c][2], "Abbrechen") == 2 then return end
if GetVoteCoins() < query01[c][2] then return chat("Du hast zu wenig Vote-Coins!") end
SetVoteCoins(-query01[c][2])
pc.give_item2(query01[c][1])
end
end
end
In die Questlib :
PHP Code:
function GetVoteCoins()
return mysql_query("SELECT vote_coins FROM account.account WHERE id = "..pc.get_account_id().." LIMIT 1;")[1][1]
end
function SetVoteCoins(sum)
if mysql_query("UPDATE account.account SET vote_coins = vote_coins+"..sum.." WHERE id = "..pc.get_account_id().." LIMIT 1;") then
return true
else
return false
end
end
function LoadVoteShopCat()
local a_b = {}
local query = mysql_query("SELECT kat, name FROM account.vote_shop_cat ORDER by kat;")
for a = 1, table.getn(query) do
table.insert(a_b, query[a][2])
end
table.insert(a_b, "Abbrechen")
return a_b
end
function select2(tab,...)
arg.n = nil
if type(tab) ~= "table" and type(tab) == 'number' then
table.insert(arg,1,tab)
tab = arg
elseif type(tab) ~= "table" and type(tab) == 'string' then
table.insert(arg,1,tab)
table.insert(arg,1,8)
tab = arg
elseif type(tab) == "table" and type(tab[1]) == 'string' then
table.insert(tab,1,8)
end
local max = tab[1]; table.remove(tab,1)
local tablen,outputstr,outputcount,nextc,incit = table.getn(tab),"",0,0,0
table.foreach(tab,
function(i,l)
outputcount = outputcount + 1
if outputcount == 1 then
outputstr=outputstr..'sel = select("'..l..'"'
elseif outputcount == max and tablen > outputcount+incit then
if tablen ~= outputcount+incit+1 then
outputstr=outputstr..',"'..l..'","Nächste Seite") + '..incit..' '
if nextc > 0 then
outputstr = outputstr..'end '
end
outputstr=outputstr..'; if sel == '..(incit+max+1)..' then '
nextc, outputcount, incit= nextc+1,0,incit+max
else
outputstr=outputstr..',"'..l..'"'
end
else
outputstr=outputstr..',"'..l..'"'
end
end
)
outputstr = outputstr..') + '..incit
if nextc > 0 then
outputstr = outputstr..' end'
end
outputstr= outputstr.. '; return sel'
print(outputstr)
local sel = assert(loadstring(outputstr))()
tablen,outputstr,outputcount,nextc,incit = nil,nil,nil,nil,nil
return sel
end
SQL :
PHP Code:
CREATE TABLE `vote_shop` (
`id` int(10) NOT NULL DEFAULT '0',
`vnum` int(10) NOT NULL,
`price` int(10) NOT NULL,
`art` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `vote_shop_cat` (
`id` int(10) NOT NULL DEFAULT '0',
`kat` int(10) NOT NULL,
`name` varchar(20) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Zudem müsst ihr noch in der Account-Tabelle eine weitere Spalte Namens "vote_coins" erstellen.