Jump to content

Ayuda MySQL


Plate

Recommended Posts

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

Hize desastre nada mas xD

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
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
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 xD

Link to comment
  • Recently Browsing   0 members

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