Advertisement
Guest User

Untitled

a guest
May 24th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. --just a testing table you can remove this and add the one you have in skin shop script.
  2. local skinSelectionTable = {
  3. ["cj"] = 0,
  4. ["truth"] = 1,
  5. ["maccer"] = 2,
  6. ["andre"] = 3,
  7. ["Barry"] = 4,
  8. ["Barry Big"] = 5,
  9. ["emmet"] = 6,
  10. ["Taxi Driver"] = 7,
  11. ["janitor"] = 8,
  12. ["Normal Ped"] = 9
  13. }
  14.  
  15. --creating the GUI
  16. function runGUI()
  17. guiMainWindow = guiCreateWindow(725, 275, 336, 478, "Guard", false)
  18. guiWindowSetSizable(guiMainWindow, false)
  19. guiGridList = guiCreateGridList(10, 25, 316, 379, false, guiMainWindow)
  20. guiGridListAddColumn(guiGridList, "Skin name", 0.5)
  21. guiGridListAddColumn(guiGridList, "Skin id", 0.5)
  22. guiCloseButton = guiCreateButton(16, 412, 127, 49, "Close", false, guiMainWindow)
  23. guiCreateButton = guiCreateButton(189, 412, 127, 49, "Choose Guard", false, guiMainWindow)
  24. guiSetVisible(guiMainWindow, false)
  25. -- to hide the GUI after they click "Close" button
  26. addEventHandler("onClientGUIClick", guiCloseButton, function()
  27. guiSetVisible(guiMainWindow, false)
  28. showCursor(false, true)
  29. end)
  30.  
  31. addEventHandler("onClientGUIClick", guiCreateButton, createGuardHandler)
  32. populateGridlist()
  33. end
  34. --opening the GUI with the commandHandler.
  35. function openGUI()
  36. if not (guiGetVisible(guiMainWindow)) then
  37. guiSetVisible(guiMainWindow, true)
  38. showCursor(true, true)
  39. end
  40. end
  41. -- to add the table to the gridList
  42. function populateGridlist()
  43. for name, skin in pairs(skinSelectionTable) do
  44. local row = guiGridListAddRow(guiGridList)
  45.  
  46. guiGridListSetItemText(guiGridList, row, 1, name, false, false)
  47. guiGridListSetItemText(guiGridList, row, 2, skin, false, false)
  48. guiGridListSetItemData(guiGridList, row, 1, tostring(skin))
  49. end
  50. end
  51. --creating event to trigger in server-sided in order to create the ped.
  52. function createGuardHandler(button, state)
  53. if (button == "left" and state == "up") then
  54. local row, col = guiGridListGetSelectedItem(guiGridList)
  55.  
  56. if (row and col and row ~= -1 and col ~= -1) then
  57. selected = guiGridListGetItemData(guiGridList,row,col)
  58. selected = tonumber(selected)
  59.  
  60. if (selected) then
  61. --you probably need to change this, couldnt find the CIT message export.
  62. outputChatBox("Guard has been chosen")
  63. guiSetVisible(guiMainWindow, false)
  64. showCursor(false, false)
  65. else
  66. --you probably need to change this, couldnt find the CIT error message export.
  67. outputChatBox("Error")
  68. end
  69. end
  70. end
  71. end
  72. --triggering the event here with a different commandHandler.
  73. function createGuard()
  74. if (selected) then
  75. local player = getLocalPlayer()
  76. triggerServerEvent("createGuardFromGUI", getRootElement(), selected, player)
  77. end
  78. end
  79.  
  80. addCommandHandler("guard", createGuard)
  81. addCommandHandler("chooseguard", function()
  82. if not(guiMainWindow) then
  83. runGUI()
  84. end
  85. openGUI()
  86. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement