Ich möchte gerne den mysql_query befehl nutzen.. jedoch komme ich nicht weiter, deshalb brauche ich eure Hilfe.
Was muss ich noch tun, damit es funktioniert..
Wollte das Premiumsystem einfügen und irgendwie aus welchem Grund auch immer will das nicht funktionieren, weil das System kein Zugriff auf die DB hat.
Info:
mysql_query("UPDATE player.player SET name = '"[VIP]"..pc.get_name().."' WHERE name = '"..pc.get_name().."';")
--quest.create = function(f) return coroutine.create(f) end
--quest.process = function(co,args) return coroutine.resume(co, args) end
setstate = q.setstate
newstate = q.setstate
q.set_clock = function(name, value) q.set_clock_name(name) q.set_clock_value(value) end
q.set_counter = function(name, value) q.set_counter_name(name) q.set_counter_value(value) end
c_item_name = function(vnum) return ("[ITEM value;"..vnum.."]") end
c_mob_name = function(vnum) return ("[MOB value;"..vnum.."]") end
-- d.set_folder = function (path) raw_script("[SET_PATH path;"..path.."]") end
-- d.set_folder = function (path) path.show_cinematic("[SET_PATH path;"..path.."]") end
-- party.run_cinematic = function (path) party.show_cinematic("[RUN_CINEMATIC value;"..path.."]") end
newline = "[ENTER]"
function color256(r, g, b) return "[COLOR r;"..(r/255.0).."|g;"..(g/255.0).."|b;"..(b/255.0).."]" end
function color(r,g,b) return "[COLOR r;"..r.."|g;"..g.."|b;"..b.."]" end
function delay(v) return "[DELAY value;"..v.."]" end
function setcolor(r,g,b) raw_script(color(r,g,b)) end
function setdelay(v) raw_script(delay(v)) end
function resetcolor(r,g,b) raw_script("[/COLOR]") end
function resetdelay(v) raw_script("[/DELAY]") end
-- minimap에 동그라미 표시
function addmapsignal(x,y) raw_script("[ADDMAPSIGNAL x;"..x.."|y;"..y.."]") end
-- minimap 동그라미들 모두 클리어
function clearmapsignal() raw_script("[CLEARMAPSIGNAL]") end
-- 클라이언트에서 보여줄 대화창 배경 그림을 정한다.
function setbgimage(src) raw_script("[BGIMAGE src;") raw_script(src) raw_script("]") end
-- 대화창에 이미지를 보여준다.
function addimage(x,y,src) raw_script("[IMAGE x;"..x.."|y;"..y) raw_script("|src;") raw_script(src) raw_script("]") end
function makequestbutton(name)
raw_script("[QUESTBUTTON idx;")
raw_script(""..q.getcurrentquestindex())
raw_script("|name;")
raw_script(name) raw_script("]")
end
function make_quest_button_ex(name, icon_type, icon_name)
test_chat(icon_type)
test_chat(icon_name)
raw_script("[QUESTBUTTON idx;")
raw_script(""..q.getcurrentquestindex())
raw_script("|name;")
raw_script(name)
raw_script("|icon_type;")
raw_script(icon_type)
raw_script("|icon_name;")
raw_script(icon_name)
raw_script("]")
end
-- Levelbegrenzungen
local lvl = {35, 65, 99}
----
local k=0
for i=1, 3 do
if level<=lvl[i] and k==0 then
k = i
end
end
for i=1, table.getn(mobs[k]) do
for p=mobs[k][i][1], mobs[k][i][2] do
if vnum==p then
return true
end
end
end
for p=metin[k][1], metin[k][2] do
if vnum==p then
return true
end
end
return false
end
function make_quest_button(name) makequestbutton(name) end
function send_letter_ex(name, icon_type, icon_name) make_quest_button_ex(name, icon_type, icon_name) setskin(NOWINDOW) q.set_title(name) q.start() end
function send_letter(name) makequestbutton(name) setskin(NOWINDOW) q.set_title(name) q.start() end
function clear_letter() q.done() end
function say_title(name) say(color256(255, 230, 186)..name..color256(196, 196, 196)) end
function say_reward(name) say(color256(255, 200, 200)..name..color256(196, 196, 196)) end
function say_pc_name() say(pc.get_name()..":") end
function say_size(width, height) say("[WINDOW_SIZE width;"..width.."|height;"..height.."]") end
function setmapcenterposition(x,y)
raw_script("[SETCMAPPOS x;")
raw_script(x.."|y;")
raw_script(y.."]")
end
function say_item(name, vnum, desc)
say("[INSERT_IMAGE image_type;item|idx;"..vnum.."|title;"..name.."|de sc;"..desc.."]")
end
function say_item_vnum(vnum)
say_item(item_name(vnum), vnum, "")
end
function setvarchar(name, var)
local laenge = string.len (var)
local setchar = 0
local save_name = 0
local letter = 0
while laenge > setchar do
setchar = setchar + 1
letter = string.sub (var, setchar, setchar)
letter = string.byte(letter, 1)
save_name = ""..name.."_char_"..setchar..""
pc.setqf(save_name, letter)
end
local save_laenge=""..name.."laenge"
pc.setqf(save_laenge, laenge)
end
function getvarchar(name)
local save_laenge = ""..name.."laenge"
local laenge = pc.getqf(save_laenge)
local save_name = 0
local var = ""
local letter = 0
local getchar = 0
while laenge > getchar do
getchar = getchar + 1
save_name = ""..name.."_char_"..getchar..""
letter = pc.getqf(save_name)
if letter!=0 then
letter = string.char(letter)
else
letter = ""
end
var = ""..var..""..letter..""
end
return var
end
function delvarchar(name)
local save_laenge = ""..name.."laenge"
local laenge = pc.getqf(save_laenge)
local getchar = 0
while laenge > getchar do
getchar = getchar + 1
local save_name = ""..name.."_char_"..getchar..""
pc.delqf(save_name)
end
pc.delqf(save_laenge)
end
function global_setvarchar(name, var)
local laenge = string.len (var)
local setchar = 0
local save_name = 0
local letter = 0
while laenge > setchar do
setchar = setchar + 1
letter = string.sub (var, setchar, setchar)
letter = string.byte(letter)
if letter==91 or letter==93 then
letter=32
end
save_name = ""..name.."_char_"..setchar..""
game.set_event_flag(save_name, letter)
end
local save_laenge=""..name.."laenge"
game.set_event_flag(save_laenge, laenge)
end
function global_getvarchar(name)
local save_laenge = ""..name.."laenge"
local laenge = game.get_event_flag(save_laenge)
local save_name = 0
local var = ""
local letter = 0
local getchar = 0
while laenge > getchar do
getchar = getchar + 1
save_name = ""..name.."_char_"..getchar..""
letter = game.get_event_flag(save_name)
if letter!=0 then
letter = string.char(letter)
else
letter = ""
end
var = ""..var..""..letter..""
end
return var
end
function pc_is_novice()
if pc.get_skill_group()==0 then
return true
else
return false
end
end
function pc_get_exp_bonus(exp, text)
say_reward(text)
pc.give_exp2(exp)
set_quest_state("levelup", "run")
end
function pc_get_village_map_index(index)
return village_map[pc.get_empire()][index]
end
village_map = {
{1, 3},
{21, 23},
{41, 43},
}
function npc_is_same_empire()
if pc.get_empire()==npc.empire then
return true
else
return false
end
end
function npc_get_skill_teacher_race(pc_empire, pc_job, sub_job)
if 1==sub_job then
if 0==pc_job then
return WARRIOR1_NPC_LIST[pc_empire]
elseif 1==pc_job then
return ASSASSIN1_NPC_LIST[pc_empire]
elseif 2==pc_job then
return SURA1_NPC_LIST[pc_empire]
elseif 3==pc_job then
return SHAMAN1_NPC_LIST[pc_empire]
end
elseif 2==sub_job then
if 0==pc_job then
return WARRIOR2_NPC_LIST[pc_empire]
elseif 1==pc_job then
return ASSASSIN2_NPC_LIST[pc_empire]
elseif 2==pc_job then
return SURA2_NPC_LIST[pc_empire]
elseif 3==pc_job then
return SHAMAN2_NPC_LIST[pc_empire]
end
end
return 0
end
function pc_find_square_guard_vid()
if pc.get_empire()==1 then
return find_npc_by_vnum(11000)
elseif pc.get_empire()==2 then
return find_npc_by_vnum(11002)
elseif pc.get_empire()==3 then
return find_npc_by_vnum(11004)
end
return 0
end
function pc_find_skill_teacher_vid(sub_job)
local vnum=npc_get_skill_teacher_race(pc.get_empire(), pc.get_job(), sub_job)
return find_npc_by_vnum(vnum)
end
function pc_find_square_guard_vid()
local pc_empire=pc.get_empire()
if pc_empire==1 then
return find_npc_by_vnum(11000)
elseif pc_empire==2 then
return find_npc_by_vnum(11002)
elseif pc_empire==3 then
return find_npc_by_vnum(11004)
end
end
function npc_is_same_job()
local pc_job=pc.get_job()
local npc_vnum=npc.get_race()
-- test_chat("pc.job:"..pc.get_job())
-- test_chat("npc_race:"..npc.get_race())
-- test_chat("pc.skill_group:"..pc.get_skill_group())
if pc_job==0 then
if table_is_in(WARRIOR1_NPC_LIST, npc_vnum) then return true end
if table_is_in(WARRIOR2_NPC_LIST, npc_vnum) then return true end
elseif pc_job==1 then
if table_is_in(ASSASSIN1_NPC_LIST, npc_vnum) then return true end
if table_is_in(ASSASSIN2_NPC_LIST, npc_vnum) then return true end
elseif pc_job==2 then
if table_is_in(SURA1_NPC_LIST, npc_vnum) then return true end
if table_is_in(SURA2_NPC_LIST, npc_vnum) then return true end
elseif pc_job==3 then
if table_is_in(SHAMAN1_NPC_LIST, npc_vnum) then return true end
if table_is_in(SHAMAN2_NPC_LIST, npc_vnum) then return true end
end
return false
end
function npc_get_job()
local npc_vnum=npc.get_race()
if table_is_in(WARRIOR1_NPC_LIST, npc_vnum) then return COND_WARRIOR_1 end
if table_is_in(WARRIOR2_NPC_LIST, npc_vnum) then return COND_WARRIOR_2 end
if table_is_in(ASSASSIN1_NPC_LIST, npc_vnum) then return COND_ASSASSIN_1 end
if table_is_in(ASSASSIN2_NPC_LIST, npc_vnum) then return COND_ASSASSIN_2 end
if table_is_in(SURA1_NPC_LIST, npc_vnum) then return COND_SURA_1 end
if table_is_in(SURA2_NPC_LIST, npc_vnum) then return COND_SURA_2 end
if table_is_in(SHAMAN1_NPC_LIST, npc_vnum) then return COND_SHAMAN_1 end
if table_is_in(SHAMAN2_NPC_LIST, npc_vnum) then return COND_SHAMAN_2 end
return 0
end
function time_min_to_sec(value)
return 60*value
end
function time_hour_to_sec(value)
return 3600*value
end
function next_time_set(value, test_value)
local nextTime=get_time()+value
if is_test_server() then
nextTime=get_time()+test_value
end
pc.setqf("__NEXT_TIME__", nextTime)
end
function next_time_is_now(value)
if get_time()>=pc.getqf("__NEXT_TIME__") then
return true
else
return false
end
end
function table_get_random_item(self)
return self[number(1, table.getn(self))]
end
function table_is_in(self, test)
for i = 1, table.getn(self) do
if self[i]==test then
return true
end
end
return false
end
function giveup_quest_menu(title)
local s=select("진행한다", "포기한다")
if 2==s then
say(title.." 퀘스트를 정말로")
say("포기하시겠습니까?")
local s=select("네, 그렇습니다", "아닙니다")
if 1==s then
say(title.."퀘스트를 포기했습니다")
restart_quest()
end
end
end
function restart_quest()
set_state("start")
q.done()
end
function complete_quest()
set_state("__COMPLETE__")
q.done()
end
function giveup_quest()
set_state("__GIVEUP__")
q.done()
end
function complete_quest_state(state_name)
set_state(state_name)
q.done()
end
function test_chat(log)
if is_test_server() then
chat(log)
end
end
function bool_to_str(is)
if is then
return "true"
else
return "false"
end
end
function skill_group_dialog(e, j, g) -- e = 제국, j = 직업, g = 그룹
e = 1 -- XXX 메시지가 나라별로 있다가 하나로 통합되었음
-- 다른 직업이거나 다른 제국일 경우
if pc.job != j then
say(locale.skill_group.dialog[e][pc.job][3])
elseif pc.get_skill_group() == 0 then
if pc.level < 5 then
say(locale.skill_group.dialog[e][j][g][1])
return
end
say(locale.skill_group.dialog[e][j][g][2])
local answer = select(locale.yes, locale.no)
if answer == 1 then
--say(locale.skill_group.dialog[e][j][g][2])
pc.set_skill_group(g)
else
--say(locale.skill_group.dialog[e][j][g][3])
end
--elseif pc.get_skill_group() == g then
--say(locale.skill_group.dialog[e][j][g][4])
--else
--say(locale.skill_group.dialog[e][j][g][5])
end
end
function show_horse_menu()
if horse.is_mine() then
say(locale.horse_menu.menu)
local s = 0
if horse.is_dead() then
s = select(locale.horse_menu.revive, locale.horse_menu.ride, locale.horse_menu.unsummon, locale.horse_menu.close)
else
s = select(locale.horse_menu.feed, locale.horse_menu.ride, locale.horse_menu.unsummon, locale.horse_menu.close)
end
if s==1 then
if horse.is_dead() then
horse.revive()
else
local food = horse.get_grade() + 50054 - 1
if pc.countitem(food) > 0 then
pc.removeitem(food, 1)
horse.feed()
else
say(locale.need_item_prefix..item_name(food)..loca le.need_item_postfix);
end
end
elseif s==2 then
horse.ride()
elseif s==3 then
horse.unsummon()
elseif s==4 then
-- do nothing
end
end
end
POINT_POISON_PCT = 37 --독 확률
POINT_STUN_PCT = 38 --기절 확률
POINT_SLOW_PCT = 39 --슬로우 확률
POINT_CRITICAL_PCT = 40 --크리티컬 확률
POINT_PENETRATE_PCT = 41 --관통타격 확률
POINT_CURSE_PCT = 42 --저주 확률
-- DEFEND_BONUS_ATTRIBUTES
POINT_SKILL_DEFEND_BONUS = 123 --스킬 방어 데미지
POINT_NORMAL_HIT_DEFEND_BONUS = 124 --평타 방어 데미지
-- END_OF_DEFEND_BONUS_ATTRIBUTES
-- PC_BANG_ITEM_ADD
POINT_PC_BANG_EXP_BONUS = 125 --PC방 전용 경험치 보너스
POINT_PC_BANG_DROP_BONUS = 126 --PC방 전용 드롭률 보너스
-- END_PC_BANG_ITEM_ADD
-- POINT_MAX_NUM = 128 common/length.h
-- point type start
pc.warp_to_pc = function(name)
if name == pc.get_name() then
return -1
end
local vid = find_pc_by_name(name)
if vid == 0 then
return -2
end
local pc_is_gm = pc.is_gm()
local s = pc.select(vid)
if pc.is_gm() and not is_test_server() and not pc_is_gm then
pc.select(s)
return -3
end
local pc_x = pc.get_x()
local pc_y = pc.get_y()
pc.select(s)
local target_x = pc_x*100
local target_y = (pc_y-2)*100
test_chat(target_x..target_y)
pc.warp(target_x, target_y)
return 0
end
pc.transfer = function(name)
if name == pc.get_name() then
return -1
end
local vid = find_pc_by_name(name)
if vid == 0 then
return -2
end
local pc_is_gm = pc.is_gm()
local pc_x = pc.get_x()
local pc_y = pc.get_y()
local s = pc.select(vid)
if pc.is_gm() and not is_test_server() and not pc_is_gm then
pc.select(s)
return -3
end
local target_x = pc_x*100
local target_y = (pc_y-2)*100
test_chat(target_x..target_y)
pc.warp(target_x, target_y)
pc.select(s)
return 0
end
game.transfer_pc_to_pc = function(name1, name2)
if name1 == name2 then
return -1
end
local vid
local s
local pc_name = pc.get_name()
if name2 != pc_name then
vid = find_pc_by_name(name2)
if vid == 0 then
return -2
end
s = pc.select(vid)
end
local pc_x = pc.get_x()
local pc_y = pc.get_y()
if name1 == pc_name then
pc.select(s)
else
vid = find_pc_by_name(name1)
if vid == 0 then
if name2 != pc_name then
pc.select(s)
end
return -3
end
if name2 == pc_name then
s = pc.select(vid)
else
pc.select(vid)
end
end
local target_x = pc_x*100
local target_y = (pc_y-2)*100
test_chat(target_x..target_y)
pc.warp(target_x, target_y)
if name1 != pc_name then
pc.select(s)
end
return 0
end
--Zusatz
function say_item_name(vnum) say_title(item_name(vnum or item.get_vnum())..":") end
function say_npc_name(vnum) say_title(mob_name(vnum or npc.get_race())..":") end
function say_color(color,text)
if color=="blue" then
say(color256(0, 0, 255)..text..color256(196, 196, 196))
elseif color == "green" then
say(color256(0, 255, 0)..text..color256(196, 196, 196))
elseif color == "red" then
say(color256(255, 0, 0)..text..color256(196, 196, 196))
elseif color == "yellow" then
say(color256(255, 255, 0)..text..color256(196, 196, 196))
elseif color == "white" then
say(color256(255, 255, 255)..text..color256(196, 196, 196))
elseif color == "black" then
say(color256(0, 0, 0)..text..color256(196, 196, 196))
elseif color == "cyan" then
say(color256(0, 255, 255)..text..color256(196, 196, 196))
elseif color == "pink" then
say(color256(255, 0, 255)..text..color256(196, 196, 196))
elseif color == "orange" then
say(color256(255, 145, 0)..text..color256(196, 196, 196))
elseif color == "purple" then
say(color256(100, 0, 255)..text..color256(196, 196, 196))
else
say(color256(196, 196, 196)..text..color256(196, 196, 196))
end
end
function select2(tab)
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?hste Seite") + '..incit..' '
if nextc > 0 then
outputstr = outputstr..'end '
end
outputstr=outputstr..'; if sel == '..(incit+max+1)..' then ' -- Anfangen der neuen Abfrage
nextc, outputcount, incit= nextc+1,0,incit+max
else
outputstr=outputstr..',"'..l..'"'
end
elseif tablen == outputcount+incit then
outputstr=outputstr..',"'..l..'"'
else
outputstr=outputstr..',"'..l..'"'
end
end
)
outputstr = outputstr..') + '..incit
if nextc > 0 then
outputstr = outputstr..' end'
end
outputstr= outputstr.. '; return sel'
local sel = assert(loadstring(outputstr))()
tablen,outputstr,outputcount,nextc,incit = nil,nil,nil,nil,nil -- Speicher freimachen
return sel
end
function dofile (filename)
local f = assert(loadfile(filename))
return f()
end
function setenergy(typ,value,timez)
pc.setqf("energy_value", value)
pc.setqf("energy_date", get_time() + timez)
pc.setqf("energy_typ", typ)
end
function setenergytime(timez)
pc.setqf("energy_date", timez)
end
function getenergytyp()
return pc.getqf("energy_typ")
end
function getenergyvalue()
return pc.getqf("energy_value")
end
function getenergytime()
return pc.getqf("energy_date")
end
-- Entferne Leerzeichen vor und nach dem String
function string.trim(str)
return (string.gsub(str, "^%s*(.-)%s*$", "%1"))
end
-- String zu Array ?er 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
--[[
@name split
@author Internet
@descr
Splittet einen String in eine Tabelle.
--]]
function 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
--[[
@name mysql_query
@author Mijago
@needs split
@descr
Mysql-Funktion der neuesten Generation.
--]]
mysql_query = function(query)
if not pre then
local rt = io.open('CONFIG','r'):read('*all')
pre,_= string.gsub(rt,'.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+) %s(%S+).+','-h%1 -u%2 -p%3 -D%4')
end
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[i],function(a,b)
out[i-1] = out[i-1] or {}
out[i-1][a] = tonumber(b) or b or 'NULL'
out[t[1][a]] = out[t[1][a]] or {}
out[t[1][a]][i-1] = tonumber(b) or b or 'NULL'
end) end
out.__lines = t[1]
return out
end
--[[
@name mysql_query_old
@author Mijago
@needs split
@descr
Die Alte Version der MySQL-Query-Funktion.
--]]
function mysql_query_old(query,user,pass,db,ip)
local pre = ''
if query == '' or query == nil then
error("Query muss gesetzt sein!")
end
user = user or ql.mysql["user"]
pass = pass or ql.mysql["pass"]
ip = ip or ql.mysql["ip"]
if user ~= '' and user ~= nil then pre = pre..' -u'..user end
if pass ~= '' and pass ~= nil then pre = pre..' -p'..pass end
if db ~= '' and db ~= nil then pre = pre..' -D'..db end
if ip ~= '' and ip ~= nil then pre = pre..' -h'..ip end
math.randomseed(os.time()); local rand = math.random(0,10^7) -- Erstellen der Pfadvariable
local path = 'data/mysql_output_'..os.time()..'_'..rand..'_'..pc.get_ vid()
os.execute ("mysql "..pre.." --e=\""..query.."\" > "..path) -- Laden und Auflisten der Dateiinhalte
local fi,q = io.open(path,"r"),{["l"] = {},["out"]={}}
if fi == nil then
return "ERROR"
end
for line in fi:lines() do table.insert(q.l,(split(line,"\t"))) end
os.remove(path)
if type(q.l[1]) ~= "table" then
return "ERROR"
--error("Fehler bei der MySQL Verbindung oder bei der Rückgabe! Abbruch!")
end
local ix = 0
table.foreachi(q.l,function(i,l)
if i > 1 then table.foreach(l,function(i2,l2)
if q.out[q.l[1][i2]] == nil then q.out[q.l[1][i2]] = {} end
local c = tonumber(l2)
if type(c) == "number" and l2 == tostring(c) then
q.out[q.l[1][i2]][i-1] = c
else
q.out[q.l[1][i2]][i-1] = l2
end
end) end
end)
-- ENDE der eigentlichen MySQL-Funktion
-- START Zusatz: Hanashi-Kompatibilität & Fehlerbehandlung
q.out.__data = q.l[1]
setmetatable(q.out, { __index = function(a,b)
if type(b) == "number" then
return (a[a.__data[b]] or {"ERROR"})
end
return "ERROR"
--error("Fehler bei Indexierung: Index "..b.." ist nicht vorhanden!")
end})
return q.out
end
--[[
@name duration
@author Mijago
@descr
Gibt die verbleibende Zeit als String zurück.
--]]
function duration(ipe)
local ipe,dat= ipe or 0,''
local s,m,h,d,y = tonumber(os.date('%S',ipe)),
tonumber(os.date('%M',ipe)),
tonumber(os.date('%H',ipe)),
tonumber(os.date('%d',ipe))-1,
tonumber(os.date('%Y',ipe))-1970
print(s,m,h,d,y)
for x,c in {{s,"Sek."},{m,"Min."},{h,"Std."},{d,"Tage"},{Y,"J ahre"}} do
if (c[1] or 0) > 0 then
if x > 1 then dat = ' '..dat end
dat = c[1]..' '..c[2]..dat
end
end
return dat
end
--[[
@name is_number
@author Mijago
@descr
Prüft, ob eine Variable eine Zahl ist.
--]]
function is_number(var)
if (type(var) == "number") then
return true
else
return false
end
end
--[[
@name is_string
@author Mijago
@descr
Prüft, ob eine Variable ein String ist.
--]]
function is_string(var)
if (type(var) == "string") then
return true
else
return false
end
end
--[[
@name is_table
@author Mijago
@descr
Prüft, ob eine Variable eine Tabelle ist.
--]]
function is_table(var)
if (type(var) == "table") then
return true
else
return false
end
end
--[[
@name in_table
@author Mijago
@descr
Prüft, ob eine Variablei in einer Tabelle ist.
Aufruf: in_table(var,table)
--]]
function in_table ( e, t )
for _,v in pairs(t) do
if (v==e) then
return true
end
end
return false
end
--[[
@name numlen
@author Mijago
@descr
Gibt die Anzahl der Ziffern einer Zahl wieder.
--]]
function numlen(num)
return string.len(tostring(num))
end
--[[
@name string.reverse
@author Mijago
@descr
Kehrt einen String um.
--]]
function string.reverse(str)
local se = ''
for i=1,string.len(str) do
se = string.sub(str,i,i)..se
end
return se
end
--[[
@name num_format
@author Mijago; Idee von Benhero
@descr
Formatiert lange Zahlen mit Punkten.
--]]
function num_format(num)
if type(num) == "number" then num = tostring(num) end
if string.len(num) <= 3 then return num end
return string.reverse(string.gsub(string.reverse(num),'(% d%d%d)','%1.'))
end
--[[
@name select2
@author Mijago
@needs split
@descr
Wie Select:
Eine Tabelle oder eine Stringliste wird auf Seiten aufgeteilt.
Weiter und Abbrechen Buttons.
--]]
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 ' -- Anfangen der neuen Abfrage
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 -- Speicher freimachen
return sel
end
--[[
@name select3
@author Mijago
@needs split
@descr
Wie Select2:
Eine Tabelle oder eine Stringliste wird auf Seiten aufgeteilt.
Weiter, Zurück und Abbrechen (-1) Buttons.
--]]
function select3(...)
arg.n = nil
local tp,max = arg,5
if type(tp[1]) == 'number' then
max = tp[1]
if type(tp[2]) == 'table' then
tp = tp[2]
else
table.remove(tp,1)
end
elseif type(tp[1]) == 'table' then
if type(tp[1][1]) == 'number' then
max = tp[1][1]
table.remove(tp[1],1)
tp = tp[1]
end
tp = tp[1]
end
local str = '{'
local tablen,act,incit = table.getn(tp),0,0
table.foreach(tp,function(i,l)
act = act + 1
if act == 1 then
str = str .. '{'..string.format('%q',l)
elseif act == max+1 and tablen > act+incit then
if tablen ~= act+incit+1 then
str = str..'},{'..string.format('%q',l)
else
str=str..','..string.format('%q',l)
end
incit = incit + max
act = 1
else
str=str..','..string.format('%q',l)
end
end)
local px = loadstring('return '..str ..'}}')()
local function copy_tab(t) local p= {} for i = 1,table.getn(t) do p[i] = t[i] end return p end
local pe = {}
for i = 1,table.getn(px) do pe [i] = copy_tab(px[i]) end
local function init(i,ip)
pe[i] = copy_tab(px[i])
local next,back,exit = 0,0,0
if i < table.getn(pe) and table.getn(pe) ~=1 then table.insert(pe[i],table.getn(pe[i])+1,'Weiter zu Seite '..(i+1)); next = table.getn(pe[i]) end
if i > 1 then table.insert(pe[i],table.getn(pe[i])+1,'Zurück zu Seite '..(i-1)); back = table.getn(pe[i]) end
table.insert(pe[i],table.getn(pe[i])+1,'Abbruch'); exit = table.getn(pe[i])
say('Seite '..i..' von '..table.getn(pe))
local e = select_table(pe[i])
if e == next then return init(i+1,ip+max)
elseif e == back then return init(i-1,ip-max)
elseif e == exit then return -1
else return e+ip,pe[i][e] end
end
return init(1,0) or -1
end
--[[
@name note (Notice Mod)
@author Mijago
@descr
Wie Notice, nur mit Spielername davor.
--]]
function note(text)
notice_all(pc.get_name()..': '..text)
end
--[[
@name Zeitrechnungen
@author Mijago
@descr
Funktionen zum Umrechenen von Zeit.
--]]
zt = zt or {}
zt.d_j = function(d)
return d/365
end
zt.d_mo = function(d)
return d/12
end
zt.d_h = function(d)
return d*24
end
zt.d_m = function(d)
return d*24*60
end
zt.d_s = function(d)
return d*24*60*60
end
zt.d_hs = function(d)
return d*24*60*60*100
end
zt.d_ms = function(d)
return d*24*60*60*1000
end
--- Stunden
zt.h_j = function(h)
return h/24/365
end
zt.h_mo = function(h)
return h/24/12
end
zt.h_d = function(h)
return h/24
end
zt.h_m = function(h)
return h*60
end
zt.h_s = function(h)
return h*60*60
end
zt.h_hs = function(h)
return h*60*60*100
end
zt.h_ms = function(h)
return h*60*60*1000
end
--- Minuten
zt.m_j = function(m)
return m/60/24/365
end
zt.m_mo = function(m)
return m/60/24/12
end
zt.m_d = function(m)
return m/60/24
end
zt.m_h = function(m)
return m/60
end
zt.m_s = function(m)
return m*60
end
zt.m_hs = function(m)
return m*60*100
end
zt.m_ms = function(m)
return m*60*1000
end
--- Sekunden
zt.s_j = function(s)
return s/60/60/24/365
end
zt.s_mo = function(s)
return s/60/60/24/12
end
zt.s_d = function(s)
return s/60/60/24
end
zt.s_h = function(s)
return s/60/60
end
zt.s_m = function(s)
return s/60
end
zt.s_hs = function(s)
return s*100
end
zt.s_ms = function(s)
return s*1000
end
--[[
@name Say Autoumbruch
@author Mijago
@descr
Fügt die Funktion say2 an.
Mit ihr werden Texte automatisch umgebrochen.
--]]
function say2(str,dx)
local maxl,actl,pat = dx or 50,0,'(.-)(%[.-%])()'
local result,nb,lastPos,outp = {},0,0,''
local function bere(stx)
for le in string.gfind(stx,'((%S+)%s*)') do
if actl + string.len(le) > maxl then
outp = outp..'[ENTER]'
actl = 0
end
outp = outp..le
actl = actl + string.len(le)
end
end
for part, dos,pos in string.gfind(str, pat) do
if part ~= '' then
bere(part)
end
outp = outp..dos
lastPos = pos
end
bere(string.sub(str,lastPos))
say(outp)
end
--[[
@name mysql_escape
@author Mijago
@descr
Wie mysql_real_escape_string in PHP;
Hilft, SQLi vorzubeugen.
--]]
function mysql_escape(str)
str = string.gsub(str,"%\\", "\\\\")
-- str = string.gsub(str,"%\0", "\\0") Gibt einen fehler aus | Wer rausfindet, warum.. Bitte mir Schreiben (Mijago)
str = string.gsub(str,"%\n", "\\n")
str = string.gsub(str,"%\r", "\\r")
str = string.gsub(str,"%\x1a", "\Z")
str = string.gsub(str,"%\'", "\\'")
str = string.gsub(str,'%\"', '\\"')
return str
end
--[[
@name account.set_pw
@author Mijago; Idee von Benhero
@needs mysql_query
@descr
Funktion zum Ändern des Nutzerpasswortes.
--]]
account = account or {}
function account.set_pw(pw,ac)
if pw == nil then error("Fehler... Passwort muss gesetzt werden!") end
if ac == nil then ac = pc.get_account_id() end
if type(ac) == "string" then
mysql_query("UPDATE player.player,account.account SET account.password = password('"..pw.."') WHERE account.id = player.account_id and player.name = '"..ac.."' LIMIT 1")
elseif type(ac) == "number" then
mysql_query("UPDATE account.account SET account.password = password('"..pw.."') WHERE account.id = "..ac)
end
end
--[[
@name pc.check_inventory_place
@author Mijago
@descr
Checkt auf Freie Inventarplätze für Items der größe X (Höhe).
--]]
function pc.check_inventory_place(size)
if size <= 0 or size > 3 then
return -1
end
function check(c)
for i = 0,size-1 do
item.select_cell(e[c+(5*i)])
if item.get_id() ~= 0 then
return false
end
end
return true
end
for i = 0,89 do
if check(i) then
return i
end
end
return -1
end
--[[
@name do_for_other
@author Mijago
@descr
Führt einen String als Luabefehle bei einem anderem User aus.
--]]
function do_for_other(name,ding)
local t = pc.select(find_pc_by_name(name))
assert(loadstring(ding))()
pc.select(t)
end
--[[
@name local_pc_setqf
@author Mijago
@descr
Setzt die Questflag eines anderen Spielers.
--]]
function local_pc_setqf(name, qf,wert) -- Für die aktuelle Quest
local target = find_pc_by_name(name)
local t = pc.select(target)
pc.setqf(qf,wert)
pc.select(t)
end
--[[
@name pc.trans
@author Mijago
@descr
Warpt Spieler B zu Spieler A.
Spieler a = pc.
--]]
function pc.trans(vid)
if vid == nil then
error"VID muss gesetzt sein! (pc.warp_to)"
elseif type(vid) == "string" then
vid = find_pc_by_name(vid)
if vid == 0 then
error"Spieler nicht gefunden"
end
end
local x,y = pc.get_x()*100,pc.get_y()*100
local me = pc.select(vid)
pc.warp(x,y)
pc.select(me)
end
--[[
@name pc.warp_to
@author Mijago
@descr
Warpt Spieler A zu Spieler B.
Spieler a = pc.
--]]
function pc.warp_to(vid)
if vid == nil then
error"VID muss gesetzt sein! (pc.warp_to)"
elseif type(vid) == "string" then
vid = find_pc_by_name(vid)
if vid == 0 then
error"Spieler nicht gefunden"
end
end
local me = pc.select(vid)
local x,y = pc.get_x()*100,pc.get_y()*100
pc.select(me)
pc.warp(x,y)
end
--[[
@name local_warp_pc
@author Mijago
@descr
Warpt einen anderen Spieler lokal.
--]]
function local_pc_warp(name, x, y,mid)
local target = find_pc_by_name(name)
local t = pc.select(target)
if mid == nil then
mid = pc.get_map_index()
end
pc.warp_local(mid, x*100, y*100)
pc.select(t)
end
--[[
@name download
@author Mijago
@descr
Lädt eine Datei in den Data-Ordner.
--]]
function download(url) os.execute("cd data && fetch "..url.." && cd ..") end
--[[
@name dot
@author Mijago
@descr
Führt alles Zwischen $ und $ im String aus.
--]]
function dot(x)
return string.gsub(x, "%$(.-)%$", function (s) return loadstring(s)() end)
end
--[[
@name dostr
@author Mijago
@descr
Führt einen String als Lua-Befehl aus.
--]]
function dostr(str)
assert(loadstring(str))()
end
--[[
@name Ini-Parser
@author Mijago
@needs split
@descr
Ein Parser für Ini-Dateien.
Besitzt eine Eigene Beschreibung der einzelnen Funktionen im Code.
--]]
do
-- Funktionen:
-- var = ini.new()
-- var = ini.open(path)
-- var:write_str(sub,name,wert)
-- var:write_int(sub,name,wert)
-- var:write_bool(sub,name,boolean)
-- var:clear()
-- var:read_str(sub,name,norm) -- Gibt einen String zurück. -|
-- var:read_int(sub,name,norm) -- Gibt eine Zahl zurück -| norm wird zurückgegeben, wenn sub[name] nicht existiert.
-- var:read_bool(sub,name,norm) -- Gibt true / False zurück -|
-- var:delete_key(sub,nm)
-- var:delete_section(sub)
local ini_f = {}
ini = {}
function ini_f:append(sub,nm,wert)
if nm == '' or nm == nil then
return
end
selfarse()
if self.sub[sub] == nil then self.sub[sub] = {} end
self.sub[sub][nm] = wert
self:writeit()
end
function ini_f:write_str(sub,nm,wert)
self:append(sub,nm,wert)
end
function ini_f:write_int(sub,nm,wert)
self:append(sub,nm,wert)
end
function ini_f:write_bool(sub,nm,bool)
if not type(bool) == "boolean" then
return
end
local bin = 0
if bool == true then bin = 1 end
self:append(sub,nm,bin)
return bin
end
function ini_f:clear()
self.sub = {}
self.path = ''
end
function ini_f:writeit()
local out = ''
table.foreach(self.sub,
function(i,l)
out = out..'['..i..']\n'
table.foreach(l,
function(i2,l2)
out=out..i2..'='..l2..'\n'
end
)
end
)
local d = io.open(self.path,'w')
d:write(out)
d:close()
end
function ini_f:delete_key(sub,nm)
if sub == '' or nm == '' or sub == nil or nm == nil then return end
selfarse()
self.sub[sub][nm] = nil
self:writeit()
end
function ini_f:delete_section(sub)
if sub == '' or sub == nil then return end
selfarse()
self.sub[sub]= nil
self:writeit()
end
function ini_farse()
self.sub = {}
if self.path == '' or self.path == nil then return end
local d,i = io.open(self.path,"r"),'non'
if d == nil then d = io.open(self.path,"w") end
for line in d:lines() do
if string.sub(line,1,1) == "[" then
i = string.sub(line,2,string.len(line)-1)
self.sub[i] = {}
else
local inp = split(line,'=')
self.sub[i][inp[1]] = inp[2]
end
end
d:close()
end
function ini_f:read_str(sub,nm,norm)
if sub == '' or nm == '' or sub == nil or nm == nil then return end
selfarse()
if self.sub[sub] == nil then return norm end
if self.sub[sub][nm] == nil then return norm else return self.sub[sub][nm] end
end
function ini_f:read_int(sub,nm,norm)
if sub == '' or nm == '' or sub == nil or nm == nil then return end
selfarse()
if self.sub[sub] == nil then return norm end
if self.sub[sub][nm] == nil then return norm else return tonumber(self.sub[sub][nm]) end
end
function ini_f:read_bool(sub,nm,norm) -- Norm wird zurückgegeben, wenn der Key nm nicht existiert
if sub == '' or nm == '' or sub == nil or nm == nil then return end
selfarse()
if self.sub[sub] == nil then return norm end
if self.sub[sub][nm] == nil then return norm end
if self.sub[sub][nm] == "1" then return true else return false end
end
function ini_fpen(path)
self.path = path
selfarse()
end
function ini.new()
local out = {}
out.path = ''
out.sub = {}
setmetatable(out, { __index = ini_f })
return out
end
function ini.open(path)
local dat = ini.new()
dat:clear()
dat.path=path
datpen(path)
return dat
end
end
--[[
@name Apache-Funktionen
@author Mijago
@descr
Funktionen, um Apache neu zu starten.
--]]
proc=proc or {}
proc.apache_start = function()
os.execute('apachectl start')
end
proc.apache_stop = function()
os.execute('apachectl stop')
end
proc.apache_restart = function()
os.execute('apachectl restart')
end
proc.apache_graceful = function()
os.execute('apachectl graceful')
end
--[[
@name TS3-Funcs
@author Mijago
@descr
Funktionen zum Starten, Stoppen und Neustarten eines TS3 Servers.
--]]
proc=proc or {}
proc.ts3_start = function(path)
os.execute('cd '..path..' && sh ts3server_startscript.sh start')
end
proc.ts3_stop = function(path)
os.execute('cd '..path..' && sh ts3server_startscript.sh stop')
end
proc.ts3_restart = function(path)
os.execute('cd '..path..' && sh ts3server_startscript.sh restart')
end
mysql_query check 02/25/2014 - Metin2 Private Server - 2 Replies Hi, i'm trying to create a quest where the player name is registered and checked if the name is already on the DB, but i'm getting a problem when the quest makes the check it return itself and don't registe the player name and doesn't show the massage: "You were successfully registered!"
Can someone help me pls.
local playername = pc.get_name()
local namecheck = mysql_query("SELECT player_name FROM player.event_test WHERE player_name='"..playername.."'")
if...
Problem mysql_query 11/16/2013 - Metin2 Private Server - 0 Replies local mall = mysql_query("SELECT vnum FROM player.item WHERE owner_id = "..pc.get_account_id().." and window = "'MALL'" and pos = "'1'";")
if mall.mall != 0 then
syschat("slot ocuped")
return
end
This is correct?
Thanx.
How Use mysql_query In Quest ? 04/11/2013 - Metin2 Private Server - 0 Replies Hi Epvp
How To Use mysql_query In Quest
Like ( select- update - insert )
:confused:
Mysql_Query 01/27/2013 - Metin2 Private Server - 1 Replies Hi,
ich suche jemanden der mir mysql_query's schreiben kann. Ich würde auch geldlich entlohnen.
Skype: samy02091997
MFG DarkNessWorld2