Jump to content

قاعدة حفظ البيانات


Recommended Posts

وش تبي تسوي بالضبط؟,

الي فهمته انك تبي لو حذفت سيارته تختفي من الجريد ليست صح ولا لا؟ طيب كيف نظام الجريد ليست؟ يعني اسم اللاعب وجنبه رو مكتوب فيه انه معه سياره؟

واطرح اكوادك كامله ,,

نظام القريد ليست بس رو حق السيارة وهو يحفظ السيارة بس المشكلة لما احذف الرو اللي حددته ينحذف لكن لما اسوي ريستارت القاهم ماانحذفو

:: Client

addEventHandler("onClientGUIClick",root, 
    function () 
        if ( source == GUIEditor_Button[1] ) then 
           local name = guiGetText(GUIEditor_Edit[1]) 
           local carID = guiGetText(GUIEditor_Edit[2]) 
           local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
             triggerServerEvent("Save",localPlayer, carName) 
        elseif ( source == GUIEditor_Button[2] ) then 
           local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
        if ( row and col and row ~= -1 and col ~= -1 ) then 
              triggerServerEvent("RemoveRow", localPlayer, carName, row) 
           end 
       end 
   end 
) 
            
addEvent ( "DeleteRow" , true) 
addEventHandler ( "DeleteRow", root, 
 function ( carName ) 
     if ( carName and carName ~= nil ) then 
          guiGridListRemoveRow ( GUIEditor_Grid[1], carName ) 
       end 
   end 
) 
  
addEvent ( "AddDataCarName", true ) 
addEventHandler ( "AddDataCarName", root, 
    function (carName ) 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( carName ), false, false ) 
    end 
) 
  
addEvent ( "AddCarName", true ) 
addEventHandler ( "AddCarName", root, 
    function ( onClientSqlList) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.carName ), false, false )  
        end 
    end 
) 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        triggerServerEvent ( "Refresh", localPlayer ) 
    end 
) 

:: Server

addEventHandler ( "onResourceStart", resourceRoot, 
      function ( ) 
          executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `SQL_Data` (`carName`)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0)  
   end 
) 
  
function setSQL_Data ( carName ) 
    return executeSQLQuery ( "INSERT INTO `SQL_Data` ( `carName` ) VALUES ( ? )", tostring(carName) ) 
end 
       
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `SQL_Data`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( "Save", true ) 
addEventHandler ( "Save", root, 
   function ( carName )       
      
        setSQL_Data ( carName) 
        triggerClientEvent ( root, "AddDataCarName", root,carName ) 
    end 
) 
  
addEvent("RemoveRow", true) 
addEventHandler("RemoveRow", root, function(carName, row) 
  if executeSQLQuery("DELETE FROM `SQL_Data` WHERE `carName` = ? ", tostring(carName) ) then 
         
         triggerClientEvent(root, "DeleteRow", root, tostring( row )) 
      end 
 end 
) 
  
 addEvent ( "Refresh", true ) 
 addEventHandler ( "Refresh", root, 
    function ( ) 
        UpDateListInSql ( source ) 
    end 
) 

Link to comment
  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

-- Client Side # 
addEventHandler('onClientGUIClick',root,function () 
    local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
    local name = guiGridListGetItemText(GUIEditor_Grid[1],row,1) 
    local vehicle = guiGridListGetItemText(GUIEditor_Grid[1],row,2) 
    if ( source == GUIEditor_Button[1] ) then 
        local plrName = guiGetText(GUIEditor_Edit[1]) 
        local carID = guiGetText(GUIEditor_Edit[1]) 
            if not tonumber(carID) or carID == '' or plrName == '' then return end 
            local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
            triggerServerEvent('Save',localPlayer, carName,plrName) 
        elseif ( source == GUIEditor_Button[2] ) then 
                if ( row and col and row ~= -1 and col ~= -1 ) then 
                    triggerServerEvent('RemoveRow', localPlayer, vehicle,name,row) 
           end 
       end 
   end 
) 
            
addEvent ( 'RemoveFromGrid' , true) 
addEventHandler ( 'RemoveFromGrid', root,function ( theRow ) 
        guiGridListRemoveRow (GUIEditor_Grid[1], tostring(theRow) ) 
    end 
) 
  
addEvent ( 'AddDataCarName', true ) 
addEventHandler ( 'AddDataCarName', root,function (car,plr) 
    local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( plr ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 2,tostring ( car ), false, false ) 
    end 
) 
  
addEvent ( 'AddCarName', true ) 
addEventHandler ( 'AddCarName', root,function ( onClientSqlList ) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.plr ), false, false ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 2, tostring ( v.car ), false, false ) 
        end 
    end 
) 
  
addEventHandler('onClientResourceStart',resourceRoot,function() 
    triggerServerEvent ( 'Refresh', localPlayer ) 
    end 
) 

-- Server Side # 
addEventHandler ( 'onResourceStart', resourceRoot,function ( ) 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `CarSystem` (car,plr)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0) 
   end 
) 
  
function setSQL_Data ( car , plr) 
    return executeSQLQuery ( "INSERT INTO `CarSystem` ( `car`, `plr` ) VALUES ( ?,? )", tostring(car),tostring(plr) ) 
end 
      
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `CarSystem`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( 'Save', true ) 
addEventHandler ( 'Save', root,function (car,plr)       
    setSQL_Data (car,plr) 
        triggerClientEvent ( root, "AddDataCarName", root,car,plr ) 
    end 
) 
  
addEvent('RemoveRow', true) 
addEventHandler('RemoveRow', root, function(vehicle, name,row) 
    executeSQLQuery("DELETE FROM `CarSystem` WHERE `car` = '" .. tostring(vehicle) .. "' AND plr = '".. tostring(name) .."'") 
        triggerClientEvent('RemoveFromGrid',root,tonumber(row)) 
    end 
) 
  
addEvent ( 'Refresh', true ) 
addEventHandler ( 'Refresh', root,function ( ) 
    UpDateListInSql ( source ) 
    end 
) 
Link to comment
-- Client Side # 
addEventHandler('onClientGUIClick',root,function () 
    local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
    local name = guiGridListGetItemText(GUIEditor_Grid[1],row,1) 
    local vehicle = guiGridListGetItemText(GUIEditor_Grid[1],row,2) 
    if ( source == GUIEditor_Button[1] ) then 
        local plrName = guiGetText(GUIEditor_Edit[1]) 
        local carID = guiGetText(GUIEditor_Edit[1]) 
            if not tonumber(carID) or carID == '' or plrName == '' then return end 
            local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
            triggerServerEvent('Save',localPlayer, carName,plrName) 
        elseif ( source == GUIEditor_Button[2] ) then 
                if ( row and col and row ~= -1 and col ~= -1 ) then 
                    triggerServerEvent('RemoveRow', localPlayer, vehicle,name,row) 
           end 
       end 
   end 
) 
            
addEvent ( 'RemoveFromGrid' , true) 
addEventHandler ( 'RemoveFromGrid', root,function ( theRow ) 
        guiGridListRemoveRow (GUIEditor_Grid[1], tostring(theRow) ) 
    end 
) 
  
addEvent ( 'AddDataCarName', true ) 
addEventHandler ( 'AddDataCarName', root,function (car,plr) 
    local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( plr ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 2,tostring ( car ), false, false ) 
    end 
) 
  
addEvent ( 'AddCarName', true ) 
addEventHandler ( 'AddCarName', root,function ( onClientSqlList ) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.plr ), false, false ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 2, tostring ( v.car ), false, false ) 
        end 
    end 
) 
  
addEventHandler('onClientResourceStart',resourceRoot,function() 
    triggerServerEvent ( 'Refresh', localPlayer ) 
    end 
) 

-- Server Side # 
addEventHandler ( 'onResourceStart', resourceRoot,function ( ) 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `CarSystem` (car,plr)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0) 
   end 
) 
  
function setSQL_Data ( car , plr) 
    return executeSQLQuery ( "INSERT INTO `CarSystem` ( `car`, `plr` ) VALUES ( ?,? )", tostring(car),tostring(plr) ) 
end 
      
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `CarSystem`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( 'Save', true ) 
addEventHandler ( 'Save', root,function (car,plr)       
    setSQL_Data (car,plr) 
        triggerClientEvent ( root, "AddDataCarName", root,car,plr ) 
    end 
) 
  
addEvent('RemoveRow', true) 
addEventHandler('RemoveRow', root, function(vehicle, name,row) 
    executeSQLQuery("DELETE FROM `CarSystem` WHERE `car` = '" .. tostring(vehicle) .. "' AND plr = '".. tostring(name) .."'") 
        triggerClientEvent('RemoveFromGrid',root,tonumber(row)) 
    end 
) 
  
addEvent ( 'Refresh', true ) 
addEventHandler ( 'Refresh', root,function ( ) 
    UpDateListInSql ( source ) 
    end 
) 

لا فــائــده

Link to comment
وش لا فائده؟ جربته شغال -__-

اطرح اكوادك كلها مع النوافذ ,,

:: Client

GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
  
GUIEditor_Window[1] = guiCreateWindow(353,184,180,150,"",false) 
GUIEditor_Edit[1] = guiCreateEdit(12,88,146,32,"",false,GUIEditor_Window[1]) 
GUIEditor_Edit[2] = guiCreateEdit(14,46,50,35,"",false,GUIEditor_Window[1]) 
GUIEditor_Button[1] = guiCreateButton(80,46,80,33,"",false,GUIEditor_Window[1]) 
GUIEditor_Window[2] = guiCreateWindow(150,208,200,247,"",false) 
GUIEditor_Grid[1] = guiCreateGridList(10,24,181,180,false,GUIEditor_Window[2]) 
guiGridListSetSelectionMode(GUIEditor_Grid[1],2) 
guiGridListAddColumn(GUIEditor_Grid[1],"Car                 ",0.9) 
GUIEditor_Button[2] = guiCreateButton(60,204,86,34,"DELETE",false,GUIEditor_Window[2]) 
  
addEventHandler("onClientGUIClick",root, 
    function () 
        if ( source == GUIEditor_Button[1] ) then  
           local name = guiGetText(GUIEditor_Edit[1]) 
           local carID = guiGetText(GUIEditor_Edit[2]) 
           local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
             triggerServerEvent("Save",localPlayer, carName)  
        elseif ( source == GUIEditor_Button[2] ) then 
           local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
        if ( row and col and row ~= -1 and col ~= -1 ) then 
              triggerServerEvent("RemoveRow", localPlayer, carName, row) 
           end 
       end 
   end 
) 
            
addEvent ( "DeleteRow" , true) 
addEventHandler ( "DeleteRow", root, 
 function ( carName ) 
     if ( carName and carName ~= nil ) then 
          guiGridListRemoveRow ( GUIEditor_Grid[1], carName ) 
       end 
   end 
) 
  
addEvent ( "AddDataCarName", true ) 
addEventHandler ( "AddDataCarName", root, 
    function (carName ) 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( carName ), false, false ) 
    end 
) 
  
addEvent ( "AddCarName", true ) 
addEventHandler ( "AddCarName", root, 
    function ( onClientSqlList) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.carName ), false, false ) 
        end 
    end 
) 
  
addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        triggerServerEvent ( "Refresh", localPlayer ) 
    end 
) 

:: Server

 

addEventHandler ( "onResourceStart", resourceRoot, 
      function ( ) 
          executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `SQL_Data` (`carName`)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0) 
   end 
) 
  
function setSQL_Data ( carName ) 
    return executeSQLQuery ( "INSERT INTO `SQL_Data` ( `carName` ) VALUES ( ? )", tostring(carName) ) 
end 
      
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `SQL_Data`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( "Save", true ) 
addEventHandler ( "Save", root, 
   function ( carName )          
        setSQL_Data ( carName) 
        triggerClientEvent ( root, "AddDataCarName", root,carName ) 
    end 
) 
  
addEvent("RemoveRow", true) 
addEventHandler("RemoveRow", root, function(carName, row) 
  if executeSQLQuery("DELETE FROM `SQL_Data` WHERE `carName` = ? ", tostring(carName) ) then 
         triggerClientEvent(root, "DeleteRow", root, tostring( row )) 
      end 
 end 
) 
  
 addEvent ( "Refresh", true ) 
 addEventHandler ( "Refresh", root, 
    function ( ) 
        UpDateListInSql ( source ) 
    end 
) 

حط اي دي السيارة بالاديت الصغير مثلاً 581 واضغط الزر اللي جنبه كذا يروح اسم السيارة للقريد ليست وجرب اضغط ديليت للسيارة وسو ريستارت وشوف والاديت الثاني ماعليك منه

Link to comment

ما اشوف انك نسخت الاكواد الي عطيتك بالاساس -__-

-- Client Side # 
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
  
GUIEditor_Window[1] = guiCreateWindow(353,184,180,150,"",false) 
GUIEditor_Edit[1] = guiCreateEdit(12,88,146,32,"",false,GUIEditor_Window[1]) 
GUIEditor_Edit[2] = guiCreateEdit(14,46,50,35,"",false,GUIEditor_Window[1]) 
GUIEditor_Button[1] = guiCreateButton(80,46,80,33,"",false,GUIEditor_Window[1]) 
GUIEditor_Window[2] = guiCreateWindow(150,208,200,247,"",false) 
GUIEditor_Grid[1] = guiCreateGridList(10,24,181,180,false,GUIEditor_Window[2]) 
guiGridListSetSelectionMode(GUIEditor_Grid[1],2) 
guiGridListAddColumn(GUIEditor_Grid[1],"Car                 ",0.9) 
GUIEditor_Button[2] = guiCreateButton(60,204,86,34,"DELETE",false,GUIEditor_Window[2]) 
  
addEventHandler('onClientGUIClick',root,function () 
    local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
    local name = guiGridListGetItemText(GUIEditor_Grid[1],row,1) 
    local vehicle = guiGridListGetItemText(GUIEditor_Grid[1],row,2) 
    if ( source == GUIEditor_Button[1] ) then 
        local plrName = guiGetText(GUIEditor_Edit[1]) 
        local carID = guiGetText(GUIEditor_Edit[1]) 
            if not tonumber(carID) or carID == '' or plrName == '' then return end 
            local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
            triggerServerEvent('Save',localPlayer, carName,plrName) 
        elseif ( source == GUIEditor_Button[2] ) then 
                if ( row and col and row ~= -1 and col ~= -1 ) then 
                    triggerServerEvent('RemoveRow', localPlayer, vehicle,name,row) 
           end 
       end 
   end 
) 
            
addEvent ( 'RemoveFromGrid' , true) 
addEventHandler ( 'RemoveFromGrid', root,function ( theRow ) 
        guiGridListRemoveRow (GUIEditor_Grid[1], tostring(theRow) ) 
    end 
) 
  
addEvent ( 'AddDataCarName', true ) 
addEventHandler ( 'AddDataCarName', root,function (car,plr) 
    local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( plr ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 2,tostring ( car ), false, false ) 
    end 
) 
  
addEvent ( 'AddCarName', true ) 
addEventHandler ( 'AddCarName', root,function ( onClientSqlList ) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.plr ), false, false ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 2, tostring ( v.car ), false, false ) 
        end 
    end 
) 
  
addEventHandler('onClientResourceStart',resourceRoot,function() 
    triggerServerEvent ( 'Refresh', localPlayer ) 
    end 
) 

-- Server Side # 
addEventHandler ( 'onResourceStart', resourceRoot,function ( ) 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `CarSystem` (car,plr)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0) 
   end 
) 
  
function setSQL_Data ( car , plr) 
    return executeSQLQuery ( "INSERT INTO `CarSystem` ( `car`, `plr` ) VALUES ( ?,? )", tostring(car),tostring(plr) ) 
end 
      
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `CarSystem`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( 'Save', true ) 
addEventHandler ( 'Save', root,function (car,plr)       
    setSQL_Data (car,plr) 
        triggerClientEvent ( root, "AddDataCarName", root,car,plr ) 
    end 
) 
  
addEvent('RemoveRow', true) 
addEventHandler('RemoveRow', root, function(vehicle, name,row) 
    executeSQLQuery("DELETE FROM `CarSystem` WHERE `car` = '" .. tostring(vehicle) .. "' AND plr = '".. tostring(name) .."'") 
        triggerClientEvent('RemoveFromGrid',root,tonumber(row)) 
    end 
) 
  
addEvent ( 'Refresh', true ) 
addEventHandler ( 'Refresh', root,function ( ) 
    UpDateListInSql ( source ) 
    end 
) 
Link to comment
ما اشوف انك نسخت الاكواد الي عطيتك بالاساس -__-

-- Client Side # 
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Edit = {} 
GUIEditor_Grid = {} 
  
GUIEditor_Window[1] = guiCreateWindow(353,184,180,150,"",false) 
GUIEditor_Edit[1] = guiCreateEdit(12,88,146,32,"",false,GUIEditor_Window[1]) 
GUIEditor_Edit[2] = guiCreateEdit(14,46,50,35,"",false,GUIEditor_Window[1]) 
GUIEditor_Button[1] = guiCreateButton(80,46,80,33,"",false,GUIEditor_Window[1]) 
GUIEditor_Window[2] = guiCreateWindow(150,208,200,247,"",false) 
GUIEditor_Grid[1] = guiCreateGridList(10,24,181,180,false,GUIEditor_Window[2]) 
guiGridListSetSelectionMode(GUIEditor_Grid[1],2) 
guiGridListAddColumn(GUIEditor_Grid[1],"Car                 ",0.9) 
GUIEditor_Button[2] = guiCreateButton(60,204,86,34,"DELETE",false,GUIEditor_Window[2]) 
  
addEventHandler('onClientGUIClick',root,function () 
    local row, col = guiGridListGetSelectedItem(GUIEditor_Grid[1]) 
    local name = guiGridListGetItemText(GUIEditor_Grid[1],row,1) 
    local vehicle = guiGridListGetItemText(GUIEditor_Grid[1],row,2) 
    if ( source == GUIEditor_Button[1] ) then 
        local plrName = guiGetText(GUIEditor_Edit[1]) 
        local carID = guiGetText(GUIEditor_Edit[1]) 
            if not tonumber(carID) or carID == '' or plrName == '' then return end 
            local carName = getVehicleNameFromModel ( tonumber ( carID ) ) 
            triggerServerEvent('Save',localPlayer, carName,plrName) 
        elseif ( source == GUIEditor_Button[2] ) then 
                if ( row and col and row ~= -1 and col ~= -1 ) then 
                    triggerServerEvent('RemoveRow', localPlayer, vehicle,name,row) 
           end 
       end 
   end 
) 
            
addEvent ( 'RemoveFromGrid' , true) 
addEventHandler ( 'RemoveFromGrid', root,function ( theRow ) 
        guiGridListRemoveRow (GUIEditor_Grid[1], tostring(theRow) ) 
    end 
) 
  
addEvent ( 'AddDataCarName', true ) 
addEventHandler ( 'AddDataCarName', root,function (car,plr) 
    local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 1,tostring ( plr ), false, false ) 
        guiGridListSetItemText ( GUIEditor_Grid[1], row, 2,tostring ( car ), false, false ) 
    end 
) 
  
addEvent ( 'AddCarName', true ) 
addEventHandler ( 'AddCarName', root,function ( onClientSqlList ) 
        guiGridListClear ( GUIEditor_Grid[1] ) 
        for _, v in ipairs ( onClientSqlList ) do 
        local row = guiGridListAddRow ( GUIEditor_Grid[1] ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 1, tostring ( v.plr ), false, false ) 
            guiGridListSetItemText (GUIEditor_Grid[1], row, 2, tostring ( v.car ), false, false ) 
        end 
    end 
) 
  
addEventHandler('onClientResourceStart',resourceRoot,function() 
    triggerServerEvent ( 'Refresh', localPlayer ) 
    end 
) 

-- Server Side # 
addEventHandler ( 'onResourceStart', resourceRoot,function ( ) 
    executeSQLQuery ( "CREATE TABLE IF NOT EXISTS `CarSystem` (car,plr)" ) 
          outputDebugString("SQL Data Base Started!",0,0,255,0,0) 
   end 
) 
  
function setSQL_Data ( car , plr) 
    return executeSQLQuery ( "INSERT INTO `CarSystem` ( `car`, `plr` ) VALUES ( ?,? )", tostring(car),tostring(plr) ) 
end 
      
  
function SelectFromSql ( ) 
    local data = executeSQLQuery ( "SELECT * FROM `CarSystem`" ) 
    if ( type ( data ) == "table" and #data == 0) or not data then 
        return { } 
    else 
        return data; 
    end 
end 
  
function UpDateListInSql ( element ) 
    if ( not isElement ( element ) ) then 
        return; 
    end 
  
    local Upsql = SelectFromSql ( ) 
    triggerClientEvent ( element, "AddCarName", element, Upsql ) 
end 
  
addEvent ( 'Save', true ) 
addEventHandler ( 'Save', root,function (car,plr)       
    setSQL_Data (car,plr) 
        triggerClientEvent ( root, "AddDataCarName", root,car,plr ) 
    end 
) 
  
addEvent('RemoveRow', true) 
addEventHandler('RemoveRow', root, function(vehicle, name,row) 
    executeSQLQuery("DELETE FROM `CarSystem` WHERE `car` = '" .. tostring(vehicle) .. "' AND plr = '".. tostring(name) .."'") 
        triggerClientEvent('RemoveFromGrid',root,tonumber(row)) 
    end 
) 
  
addEvent ( 'Refresh', true ) 
addEventHandler ( 'Refresh', root,function ( ) 
    UpDateListInSql ( source ) 
    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...