Advertisement
Guest User

client

a guest
Dec 16th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. local Dialog = ImportPackage("dialogui")
  2. local _ = function(k,...) return ImportPackage("i18n").t(GetPackageName(),k,...) end
  3.  
  4. local guidePNJ
  5. local GuideIds = { }
  6.  
  7. AddEvent("OnTranslationReady", function()
  8.     guidePNJ = Dialog.create(_("uneed"), nil, _("choice"), _("cancel"))
  9.     Dialog.addSelect(guidePNJ, 1, _("guide_menu"), 10)
  10. end)
  11.  
  12. function OnKeyPress(key)
  13.     if key == "E" then
  14.    
  15.         local NearestGuidePNJ = GetNearestGuidePNJ()
  16.         if NearestGuidePNJ ~= 0 then
  17.             CallRemoteEvent("guideInteract", NearestGuidePNJ)      
  18.         end
  19.     end
  20. end
  21. AddEvent("OnKeyPress", OnKeyPress)
  22.  
  23. AddEvent("OnDialogSubmit", function(dialog, button, ...)
  24.     if dialog == guidePNJ then
  25.         local args = { ... }
  26.         if button == 1 then
  27.             if args[1] == "" then
  28.             else
  29.                 AddPlayerChat(args[1]))
  30.         end
  31.     end
  32. end)
  33.  
  34. AddRemoteEvent("guideSetup", function(GuideObject)
  35.     GuideIds = GuideObject
  36. end)
  37.  
  38. function GetNearestGuidePNJ()
  39.     local x, y, z = GetPlayerLocation()
  40.     for k,v in pairs(GetStreamedNPC()) do
  41.         local x2, y2, z2 = GetNPCLocation(v)
  42.         local dist = GetDistance3D(x, y, z, x2, y2, z2)
  43.         if dist < 150.0 then
  44.             for k,i in pairs(GuideIds) do
  45.                 if v == i then
  46.                     return v
  47.                 end
  48.             end
  49.         end
  50.     end
  51.  
  52.     return 0
  53. end
  54.  
  55. function tablefind(tab, el)
  56.     for index, value in pairs(tab) do
  57.         if value == el then
  58.             return index
  59.         end
  60.     end
  61. end
  62.  
  63. AddRemoteEvent("openGuidePNJ", function(menuGuide))
  64.     local menuName = {}
  65.     for k,v in pairs(menuGuide) do
  66.         menuName[k] = _(k)
  67.     end
  68.     Dialog.setSelectLabeledOptions(guidePNJ, 1, 1, menuName)
  69.     Dialog.show(guidePNJ)
  70. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement