csmit195

Vehicle Manager

Jan 24th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.84 KB | None | 0 0
  1. notAllowedTypes = {'Plane', 'Train', 'Trailer'}
  2.  
  3. GUIEditor = {
  4.     button = {},
  5.     edit = {},
  6.     window = {},
  7.     gridlist = {},
  8.     checkbox = {},
  9.     label = {},
  10.     radiobutton = {},
  11. }
  12. local screenW, screenH = guiGetScreenSize()
  13.  
  14. GUIEditor.window[2] = guiCreateWindow((screenW - 294) / 2, (screenH - 192) / 2, 294, 192, "[+] NEW SAVE", false)
  15. guiWindowSetSizable(GUIEditor.window[2], false)
  16. guiSetVisible(GUIEditor.window[2], false)
  17.  
  18. GUIEditor.edit[2] = guiCreateEdit(86, 28, 197, 25, "", false, GUIEditor.window[2])
  19. GUIEditor.label[2] = guiCreateLabel(10, 28, 64, 24, "Name:", false, GUIEditor.window[2])
  20. guiLabelSetVerticalAlign(GUIEditor.label[2], "center")
  21. GUIEditor.label[3] = guiCreateLabel(10, 57, 64, 24, "Vehicle:", false, GUIEditor.window[2])
  22. guiLabelSetVerticalAlign(GUIEditor.label[3], "center")
  23. GUIEditor.edit[3] = guiCreateEdit(85, 56, 199, 25, "Infernus", false, GUIEditor.window[2])
  24. guiEditSetReadOnly(GUIEditor.edit[3], true)
  25. GUIEditor.checkbox[1] = guiCreateCheckBox(85, 91, 99, 27, "Vehicle Color", true, false, GUIEditor.window[2])
  26. GUIEditor.label[5] = guiCreateLabel(10, 89, 64, 24, "Save:", false, GUIEditor.window[2])
  27. guiLabelSetVerticalAlign(GUIEditor.label[5], "center")
  28. GUIEditor.checkbox[2] = guiCreateCheckBox(188, 91, 91, 27, "Lights Color", true, false, GUIEditor.window[2])
  29. GUIEditor.checkbox[3] = guiCreateCheckBox(85, 123, 98, 27, "Upgrades", true, false, GUIEditor.window[2])
  30. GUIEditor.checkbox[4] = guiCreateCheckBox(187, 123, 89, 27, "Paintjob", true, false, GUIEditor.window[2])
  31. GUIEditor.button[5] = guiCreateButton(207, 155, 72, 27, "[+] ADD", false, GUIEditor.window[2])
  32. guiSetProperty(GUIEditor.button[5], "NormalTextColour", "FFAAAAAA")
  33. GUIEditor.button[6] = guiCreateButton(130, 155, 77, 27, "[x] CANCEL", false, GUIEditor.window[2])
  34. guiSetProperty(GUIEditor.button[6], "NormalTextColour", "FFAAAAAA")
  35.  
  36.  
  37. GUIEditor.window[1] = guiCreateWindow((screenW - 323) / 2, (screenH - 395) / 2, 323, 395, "F5 - Car Manager", false)
  38. guiWindowSetSizable(GUIEditor.window[1], false)
  39. guiSetVisible(GUIEditor.window[1], false)
  40.  
  41. GUIEditor.gridlist[1] = guiCreateGridList(10, 22, 304, 304, false, GUIEditor.window[1])
  42. name = guiGridListAddColumn(GUIEditor.gridlist[1], "Name", 0.3)
  43. vehicle = guiGridListAddColumn(GUIEditor.gridlist[1], "Vehicle", 0.3)
  44. date = guiGridListAddColumn(GUIEditor.gridlist[1], "Date", 0.3)
  45. guiGridListSetItemText(GUIEditor.gridlist[1], 0, 1, "-", false, false)
  46. guiGridListSetItemText(GUIEditor.gridlist[1], 0, 2, "Blista Compact", false, false)
  47. guiGridListSetItemText(GUIEditor.gridlist[1], 0, 3, "12/12/2222", false, false)
  48. GUIEditor.button[1] = guiCreateButton(234, 331, 79, 28, "Spawn", false, GUIEditor.window[1])
  49. guiSetProperty(GUIEditor.button[1], "NormalTextColour", "FFAAAAAA")
  50. GUIEditor.button[2] = guiCreateButton(10, 331, 79, 28, "[+] NEW", false, GUIEditor.window[1])
  51. guiSetProperty(GUIEditor.button[2], "NormalTextColour", "FFAAAAAA")
  52. GUIEditor.button[3] = guiCreateButton(89, 331, 79, 28, "[-] DELETE", false, GUIEditor.window[1])
  53. guiSetProperty(GUIEditor.button[3], "NormalTextColour", "FFAAAAAA")
  54. GUIEditor.radiobutton[1] = guiCreateRadioButton(20, 362, 72, 28, "English", false, GUIEditor.window[1])
  55. guiSetProperty(GUIEditor.radiobutton[1], "NormalTextColour", "C8FFFFFF")
  56. GUIEditor.radiobutton[2] = guiCreateRadioButton(101, 362, 71, 28, "Español", false, GUIEditor.window[1])
  57. guiSetProperty(GUIEditor.radiobutton[2], "NormalTextColour", "C8FFFFFF")
  58. guiRadioButtonSetSelected(GUIEditor.radiobutton[2], true)
  59.  
  60. xmlMain = xmlLoadFile('vehicles.xml') or xmlCreateFile('vehicles.xml', 'vehicles')
  61.  
  62. function activate()
  63.     if notAllowedTypes[getVehicleType(getPedOccupiedVehicle(localPlayer))] then outputChatBox('That vehicle is in the banlist!', 255, 0, 0) return end
  64.     for i, v in ipairs(xmlNodeGetChildren(xmlMain)) do
  65.         row = guiGridListAddRow(GUIEditor.gridlist[1])
  66.         guiGridListSetItemText(GUIEditor.gridlist[1], row, name, xmlNodeGetAttribute(v, 'name'), false, false)
  67.         guiGridListSetItemText(GUIEditor.gridlist[1], row, vehicle, getVehicleNameFromModel(xmlNodeGetAttribute(v, 'id')), false, false)
  68.         guiGridListSetItemText(GUIEditor.gridlist[1], row, date, xmlNodeGetAttribute(v, 'date'), false, false)
  69.     end
  70.  
  71.     guiSetVisible(GUIEditor.window[1], not guiGetVisible(GUIEditor.window[1]))
  72.     showCursor(guiGetVisible(GUIEditor.window[1]))
  73. end
  74. bindKey('F5', 'down', activate)
  75.  
  76. addEventHandler('onClientGUIClick', getRootElement(),
  77. function()
  78.     if source == GUIEditor.button[2] then -- NEW VEHICLE
  79.         guiSetText(GUIEditor.edit[3], getVehicleName(getPedOccupiedVehicle(localPlayer)))
  80.         guiSetVisible(GUIEditor.window[2], true)
  81.         guiSetInputEnabled(true)
  82.     elseif source == GUIEditor.button[5] then -- NEW WINDOW - ADD BUTTON
  83.         if guiGetText(GUIEditor.edit[2]) == '' then outputChatBox('Fill in the NAME field correctly!', 255, 0, 0) return end
  84.         local vehicle = getPedOccupiedVehicle(localPlayer)
  85.         local vehColor = guiCheckBoxGetSelected(GUIEditor.checkbox[1])
  86.         local vehLights = guiCheckBoxGetSelected(GUIEditor.checkbox[2])
  87.         local vehUpgrades = guiCheckBoxGetSelected(GUIEditor.checkbox[3])
  88.         local vehPaintjob = guiCheckBoxGetSelected(GUIEditor.checkbox[4])
  89.         xmlVehicleNode = xmlCreateChild(xmlMain, 'vehicle')
  90.         xmlNodeSetAttribute(xmlVehicleNode, 'name', guiGetText(GUIEditor.edit[2]))
  91.         xmlNodeSetAttribute(xmlVehicleNode, 'id', getElementModel(vehicle))
  92.         if vehColor then
  93.             local r, g, b = getVehicleColor(vehicle, true)
  94.             xmlNodeSetAttribute(xmlVehicleNode, 'vehred', r)
  95.             xmlNodeSetAttribute(xmlVehicleNode, 'vehgreen', g)
  96.             xmlNodeSetAttribute(xmlVehicleNode, 'vehblue', b)
  97.         end
  98.         if vehLights then
  99.             local r, g, b = getVehicleHeadLightColor(vehicle)
  100.             xmlNodeSetAttribute(xmlVehicleNode, 'lightsred', r)
  101.             xmlNodeSetAttribute(xmlVehicleNode, 'lightsgreen', g)
  102.             xmlNodeSetAttribute(xmlVehicleNode, 'lightsblue', b)
  103.         end
  104.         if vehUpgrades then
  105.             xmlUpgradesNode = xmlCreateChild(xmlVehicleNode, 'upgrades')
  106.             for i, v in ipairs(getVehicleUpgrades(vehicle)) do
  107.                 xmlNodeSetAttribute(xmlUpgradesNode, getVehicleUpgradeSlotName(v), v)
  108.             end
  109.         end
  110.         if vehPaintjob then
  111.             xmlNodeSetAttribute(xmlVehicleNode, 'paintjob', getVehiclePaintjob(vehicle))
  112.         end
  113.         xmlNodeSetAttribute(xmlVehicleNode, 'date', getRealTime()['monthday']..'/'..(getRealTime()['month'] + 1)..'/'..(getRealTime()['year'] + 1900))
  114.         xmlSaveFile(xmlMain)
  115.         guiSetVisible(GUIEditor.window[2], false)
  116.         guiSetInputEnabled(false)
  117.     elseif source == GUIEditor.button[6] then -- NEW WINDOW - CANCEL BUTTON
  118.         guiSetVisible(GUIEditor.window[2], false)
  119.         guiSetInputEnabled(false)
  120.     elseif source == GUIEditor.button[3] then -- DELETE VEHICLE
  121.        
  122.     end
  123. end )
  124.  
  125. addEventHandler('onClientPlayerQuit', getRootElement(),
  126. function()
  127.     if source == localPlayer then
  128.         xmlUnloadFile(xmlMain)
  129.     end
  130. end )
  131.  
  132. addEventHandler('onClientResourceStart', getRootElement(),
  133. function(res)
  134.     if res == this then
  135.         xmlUnloadFile(xmlMain)
  136.     end
  137. end )
Advertisement
Add Comment
Please, Sign In to add comment