mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-01-11 00:03:18 +08:00
119 lines
2.4 KiB
Lua
119 lines
2.4 KiB
Lua
local chatInputActive = false
|
|
local chatInputActivating = false
|
|
|
|
RegisterNetEvent('chatMessage')
|
|
RegisterNetEvent('chat:addTemplate')
|
|
RegisterNetEvent('chat:addMessage')
|
|
RegisterNetEvent('chat:addSuggestion')
|
|
RegisterNetEvent('chat:removeSuggestion')
|
|
RegisterNetEvent('chat:clear')
|
|
|
|
-- internal events
|
|
RegisterNetEvent('_chat:messageEntered')
|
|
|
|
--deprecated, use chat:addMessage
|
|
AddEventHandler('chatMessage', function(author, color, text)
|
|
if author == "" then
|
|
author = false
|
|
end
|
|
SendNUIMessage({
|
|
type = 'ON_MESSAGE',
|
|
message = {
|
|
color = color,
|
|
multiline = true,
|
|
args = { author, text }
|
|
}
|
|
})
|
|
end)
|
|
|
|
AddEventHandler('chat:addMessage', function(message)
|
|
SendNUIMessage({
|
|
type = 'ON_MESSAGE',
|
|
message = message
|
|
})
|
|
end)
|
|
|
|
AddEventHandler('chat:addSuggestion', function(name, help, params)
|
|
SendNUIMessage({
|
|
type = 'ON_SUGGESTION_ADD',
|
|
suggestion = {
|
|
name = name,
|
|
help = help,
|
|
params = params or nil
|
|
}
|
|
})
|
|
end)
|
|
|
|
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)
|
|
|
|
RegisterNUICallback('chatResult', function(data, cb)
|
|
chatInputActive = false
|
|
SetNuiFocus(false)
|
|
|
|
if not data.canceled then
|
|
local id = PlayerId()
|
|
|
|
--deprecated
|
|
local r, g, b = 0, 0x99, 255
|
|
|
|
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message)
|
|
end
|
|
|
|
cb('ok')
|
|
end)
|
|
|
|
RegisterNUICallback('loaded', function(data, cb)
|
|
TriggerServerEvent('chat:init');
|
|
|
|
cb('ok')
|
|
end)
|
|
|
|
Citizen.CreateThread(function()
|
|
SetTextChatEnabled(false)
|
|
SetNuiFocus(false)
|
|
|
|
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)
|