تصحيح بسيط للكود الي فوق ^
function changeGridlistToVehicleNames ( gridlist, columnnum )
if not ( columnnum ) then
columnnum = 1
end
if not ( tonumber ( columnnum ) ) then
columnnum = 1
end
if ( gridlist ) then
if ( getElementType ( gridlist ) == "gui-gridlist" ) then
guiGridListClear ( gridlist )
for i = 411, 611 do
if ( getVehicleNameFromModel ( i ) ~= "" ) then
guiGridListSetItemText ( gridlist, guiGridListAddRow ( gridlist ), columnnum, getVehicleNameFromModel ( i ), false, false )
end
end
end
end
end
______________________________________________________________________________________________________________________________________________
#edit :
changeGridlistToVehicleNamesAndIds
الوضيفة زي الي فوق بس مع تعديلات بسيطة
Source Code :
function changeGridlistToVehicleNamesAndIds ( gridlist, sort, columnnum, columnnuma, AZ )
local vehsTable = { };
if not ( columnnum ) then
columnnum = 1
end;
if not ( columnnuma ) then
columnnuma = 2
end;
if not ( AZ ) then
AZ = "AZ"
end;
if ( gridlist and tostring ( sort ) and tostring ( AZ ) ) then
if ( getElementType ( gridlist ) == "gui-gridlist" ) then
guiGridListClear ( gridlist );
for i = 411, 611 do
if ( getVehicleNameFromModel ( i ) ~= "" ) then
table.insert ( vehsTable, { vehName = getVehicleNameFromModel ( i ), vehID = i } );
end;
end;
if ( sort == "ID" ) then
if ( AZ == "ZA" ) then
table.sort ( vehsTable, function ( a, b )
return
tonumber ( a["vehID"] ) > tonumber ( b["vehID"] )
end
);
else
if ( AZ == "AZ" ) then
table.sort ( vehsTable, function ( a, b )
return
tonumber ( a["vehID"] ) < tonumber ( b["vehID"] )
end
);
end;
end;
else
if ( sort == "Name" ) then
if ( AZ == "ZA" ) then
table.sort ( vehsTable, function ( a, b )
return
a["vehName"] > b["vehName"]
end
);
else
if ( AZ == "AZ" ) then
table.sort ( vehsTable, function ( a, b )
return
a["vehName"] < b["vehName"]
end
);
end;
end;
end;
end;
for _, v in ipairs ( vehsTable ) do
row = guiGridListAddRow ( gridlist )
guiGridListSetItemText ( gridlist, row, columnnum, v["vehName"], false, false );
guiGridListSetItemText ( gridlist, row, columnnuma, tostring ( v["vehID"] ), false, false );
end
end;
end;
end;
Syntax :
changeGridlistToVehicleNamesAndIds ( element gridList, string sortType [ , int VehicleName columnIndex, int VehicleID columnIndex, string sortAZ ] )
Required Arguments :
gridList: القريد ليست
sortType: طريقة الترتيب يا بالايدي او بالاسم
( الايدي = "ID",,,, الاسم = "Name" )
Optional Arguments :
VehicleName columnIndex : كولمن اسم السيارة ( اذا تركته فاضي بيكون الكولمن 1)ء
VehicleID columnIndex : كولمن ايدي السيارة ( اذا تركته فاضي بيكون الكولمن 2 )ء
sortAZ : طريقة الترتيب يا
"AZ"
او
"ZA"
Example :
addEventHandler ( 'onClientResourceStart', root, function ( )
local screenW, screenH = guiGetScreenSize ( )
wnd = guiCreateWindow((screenW - 426) / 2, (screenH - 367) / 2, 426, 367, "EXAMPLE", false)
guiWindowSetSizable(wnd, false)
guiSetAlpha(wnd, 1.00)
guiSetVisible ( wnd, false )
Grid = guiCreateGridList(22, 40, 373, 292, false, wnd)
guiGridListAddColumn(Grid, "#Vehicle name", 0.5)
guiGridListAddColumn(Grid, "#Vehicle ID", 0.5)
changeGridlistToVehicleNamesAndIds ( Grid, "Name", 1, 2, "AZ" )
end )
bindKey ( 'F7', "down", function ( )
guiSetVisible ( wnd, not guiGetVisible ( wnd ) )
showCursor ( guiGetVisible ( wnd ) )
end )
function changeGridlistToVehicleNamesAndIds ( gridlist, sort, columnnum, columnnuma, AZ )
local vehsTable = { };
if not ( columnnum ) then
columnnum = 1
end;
if not ( columnnuma ) then
columnnuma = 2
end;
if not ( AZ ) then
AZ = "AZ"
end;
if ( gridlist and tostring ( sort ) and tostring ( AZ ) ) then
if ( getElementType ( gridlist ) == "gui-gridlist" ) then
guiGridListClear ( gridlist );
for i = 411, 611 do
if ( getVehicleNameFromModel ( i ) ~= "" ) then
table.insert ( vehsTable, { vehName = getVehicleNameFromModel ( i ), vehID = i } );
end;
end;
if ( sort == "ID" ) then
if ( AZ == "ZA" ) then
table.sort ( vehsTable, function ( a, b )
return
tonumber ( a["vehID"] ) > tonumber ( b["vehID"] )
end
);
else
if ( AZ == "AZ" ) then
table.sort ( vehsTable, function ( a, b )
return
tonumber ( a["vehID"] ) < tonumber ( b["vehID"] )
end
);
end;
end;
else
if ( sort == "Name" ) then
if ( AZ == "ZA" ) then
table.sort ( vehsTable, function ( a, b )
return
a["vehName"] > b["vehName"]
end
);
else
if ( AZ == "AZ" ) then
table.sort ( vehsTable, function ( a, b )
return
a["vehName"] < b["vehName"]
end
);
end;
end;
end;
end;
for _, v in ipairs ( vehsTable ) do
row = guiGridListAddRow ( gridlist )
guiGridListSetItemText ( gridlist, row, columnnum, v["vehName"], false, false );
guiGridListSetItemText ( gridlist, row, columnnuma, tostring ( v["vehID"] ), false, false );
end
end;
end;
end;