Sziasztok.
Hogyan lehet MYSQL bol quest segitségével kiirni pl egy oszlopba mennyi tárgy van ?
ami segitségre van az egy os.execute [ Nincs mysql_query funkciom]
példa :
quest darabbegin
state start begin
when login begin
local darab= os.execute("mysql -u mt2 -pmetin2 account --execute='SELECT darab1 FROM account WHERE id=".. pc.get_account_id() .."';")
local darab2= os.execute("mysql -u mt2 -pmetin2 account --execute='SELECT darab2 FROM account WHERE id=".. pc.get_account_id() .."';")
cmdchat("KillBlauReich "..darab)
cmdchat("KillGelbReich "..darab2)
chat("Pontjaim 1 : ".. darab)
end
end
end
Na ebbe mi a hiba és esetleg hogy lehetne ezt megoldani ki is írja ?
az oszlopok léteznek :D
Köszönöm a segítséget :3
quest darabbegin
Idézetet írta: Reve Dátum 2014-02-18, 19:08:02
quest darabbegin
azon kívül -.-' azt csak itt fórumon írtam el ...
ja, azthittem ctrl+c. Ránézésre nem látok semmit.
Probléma az hogy adjam át annak a cmdchat nek az adott oszlopban lévő számot
pl darab = 30
és ezt cmdchat adja át az értékét amit SQL ből lekérdez :D
Áhh! nem account.accountot kéne az account helyére írni?
a-a
mysql -u mt2 -pmetin2 account
mysql -u [mysql felhasználó] -p[mysql jelszó] [adatbázisnév]
így nézz ki :D
Egyáltalán int-el tér vissza a query?
A táblázat oszlop tipusa csak INT! így nem tud stringel visszatérni :D gondolom én :D
azért van ott a say hogy mit ir ki :/
de nekem csak 0-t ir ki de nem nulla az értéke :/
gondolom tömb kell vagy valami számlálás :/
Sziasztok
tömbbel tér vissza a mysql
(https://board.ddmt2.net/proxy.php?request=http%3A%2F%2Fkepfeltoltes.hu%2Fthumb%2F140218%2Fpontok_www.kepfeltoltes.hu_.jpg&hash=71535c1576cfef0475f57e3d7866429ec4715372) (http://kepfeltoltes.hu/view/140218/pontok_www.kepfeltoltes.hu_.jpg)
A képet a Képfeltöltés.hu tárolja. http://www.kepfeltoltes.hu (http://www.kepfeltoltes.hu)
a quest
quest killstat begin
state start begin
when 3952.chat."Statisztika" begin
local akt_pont = mysql_query("SELECT emp1,emp2,emp3,mob from player.player WHERE player.id ='"..pc.get_player_id().."'")
local Bir1 = akt_pont[1][1]
local Bir2 = akt_pont[1][2]
local Bir3 = akt_pont[1][3]
local Mob = akt_pont[1][4]
setbgimage('004.tga')
say("")
say("")
say_title(" Aktuális pontjaid")
say("")
say("")
-- say("123456789012345678901234567890123456789012345")
csay.indianred(" Ölési Statisztika")
say("")
csay.indianred(" Birodalom 1: "..akt_pont[1][1].." játékost öltél meg")
csay.yellow(" Birodalom 2: "..akt_pont[1][2].." játékost öltél meg")
csay.skyblue(" Birodalom 3: "..akt_pont[1][3].." játékost öltél meg")
csay.burlywood(" Szörnyek: "..akt_pont[1][4].." szörnyet öltél meg")
end
end
end
Azt persze nem tudom, hogy te hol tárolod az adatokat
én a player táblába be az egyszerűség kedvéért
emp1,emp2,emp3,mob : Type :Int , Lenght : 15, Deciamals 0
A mysql_query rész funkciója kellene nekem :/
az nincs meg
Elvileg ez lenne
Idézfunction split(str, delim, maxNb)
if str == nil then return str end
if string.find(str, delim) == nil then return { str } end
if maxNb == nil or maxNb < 1 then maxNb = 0 end
local result = {}
local pat = "(.-)" .. delim .. "()"
local nb = 0
local lastPos
for part, pos in string.gfind(str, pat) do
nb = nb + 1
result[nb] = part
lastPos = pos
if nb == maxNb then break end
end
if nb ~= maxNb then result[nb + 1] = string.sub(str, lastPos) end
return result
end
mysql_query = function(query)
local rt = io.open('CONFIG','r'):read('*all')
local pre= string.gsub(rt,'.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+)%s(%S+).+','-h%1 -u%2 -p%3 -D%4')
math.randomseed(os.time())
local fi,t,out = 'mysql_data_'..math.random(10^9)+math.random(2^4,2^10),{},{}
os.execute('mysql '..pre..' --e='..string.format('%q',query)..' > '..fi)
for av in io.open(fi,'r'):lines() do table.insert(t,split(av,'\t')) end; os.remove(fi);
for i = 2, table.getn(t) do table.foreach(t,function(a,b)
out[i-1] = out[i-1] or {}
out[i-1][a] = b
out[t[1][a]] = out[t[1][a]] or {}
out[t[1][a]][i-1] = b
end) end
return out
end
-- Entferne Leerzeichen vor und nach dem String
function string.trim(str)
return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
end
-- String zu Array über Seperator
function string.explode(str, sep)
if sep == "" or str == "" then
error("Fehlende Parameter")
end
local pos, t = 1, {}
for s, e in function() return string.find(str, sep, pos) end do
table.insert(t, string.trim(string.sub(str, pos, s-1)))
pos = e+1
end
table.insert(t, string.trim(string.sub(str, pos)))
return t
end
de keress rá Mijago - ra, ő irta
közben találtam még...
Idézfunction mysql_query(query,user,pw,db,ip) -- Gibt ALLE Werte als STR zurück. -- Solo per select
local var = {}
var.pre = ''
if ip ~= nil then
var.pre = var.pre..' -h'..ip
end
if user ~= nil then
var.pre = var.pre..' -u'..user
end
if pw ~= nil then
var.pre = var.pre..' -p'..pw
end
if db ~= nil then
var.pre = var.pre..' -D'..db
end
var.scriptfile = 'sc_'..pc.get_name()
var.outputfile = 'op_'..pc.get_name()
query = string.gsub(query,'"',"'")
var.str = "mysql "..var.pre.." < "..var.scriptfile.." > "..var.outputfile
script = io.open(var.scriptfile,"w")
script:write(query)
script:close()
os.execute(var.str)
local g = {}
local f = io.open(var.outputfile)
g.i = 0
g.li={}
g.out= {}
g.count = 0
for line in f:lines() do
g.i = g.i+1
g.li[g.i] = line
end
-- TESTDEBUG
if g.li[1] == nil then
return "ERROR"
end
if string.len(g.li[1]) == 0 then
return "ERROR"
end
-- TESTDEBUG ENDE
-- Abfrage später : if out == "ERROR" then return end << Beispiel!!
g.fields = split(g.li[1],' ')
table.foreachi(g.fields,
function(lb,ln)
g.out[ln] = {}
end)
table.foreachi(g.li,
function(ou1,ou2)
if ou1 > 1 then
local la = split(ou2,' ')
g.count = g.count+1
table.foreachi(g.fields,
function(lb,ln)
g.out[ln][(ou1-1)] = la[lb]
end)
end
end
)
f:close()
-- Alle Strings, die nur Zahlen beinhalten, in Zahlen umwandeln
-- Zeigt gleichzeitig die Nutzungsmöglichkeit vom von mir modifizierten tonumber()
table.foreach(g.out,
function(i,l)
table.foreach(l,
function(i2,l2)
local d,e = tonumber(l2)
if e then
g.out[i2] = d
end
end
)
end
)
g.out.__data = {} -- Zur Ausgabe Queryspezifischer Daten
g.out.__data.fields = g.fields
g.out.__data.lines = g.count
g.out.__data.user = user
g.out.__data.pass = pw
g.out.__data.host = ip
g.out.__data.db = db
g.out.__data.query = query
os.execute("rm "..var.scriptfile)
os.execute("rm "..var.outputfile)
return g.out
end
valameik csak jó lesz :)
És ebből te melyiket használód ? :D
am köszi :D
Ha jól gondolom a másodikat
de sztem ha rákeresel gugliba "mijago epvp" a jót fogja kidobni
rákerestem, jólgondoltam :)
http://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/2059867-r-mysql-function.html (http://www.elitepvpers.com/forum/metin2-pserver-guides-strategies/2059867-r-mysql-function.html)
Köszönöm a segítséget :)