Advertisement
bernard69

Untitled

Nov 18th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. name this cl_chat.lua ok? ok!
  2.  
  3.  
  4.  
  5. ---------------------------------
  6. local chatInputActive = false
  7. local chatInputActivating = false
  8.  
  9. RegisterNetEvent('chatMessage')
  10. RegisterNetEvent('chat:addTemplate')
  11. RegisterNetEvent('chat:addMessage')
  12. RegisterNetEvent('chat:addSuggestion')
  13. RegisterNetEvent('chat:removeSuggestion')
  14. RegisterNetEvent('chat:clear')
  15.  
  16. -- internal events
  17. RegisterNetEvent('__cfx_internal:serverPrint')
  18.  
  19. RegisterNetEvent('_chat:messageEntered')
  20.  
  21. --deprecated, use chat:addMessage
  22. AddEventHandler('chatMessage', function(author, color, text)
  23. local hud = exports["isPed"]:isPed("hud")
  24.  
  25. if color == 8 then
  26. TriggerEvent("phone:addnotification",author,text)
  27. return
  28. end
  29. if hud < 3 then
  30. local args = { text }
  31. if author ~= "" then
  32. table.insert(args, 1, author)
  33. end
  34. SendNUIMessage({
  35. type = 'ON_MESSAGE',
  36. message = {
  37. color = color,
  38. multiline = true,
  39. args = args
  40. }
  41. })
  42. end
  43. end)
  44.  
  45. AddEventHandler('__cfx_internal:serverPrint', function(msg)
  46. print(msg)
  47.  
  48. SendNUIMessage({
  49. type = 'ON_MESSAGE',
  50. message = {
  51. color = { 0, 0, 0 },
  52. multiline = true,
  53. args = { msg }
  54. }
  55. })
  56. end)
  57.  
  58.  
  59.  
  60. AddEventHandler('chat:addMessage', function(message)
  61. local hud = exports["isPed"]:isPed("hud")
  62. if hud then
  63. SendNUIMessage({
  64. type = 'ON_MESSAGE',
  65. message = message
  66. })
  67. end
  68. end)
  69.  
  70. AddEventHandler('chat:addSuggestion', function(name, help, params)
  71. SendNUIMessage({
  72. type = 'ON_SUGGESTION_ADD',
  73. suggestion = {
  74. name = name,
  75. help = help,
  76. params = params or nil
  77. }
  78. })
  79. end)
  80.  
  81. AddEventHandler('chat:removeSuggestion', function(name)
  82. SendNUIMessage({
  83. type = 'ON_SUGGESTION_REMOVE',
  84. name = name
  85. })
  86. end)
  87.  
  88. AddEventHandler('chat:addTemplate', function(id, html)
  89. SendNUIMessage({
  90. type = 'ON_TEMPLATE_ADD',
  91. template = {
  92. id = id,
  93. html = html
  94. }
  95. })
  96. end)
  97.  
  98. AddEventHandler('chat:clear', function(name)
  99. SendNUIMessage({
  100. type = 'ON_CLEAR'
  101. })
  102. end)
  103.  
  104. RegisterNUICallback('chatResult', function(data, cb)
  105. chatInputActive = false
  106. SetNuiFocus(false)
  107.  
  108. if not data.canceled then
  109. local id = PlayerId()
  110.  
  111. --deprecated
  112. local r, g, b = 0, 0x99, 255
  113.  
  114. TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message)
  115. end
  116.  
  117. cb('ok')
  118. end)
  119.  
  120. RegisterNUICallback('loaded', function(data, cb)
  121. TriggerServerEvent('chat:init');
  122.  
  123. cb('ok')
  124. end)
  125.  
  126. Citizen.CreateThread(function()
  127. SetTextChatEnabled(false)
  128. SetNuiFocus(false)
  129.  
  130. while true do
  131. Wait(0)
  132.  
  133. if not chatInputActive then
  134. if IsControlPressed(0, 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then
  135. chatInputActive = true
  136. chatInputActivating = true
  137. local hud = exports["isPed"]:isPed("hud")
  138.  
  139.  
  140. SendNUIMessage({
  141. type = 'HUD_CHANGE',
  142. hudtype = hud,
  143. })
  144.  
  145. SendNUIMessage({
  146. type = 'ON_OPEN',
  147. })
  148.  
  149. end
  150. end
  151.  
  152. if chatInputActivating then
  153. if not IsControlPressed(0, 245) then
  154. SetNuiFocus(true)
  155.  
  156. chatInputActivating = false
  157. end
  158. end
  159. end
  160. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement