Plate Posted July 15, 2013 Share Posted July 15, 2013 Hola bueno necesito una mini ayuda con este script de guardado de cuentas con mysql pero no sirve y tampoco da error function saveAccounts () -- Save in the database local account = getPlayerAccount(source) if ( account ) then local accName = getAccountName(account) local i = getElementInterior( source ) local d = getElementDimension( source ) local skin = getPedSkin ( source ) local money = getPlayerMoney ( source ) local health = getElementHealth ( source ) local armor = getPedArmor ( source ) local q = mysql_query(database,"SELECT * FROM `accounts` WHERE `Account` = '".. accName .."'") if(mysql_num_rows(q) == 0) then mysql_query( database, "INSERT INTO accounts ( `Account`, intterior, demension, skin, money, health, armor) VALUES ( '" .. accName .. "'," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor .." )" ) else res = mysql_query ( database, "UPDATE `accounts` SET intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor .." WHERE `Account` = '"..accName.."'") end end end addEventHandler ( "onPlayerQuit", root, saveAccounts ) function loadAccounts () -- Loading from the database local account = getPlayerAccount ( source ) if ( account ) then local accName = getAccountName(account) local result = mysql_query ( database ,"SELECT * FROM `accounts` WHERE `Account` = '"..accName.."'") if result then while true do local row = mysql_fetch_assoc(result) if not row then break end setElementInterior ( source, row.intterior ) setElementDimension ( source, row.demension ) setPedSkin ( source, row.skin ) setPlayerMoney ( source, row.money ) setElementHealth ( source, row.health) setPedArmor ( source, row.armor ) break end end end end addEventHandler ( "onPlayerLogin", root, loadAccounts ) Link to comment
Castillo Posted July 15, 2013 Share Posted July 15, 2013 Porque usas las funciones esas? usa las nuevas del MTA que son mas eficientes. Link to comment
Castillo Posted July 15, 2013 Share Posted July 15, 2013 dbConnect dbQuery dbExec dbFree Link to comment
Plate Posted July 15, 2013 Author Share Posted July 15, 2013 Hize desastre nada mas function saveAccounts () -- Save in the database local account = getPlayerAccount(source) if ( account ) then local accName = getAccountName(account) local i = getElementInterior( source ) local d = getElementDimension( source ) local skin = getPedSkin ( source ) local money = getPlayerMoney ( source ) local health = getElementHealth ( source ) local armor = getPedArmor ( source ) local q = dbQuery(database,"SELECT * FROM `accounts` WHERE `Account` = '".. accName .."'") local result = dbPoll( q, 10 ) if result == nil then dbQuery( database, "INSERT INTO accounts ( `Account`, intterior, demension, skin, money, health, armor) VALUES ( '" .. accName .. "'," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor .." )" ) else res = dbQuery ( database, "UPDATE `accounts` SET intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor .." WHERE `Account` = '"..accName.."'") end end end addEventHandler ( "onPlayerQuit", root, saveAccounts ) function loadAccounts () -- Loading from the database local account = getPlayerAccount ( source ) if ( account ) then local accName = getAccountName(account) local resultq = dbQuery ( database ,"SELECT * FROM `accounts` WHERE `Account` = '"..accName.."'") if resultq then while true do local result, num_affected_rows, errmsg = dbPoll ( resultq, -1 ) if num_affected_rows > 0 then for result, row in pairs ( result ) do if not row then break end setElementInterior ( source, row.intterior ) setElementDimension ( source, row.demension ) setPedSkin ( source, row.skin ) setPlayerMoney ( source, row.money ) setElementHealth ( source, row.health) setPedArmor ( source, row.armor ) break end end end end end end addEventHandler ( "onPlayerLogin", root, loadAccounts ) Link to comment
MTA Team 0xCiBeR Posted July 15, 2013 MTA Team Share Posted July 15, 2013 No defines "database", definelo usando dbConnect Lee los argumentos de las funciones que te dio Solid y estaras bien Link to comment
Arsilex Posted July 15, 2013 Share Posted July 15, 2013 function saveAccounts () -- Save in the database local account = getPlayerAccount(source) if ( account ) then local accName = getAccountName(account) local i = getElementInterior( source ) local d = getElementDimension( source ) local skin = getPedSkin ( source ) local money = getPlayerMoney ( source ) local health = getElementHealth ( source ) local armor = getPedArmor ( source ) local q = dbQuery(database,"SELECT * FROM accounts WHERE Account = '".. accName .."'") local result = dbPoll( q, 10 ) if result == nil then dbQuery( database, "INSERT INTO accounts ( Account, intterior, demension, skin, money, health, armor) VALUES ( '" .. accName .. "'," .. i .. ", " .. d .. "," .. skin .. "," .. money .. ", ".. health ..", ".. armor .." )" ) else res = dbQuery ( database, "UPDATE accounts SET intterior = ".. i ..", demension = ".. d ..", skin = ".. skin ..", money = ".. money ..", health = ".. health ..", armor = ".. armor .." WHERE `Account` = '"..accName.."'") end end end addEventHandler ( "onPlayerQuit", root, saveAccounts ) function loadAccounts () -- Loading from the database local account = getPlayerAccount ( source ) if ( account ) then local accName = getAccountName(account) local resultq = dbQuery ( database ,"SELECT * FROM accounts WHERE Account = '"..accName.."'") if resultq then while true do local result, num_affected_rows, errmsg = dbPoll ( resultq, -1 ) if num_affected_rows > 0 then for result, row in pairs ( result ) do if not row then break end setElementInterior ( source, row.intterior ) setElementDimension ( source, row.demension ) setPedSkin ( source, row.skin ) setPlayerMoney ( source, row.money ) setElementHealth ( source, row.health) setPedArmor ( source, row.armor ) break end end end end end end addEventHandler ( "onPlayerLogin", root, loadAccounts ) Link to comment
MTA Team 0xCiBeR Posted July 16, 2013 MTA Team Share Posted July 16, 2013 lo de pekio esta bien, siempre y cuando @Plate definas database con un dbConnect Link to comment
Plate Posted July 17, 2013 Author Share Posted July 17, 2013 lo de pekio esta bien, siempre y cuando @Plate definas database con un dbConnect Yo ya hize el dbConnect pero no lo pase por que es privado ^^ Link to comment
MTA Team 0xCiBeR Posted July 17, 2013 MTA Team Share Posted July 17, 2013 lo de pekio esta bien, siempre y cuando @Plate definas database con un dbConnect Yo ya hize el dbConnect pero no lo pase por que es privado ^^ lo imagine..Igual puedes usar datos falsos, para verlo entero.. Igual se entendio Link to comment
Arsilex Posted July 17, 2013 Share Posted July 17, 2013 Pero ya te funciona o no te funciona? Link to comment
Plate Posted July 21, 2013 Author Share Posted July 21, 2013 No, no me funciona recien lo probe Link to comment
Arsilex Posted July 22, 2013 Share Posted July 22, 2013 que error te sale en el debug? estas seguro que se conecta con el mysql? Link to comment
Recommended Posts