1
0
mirror of https://github.com/citizenfx/cfx-server-data.git synced 2025-01-11 00:03:18 +08:00
cfx-server-data/resources/[system]/chat/cl_chat.lua

139 lines
2.8 KiB
Lua
Raw Normal View History

2017-05-18 01:22:20 +08:00
local chatInputActive = false
local chatInputActivating = false
RegisterNetEvent('chatMessage')
2017-05-21 22:52:55 +08:00
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:clear')
2017-05-18 01:22:20 +08:00
2017-05-21 22:52:55 +08:00
-- internal events
RegisterNetEvent('__cfx_internal:serverPrint')
2017-05-21 22:52:55 +08:00
RegisterNetEvent('_chat:messageEntered')
--deprecated, use chat:addMessage
2017-05-18 01:22:20 +08:00
AddEventHandler('chatMessage', function(author, color, text)
local args = { text }
if author ~= "" then
table.insert(args, 1, author)
2017-05-18 01:22:20 +08:00
end
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = color,
multiline = true,
args = args
2017-05-18 01:22:20 +08:00
}
})
end)
AddEventHandler('__cfx_internal:serverPrint', function(msg)
print(msg)
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = { 0, 0, 0 },
multiline = true,
args = { msg }
}
})
end)
2017-05-21 22:52:55 +08:00
AddEventHandler('chat:addMessage', function(message)
2017-05-18 01:22:20 +08:00
SendNUIMessage({
type = 'ON_MESSAGE',
message = message
})
end)
2017-05-21 22:52:55 +08:00
AddEventHandler('chat:addSuggestion', function(name, help, params)
2017-05-18 01:22:20 +08:00
SendNUIMessage({
type = 'ON_SUGGESTION_ADD',
suggestion = {
name = name,
help = help,
params = params or nil
}
})
end)
2017-05-21 22:52:55 +08:00
AddEventHandler('chat:removeSuggestion', function(name)
SendNUIMessage({
type = 'ON_SUGGESTION_REMOVE',
name = name
})
end)
AddEventHandler('chat:addTemplate', function(id, html)
SendNUIMessage({
type = 'ON_TEMPLATE_ADD',
template = {
id = id,
html = html
}
})
end)
AddEventHandler('chat:clear', function(name)
SendNUIMessage({
type = 'ON_CLEAR'
})
end)
2017-05-18 01:22:20 +08:00
RegisterNUICallback('chatResult', function(data, cb)
chatInputActive = false
SetNuiFocus(false)
if not data.canceled then
local id = PlayerId()
2017-05-21 22:52:55 +08:00
--deprecated
local r, g, b = 0, 0x99, 255
if data.message:sub(1, 1) == '/' then
ExecuteCommand(data.message:sub(2))
else
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message)
end
2017-05-18 01:22:20 +08:00
end
cb('ok')
end)
RegisterNUICallback('loaded', function(data, cb)
2017-05-21 22:52:55 +08:00
TriggerServerEvent('chat:init');
2017-05-18 01:22:20 +08:00
cb('ok')
end)
Citizen.CreateThread(function()
SetTextChatEnabled(false)
2017-05-21 22:52:55 +08:00
SetNuiFocus(false)
2017-05-18 01:22:20 +08:00
while true do
Wait(0)
if not chatInputActive then
if IsControlPressed(0, 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then
chatInputActive = true
chatInputActivating = true
SendNUIMessage({
type = 'ON_OPEN'
})
end
end
if chatInputActivating then
if not IsControlPressed(0, 245) then
SetNuiFocus(true)
chatInputActivating = false
end
end
end
end)