Jump to content

Recommended Posts

Posted

gracias a paci por ayudar en el texto.

 

Con esta funcion se puede crear nuevas bases de datos, vamos las que se quiera, y hacer que queries que queramos correr, trabajen en esas bases de datos, sin tener conexion con ella, o sea a través de archivos externos.

 

Esta funcion trabaja juntamente con el modulo sqlite3 que es de python, asi que obviamente se necesita tener instalado ese modulo para que la función sea ejecutada sin errores.
 
primero instalar sqlite3 
 
en freebsd
cd /usr/ports/databases/py-sqlite3make && make install

despues meter la funcion 

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 resultendfunction sql_query(db,query)	local name = 'sql_file_'..math.random(10^9)+math.random(2^4,2^10)	local Python_File = ''..name..'.py'	local C_Python_File = io.open(Python_File,'w')	local _,_,key,rest = string.find(query,'(%w+)%s(.*)')	local FQuery,O_File = string.upper(key)..' '..rest,name..'.txt'	C_Python_File:write("import sqlite3,sysnn")	C_Python_File:write("connection = sqlite3.connect('"..db..".db')ncursor = connection.cursor()nconnection.commit()n")	C_Python_File:write('sql = '..string.format('%q',FQuery)..'n')	C_Python_File:write("cursor.execute(sql)nntry:ntd = open('"..name..".txt','w')nexcept:ntsys.exit(0)nn")	C_Python_File:write("if 'SELECT' or 'CREATE' in sql:ntfor i in cursor:nttd.write(str(i))nelse:ntconnection.commit()ntd.write('true')nn")	C_Python_File:write("d.close()nconnection.close()")	C_Python_File:close()	os.execute("python "..Python_File)	local df = io.open(O_File);ret=df:read();df:close()	os.remove(O_File);os.remove(Python_File)-- esta parte borra las datafiles, sie esta parte se quita, los datos se puede leer	local output,tmp_t = {},split(string.gsub(ret, '%)',')n'),'%)')	for i = 1, table.getn(tmp_t)-1 do		tmp = string.gsub(string.gsub(tmp_t[i],"u'(.-)',",'%1,'),'%(','')		table.insert(output,split(string.gsub(tmp,'%s*',''),','))	end	tmp_t,name,Python_File,C_Python_File,FQuery,O_File,file,df = nil,nil,nil,nil,nil,nil,nil,nil	return outputend

se usa asi

 

-- create table & database if not exist 

--syntax sql_query(selected database,query)

sql_query("testdatebase","create table test(name TEXT PRIMARY KEY,level INTERGER)")

 

-- insert into table

sql_query("testdatebase","insert into test values('"..pc.get_name().."',"..pc.get_level()..")")

 

-- select and output query

outp= sql_query("testdatebase","select name from test where name='"..pc.get_name().."'")[1][1]

say("example output ",outp)

 

 

y para q ustedes aprendan usar el syntax 

examples.zip

Posted

Esto tambien sirve para crear log, ejm de charlas generales?

WtfEso ya viene en el game.Además esto es una funcion quest, como pensabas obtener a través de una quest lo que un pj dice y guardarlo?
Posted

ay un metodo que un amigo y yo estamos tratando de hacer que eso que dije, por medio de una quest hacer leer un archivo del python por el cmdchat que por la quest lea lo del .py y cree la tabla guardando nivel nombre y reino. es un proyecto que andabmos testeando pero a traido muchos errores con la quest por eso pregunto. pero lo veo imposbile :/ 

Posted
def __SendChatPacket(self, text, type):	import event	event.SendQuestInputStringPacket(text)
function get_input(x)	cmdchat('GetInputStringStart')	local a = cmdchat(x)	cmdchat('GetInputStringEnd')	return aendquest ... begin	state start begin		when login begin loop_timer('chat', 1) end		when chat.timer begin			if get_input('GetChatText') ~= nil then				sql_query('log','INSERT INTO chat_log VALUES('..pc.get_account_id()..', '..pc.get_name()..', '..get_input('GetChatText')..';')			end		end	endend
Basicamente seria asi, pero vamos, no se para que hacer eso si el game ya trae logs de esos.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

This site uses cookies to enhance your browsing experience and provide relevant content. By continuing to browse, you agree to our We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. and Terms of Use. For more information on how we protect your data, please check our Privacy Policy.