Jump to content

executeSQLUpdate


mjau

Recommended Posts

Hi how does executeSQLUpdate work ?

function newClothes(acc, clothes) 
if executeSQLUpdate(acc, "clothes = 'clothes'") == true then 
return true 
else 
return false 
end 
end 

i trigger that function with agument for the clothes i wana set, wil that do it im just wondering since the variable is in a string on executeSQLUpdate function btw the table is right i have made a table for every acc in server

Link to comment

Eh solidsnake every player whp logs in gets a table created with their acc name so acc would be right as argument for tablename i think

function createPrivateSQLTableOnJoin(prevAcc, currentAcc) 
local accName = getAccountName(currentAcc)  
executeSQLCreateTable(accName, "bankMoney, clothes") 
end 
addEventHandler("onPlayerLogin", rootElement, createPrivateSQLTableOnJoin) 
  
function getCurrentClothes(acc) 
clothes = executeSQLSelect(acc, "clothes") 
return clothes 
end 
  
function newClothes(acc, clothes) 
if executeSQLUpdate(acc, "clothes = '"..clothes.."'") == true then 
return true 
else 
return false 
end 
end 
  

would this be right ?

Link to comment

Not tested.

function getCurrentClothes( uPlayer ) 
    if isElement( uPlayer ) then 
        local uAccount = getPlayerAccount( uPlayer ) 
        if uAccount and not isGuestAccount( uAccount ) then 
            local sAccount = getAccountName( uAccount ) 
            local tClothes = { } 
            for i = 0,12 do 
                local tResult = executeSQLQuery( "SELECT * FROM clothes WHERE user = '" .. sAccount .. "'" ) 
                if tResult and #tResult > 0 then 
                    table.insert( tClothes, { tResult[i].txd, tResult[i].model }  ) 
                end  
            end  
            return tClothes 
        end 
        return false 
    end 
    return false 
end 
  
function updateClothes( uPlayer, txd, model ) 
    if isElement( uPlayer ) and type( txd ) == 'string' and type( model ) == 'string' then 
        local uAccount = getPlayerAccount( uPlayer ) 
        if uAccount and not isGuestAccount( uAccount ) then 
            local sAccount = getAccountName( uAccount ) 
            for i = 0,12 do 
                local tRequest = executeSQLQuery( "SELECT * FROM clothes WHERE user = '" .. sAccount .. "'" ) 
                if tRequest and #tRequest > 0 then 
                    executeSQLQuery( "UPDATE clothes SET txd = '" .. txd .. "', model = '" .. model .. "' WHERE user = '" .. sAccount .. "'" ) 
                end 
            end 
            return true  
        end 
        return false 
    end 
    return false     
end 
  
addEventHandler( 'onResourceStart', resourceRoot, 
    function( ) 
        executeSQLQuery 'CREATE TABLE IF NOT EXISTS clothes ( user TEXT, txd TEXT, model TEXT )' 
    end 
)    
  
addEventHandler( 'onPlayerLogin', root, 
    function( _, uAccount ) 
        local tRequest = executeSQLQuery( "SELECT * FROM clothes WHERE user = '" .. getAccountName( uAccount ) .. "'" )  
        if tRequest and #tRequest > 0 then 
            for i = 0,17 do 
                if tRequest[i].txd and tRequest[i].model then 
                    addPedClothes( source, tRequest[i].txd, tRequest[i].model, i ) 
                end  
            end 
        end  
    end 
)    
  
addEventHandler( 'onPlayerQuit', root, 
    function( ) 
        local uAccount = getPlayerAccount( source ) 
        if uAccount and not isGuestAccount( uAccount ) then 
            local sAccount = getAccountName( uAccount ) 
            for i = 0,17 do 
                local tRequest = executeSQLQuery( "SELECT * FROM clothes WHERE user = '" .. sAccount .. "'" ) 
                local sTxd,sModel = getPedClothes( source, i ) 
                if sTxd and sModel then 
                    if tRequest and #tRequest > 0 then 
                        executeSQLQuery( "UPDATE clothes SET txd = '" .. txd .. "', model = '" .. model .. "' WHERE user = '" .. sAccount .. "'" ) 
                    else 
                        executeSQLQuery( "INSERT INTO clothes VALUES ( '" .. sAccount .. "', '" .. txd .. "', '" .. model .. "')" ) 
                    end 
                end 
            end  
        end  
    end 
)    
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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