Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
隱藏空白變更
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
文字樣式
變更外觀
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
Chat
建立於
4 年前
差異永不過期
清除
匯出
分享
解釋
3 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
308 行
全部複製
35 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
309 行
全部複製
local isRDR = not TerraingridActivate and true or false
local isRDR = not TerraingridActivate and true or false
local chatInputActive = false
local chatInputActive = false
local chatInputActivating = false
local chatInputActivating = false
local chatLoaded = false
local chatLoaded = false
RegisterNetEvent('chatMessage')
RegisterNetEvent('chatMessage')
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:addSuggestions')
RegisterNetEvent('chat:addSuggestions')
RegisterNetEvent('chat:addMode')
RegisterNetEvent('chat:addMode')
RegisterNetEvent('chat:removeMode')
RegisterNetEvent('chat:removeMode')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:clear')
RegisterNetEvent('chat:clear')
-- internal events
-- internal events
RegisterNetEvent('__cfx_internal:serverPrint')
RegisterNetEvent('__cfx_internal:serverPrint')
RegisterNetEvent('_chat:messageEntered')
RegisterNetEvent('_chat:messageEntered')
--deprecated, use chat:addMessage
--deprecated, use chat:addMessage
AddEventHandler('chatMessage', function(author, color, text)
AddEventHandler('chatMessage', function(author, color, text)
local args = { text }
local args = { text }
if author ~= "" then
if author ~= "" then
table.insert(args, 1, author)
table.insert(args, 1, author)
end
end
SendNUIMessage({
SendNUIMessage({
type = 'ON_MESSAGE',
type = 'ON_MESSAGE',
message = {
message = {
color = color,
color = color,
multiline = true,
multiline = true,
args = args
args = args
}
}
})
})
end)
end)
AddEventHandler('__cfx_internal:serverPrint', function(msg)
AddEventHandler('__cfx_internal:serverPrint', function(msg)
print(msg)
print(msg)
SendNUIMessage({
SendNUIMessage({
type = 'ON_MESSAGE',
type = 'ON_MESSAGE',
message = {
message = {
templateId = 'print',
templateId = 'print',
multiline = true,
multiline = true,
args = { msg },
args = { msg },
mode = '_global'
mode = '_global'
}
}
})
})
end)
end)
-- addMessage
-- addMessage
local addMessage = function(message)
local addMessage = function(message)
if type(message) == 'string' then
if type(message) == 'string' then
message = {
message = {
args = { message }
args = { message }
}
}
end
end
SendNUIMessage({
SendNUIMessage({
type = 'ON_MESSAGE',
type = 'ON_MESSAGE',
message = message
message = message
})
})
end
end
exports('addMessage', addMessage)
exports('addMessage', addMessage)
AddEventHandler('chat:addMessage', addMessage)
AddEventHandler('chat:addMessage', addMessage)
-- addSuggestion
-- addSuggestion
local addSuggestion = function(name, help, params)
local addSuggestion = function(name, help, params)
SendNUIMessage({
SendNUIMessage({
type = 'ON_SUGGESTION_ADD',
type = 'ON_SUGGESTION_ADD',
suggestion = {
suggestion = {
name = name,
name = name,
help = help,
help = help,
params = params or nil
params = params or nil
}
}
})
})
end
end
exports('addSuggestion', addSuggestion)
exports('addSuggestion', addSuggestion)
AddEventHandler('chat:addSuggestion', addSuggestion)
AddEventHandler('chat:addSuggestion', addSuggestion)
AddEventHandler('chat:addSuggestions', function(suggestions)
AddEventHandler('chat:addSuggestions', function(suggestions)
for _, suggestion in ipairs(suggestions) do
for _, suggestion in ipairs(suggestions) do
SendNUIMessage({
SendNUIMessage({
type = 'ON_SUGGESTION_ADD',
type = 'ON_SUGGESTION_ADD',
suggestion = suggestion
suggestion = suggestion
})
})
end
end
end)
end)
AddEventHandler('chat:removeSuggestion', function(name)
AddEventHandler('chat:removeSuggestion', function(name)
SendNUIMessage({
SendNUIMessage({
type = 'ON_SUGGESTION_REMOVE',
type = 'ON_SUGGESTION_REMOVE',
name = name
name = name
})
})
end)
end)
AddEventHandler('chat:addMode', function(mode)
AddEventHandler('chat:addMode', function(mode)
SendNUIMessage({
SendNUIMessage({
type = 'ON_MODE_ADD',
type = 'ON_MODE_ADD',
mode = mode
mode = mode
})
})
end)
end)
AddEventHandler('chat:removeMode', function(name)
AddEventHandler('chat:removeMode', function(name)
SendNUIMessage({
SendNUIMessage({
type = 'ON_MODE_REMOVE',
type = 'ON_MODE_REMOVE',
name = name
name = name
})
})
end)
end)
AddEventHandler('chat:addTemplate', function(id, html)
AddEventHandler('chat:addTemplate', function(id, html)
SendNUIMessage({
SendNUIMessage({
type = 'ON_TEMPLATE_ADD',
type = 'ON_TEMPLATE_ADD',
template = {
template = {
id = id,
id = id,
html = html
html = html
}
}
})
})
end)
end)
AddEventHandler('chat:clear', function(name)
AddEventHandler('chat:clear', function(name)
SendNUIMessage({
SendNUIMessage({
type = 'ON_CLEAR'
type = 'ON_CLEAR'
})
})
end)
end)
RegisterNUICallback('chatResult', function(data, cb)
RegisterNUICallback('chatResult', function(data, cb)
chatInputActive = false
chatInputActive = false
SetNuiFocus(false)
SetNuiFocus(false)
if not data.canceled then
if not data.canceled then
local id = PlayerId()
local id = PlayerId()
--deprecated
--deprecated
local r, g, b = 0, 0x99, 255
local r, g, b = 0, 0x99, 255
if data.message:sub(1, 1) == '/' then
if data.message:sub(1, 1) == '/' then
ExecuteCommand(data.message:sub(2))
ExecuteCommand(data.message:sub(2))
else
else
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message, data.mode)
TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message, data.mode)
end
end
end
end
cb('ok')
cb('ok')
end)
end)
local function refreshCommands()
local function refreshCommands()
if GetRegisteredCommands then
if GetRegisteredCommands then
local registeredCommands = GetRegisteredCommands()
local registeredCommands = GetRegisteredCommands()
local suggestions = {}
local suggestions = {}
for _, command in ipairs(registeredCommands) do
for _, command in ipairs(registeredCommands) do
if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then
if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then
table.insert(suggestions, {
table.insert(suggestions, {
name = '/' .. command.name,
name = '/' .. command.name,
help = ''
help = ''
})
})
end
end
end
end
TriggerEvent('chat:addSuggestions', suggestions)
TriggerEvent('chat:addSuggestions', suggestions)
end
end
end
end
local function refreshThemes()
local function refreshThemes()
local themes = {}
local themes = {}
for resIdx = 0, GetNumResources() - 1 do
for resIdx = 0, GetNumResources() - 1 do
local resource = GetResourceByFindIndex(resIdx)
local resource = GetResourceByFindIndex(resIdx)
if GetResourceState(resource) == 'started' then
if GetResourceState(resource) == 'started' then
local numThemes = GetNumResourceMetadata(resource, 'chat_theme')
local numThemes = GetNumResourceMetadata(resource, 'chat_theme')
if numThemes > 0 then
if numThemes > 0 then
local themeName = GetResourceMetadata(resource, 'chat_theme')
local themeName = GetResourceMetadata(resource, 'chat_theme')
local themeData = json.decode(GetResourceMetadata(resource, 'chat_theme_extra') or 'null')
local themeData = json.decode(GetResourceMetadata(resource, 'chat_theme_extra') or 'null')
if themeName and themeData then
if themeName and themeData then
themeData.baseUrl = 'nui://' .. resource .. '/'
themeData.baseUrl = 'nui://' .. resource .. '/'
themes[themeName] = themeData
themes[themeName] = themeData
end
end
end
end
end
end
end
end
SendNUIMessage({
SendNUIMessage({
type = 'ON_UPDATE_THEMES',
type = 'ON_UPDATE_THEMES',
themes = themes
themes = themes
})
})
end
end
AddEventHandler('onClientResourceStart', function(resName)
AddEventHandler('onClientResourceStart', function(resName)
Wait(500)
Wait(500)
複製
已複製
複製
已複製
SetTextChatEnabled(true)
refreshCommands()
--
refreshCommands()
refreshThemes()
--
refreshThemes()
end)
end)
AddEventHandler('onClientResourceStop', function(resName)
AddEventHandler('onClientResourceStop', function(resName)
Wait(500)
Wait(500)
複製
已複製
複製
已複製
refreshCommands()
--
refreshCommands()
refreshThemes()
--
refreshThemes()
end)
end)
RegisterNUICallback('loaded', function(data, cb)
RegisterNUICallback('loaded', function(data, cb)
複製
已複製
複製
已複製
TriggerServerEvent('chat:init')
--
TriggerServerEvent('chat:init')
複製
已複製
複製
已複製
refreshCommands()
--
refreshCommands()
refreshThemes()
--
refreshThemes()
chatLoaded = true
chatLoaded = true
cb('ok')
cb('ok')
end)
end)
local CHAT_HIDE_STATES = {
local CHAT_HIDE_STATES = {
SHOW_WHEN_ACTIVE = 0,
SHOW_WHEN_ACTIVE = 0,
ALWAYS_SHOW = 1,
ALWAYS_SHOW = 1,
ALWAYS_HIDE = 2
ALWAYS_HIDE = 2
}
}
local kvpEntry = GetResourceKvpString('hideState')
local kvpEntry = GetResourceKvpString('hideState')
local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
local isFirstHide = true
local isFirstHide = true
複製
已複製
複製
已複製
if not isRDR then
--
if not isRDR then
if RegisterKeyMapping then
--
if RegisterKeyMapping then
RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l')
--
RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l')
end
--
end
--
RegisterCommand('toggleChat', function()
--
RegisterCommand('toggleChat', function()
if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then
--
if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
--
chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then
--
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
--
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then
--
elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
--
chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE
end
--
end
--
isFirstHide = false
--
isFirstHide = false
--
SetResourceKvp('hideState', tostring(chatHideState))
--
SetResourceKvp('hideState', tostring(chatHideState))
end, false)
--
end, false)
end
--
end
--
Citizen.CreateThread(function()
Citizen.CreateThread(function()
SetTextChatEnabled(false)
SetTextChatEnabled(false)
SetNuiFocus(false)
SetNuiFocus(false)
local lastChatHideState = -1
local lastChatHideState = -1
local origChatHideState = -1
local origChatHideState = -1
while true do
while true do
Wait(0)
Wait(0)
if not chatInputActive then
if not chatInputActive then
if IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then
if IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then
複製
已複製
複製
已複製
chatInputActive =
true
chatInputActive =
false
chatInputActivating =
true
chatInputActivating =
false
複製
已複製
複製
已複製
SendNUIMessage({
--
SendNUIMessage({
type = 'ON_OPEN'
--
type = 'ON_OPEN'
})
--
})
end
end
end
end
if chatInputActivating then
if chatInputActivating then
if not IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) then
if not IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) then
複製
已複製
複製
已複製
SetNuiFocus(
true
)
SetNuiFocus(
false
)
chatInputActivating = false
chatInputActivating = false
end
end
end
end
if chatLoaded then
if chatLoaded then
local forceHide = IsScreenFadedOut() or IsPauseMenuActive()
local forceHide = IsScreenFadedOut() or IsPauseMenuActive()
local wasForceHide = false
local wasForceHide = false
if chatHideState ~= CHAT_HIDE_STATES.ALWAYS_HIDE then
if chatHideState ~= CHAT_HIDE_STATES.ALWAYS_HIDE then
if forceHide then
if forceHide then
origChatHideState = chatHideState
origChatHideState = chatHideState
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE
end
end
elseif not forceHide and origChatHideState ~= -1 then
elseif not forceHide and origChatHideState ~= -1 then
chatHideState = origChatHideState
chatHideState = origChatHideState
origChatHideState = -1
origChatHideState = -1
wasForceHide = true
wasForceHide = true
end
end
if chatHideState ~= lastChatHideState then
if chatHideState ~= lastChatHideState then
lastChatHideState = chatHideState
lastChatHideState = chatHideState
SendNUIMessage({
SendNUIMessage({
type = 'ON_SCREEN_STATE_CHANGE',
type = 'ON_SCREEN_STATE_CHANGE',
hideState = chatHideState,
hideState = chatHideState,
fromUserInteraction = not forceHide and not isFirstHide and not wasForceHide
fromUserInteraction = not forceHide and not isFirstHide and not wasForceHide
})
})
isFirstHide = false
isFirstHide = false
end
end
end
end
end
end
end)
end)
複製
已複製
複製
已複製
已保存差異
原始文本
開啟檔案
local isRDR = not TerraingridActivate and true or false local chatInputActive = false local chatInputActivating = false local chatLoaded = false RegisterNetEvent('chatMessage') RegisterNetEvent('chat:addTemplate') RegisterNetEvent('chat:addMessage') RegisterNetEvent('chat:addSuggestion') RegisterNetEvent('chat:addSuggestions') RegisterNetEvent('chat:addMode') RegisterNetEvent('chat:removeMode') RegisterNetEvent('chat:removeSuggestion') RegisterNetEvent('chat:clear') -- internal events RegisterNetEvent('__cfx_internal:serverPrint') RegisterNetEvent('_chat:messageEntered') --deprecated, use chat:addMessage AddEventHandler('chatMessage', function(author, color, text) local args = { text } if author ~= "" then table.insert(args, 1, author) end SendNUIMessage({ type = 'ON_MESSAGE', message = { color = color, multiline = true, args = args } }) end) AddEventHandler('__cfx_internal:serverPrint', function(msg) print(msg) SendNUIMessage({ type = 'ON_MESSAGE', message = { templateId = 'print', multiline = true, args = { msg }, mode = '_global' } }) end) -- addMessage local addMessage = function(message) if type(message) == 'string' then message = { args = { message } } end SendNUIMessage({ type = 'ON_MESSAGE', message = message }) end exports('addMessage', addMessage) AddEventHandler('chat:addMessage', addMessage) -- addSuggestion local addSuggestion = function(name, help, params) SendNUIMessage({ type = 'ON_SUGGESTION_ADD', suggestion = { name = name, help = help, params = params or nil } }) end exports('addSuggestion', addSuggestion) AddEventHandler('chat:addSuggestion', addSuggestion) AddEventHandler('chat:addSuggestions', function(suggestions) for _, suggestion in ipairs(suggestions) do SendNUIMessage({ type = 'ON_SUGGESTION_ADD', suggestion = suggestion }) end end) AddEventHandler('chat:removeSuggestion', function(name) SendNUIMessage({ type = 'ON_SUGGESTION_REMOVE', name = name }) end) AddEventHandler('chat:addMode', function(mode) SendNUIMessage({ type = 'ON_MODE_ADD', mode = mode }) end) AddEventHandler('chat:removeMode', function(name) SendNUIMessage({ type = 'ON_MODE_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 if data.message:sub(1, 1) == '/' then ExecuteCommand(data.message:sub(2)) else TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message, data.mode) end end cb('ok') end) local function refreshCommands() if GetRegisteredCommands then local registeredCommands = GetRegisteredCommands() local suggestions = {} for _, command in ipairs(registeredCommands) do if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then table.insert(suggestions, { name = '/' .. command.name, help = '' }) end end TriggerEvent('chat:addSuggestions', suggestions) end end local function refreshThemes() local themes = {} for resIdx = 0, GetNumResources() - 1 do local resource = GetResourceByFindIndex(resIdx) if GetResourceState(resource) == 'started' then local numThemes = GetNumResourceMetadata(resource, 'chat_theme') if numThemes > 0 then local themeName = GetResourceMetadata(resource, 'chat_theme') local themeData = json.decode(GetResourceMetadata(resource, 'chat_theme_extra') or 'null') if themeName and themeData then themeData.baseUrl = 'nui://' .. resource .. '/' themes[themeName] = themeData end end end end SendNUIMessage({ type = 'ON_UPDATE_THEMES', themes = themes }) end AddEventHandler('onClientResourceStart', function(resName) Wait(500) refreshCommands() refreshThemes() end) AddEventHandler('onClientResourceStop', function(resName) Wait(500) refreshCommands() refreshThemes() end) RegisterNUICallback('loaded', function(data, cb) TriggerServerEvent('chat:init') refreshCommands() refreshThemes() chatLoaded = true cb('ok') end) local CHAT_HIDE_STATES = { SHOW_WHEN_ACTIVE = 0, ALWAYS_SHOW = 1, ALWAYS_HIDE = 2 } local kvpEntry = GetResourceKvpString('hideState') local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE local isFirstHide = true if not isRDR then if RegisterKeyMapping then RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l') end RegisterCommand('toggleChat', function() if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE end isFirstHide = false SetResourceKvp('hideState', tostring(chatHideState)) end, false) end Citizen.CreateThread(function() SetTextChatEnabled(false) SetNuiFocus(false) local lastChatHideState = -1 local origChatHideState = -1 while true do Wait(0) if not chatInputActive then if IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then chatInputActive = true chatInputActivating = true SendNUIMessage({ type = 'ON_OPEN' }) end end if chatInputActivating then if not IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) then SetNuiFocus(true) chatInputActivating = false end end if chatLoaded then local forceHide = IsScreenFadedOut() or IsPauseMenuActive() local wasForceHide = false if chatHideState ~= CHAT_HIDE_STATES.ALWAYS_HIDE then if forceHide then origChatHideState = chatHideState chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE end elseif not forceHide and origChatHideState ~= -1 then chatHideState = origChatHideState origChatHideState = -1 wasForceHide = true end if chatHideState ~= lastChatHideState then lastChatHideState = chatHideState SendNUIMessage({ type = 'ON_SCREEN_STATE_CHANGE', hideState = chatHideState, fromUserInteraction = not forceHide and not isFirstHide and not wasForceHide }) isFirstHide = false end end end end)
更改後文本
開啟檔案
local isRDR = not TerraingridActivate and true or false local chatInputActive = false local chatInputActivating = false local chatLoaded = false RegisterNetEvent('chatMessage') RegisterNetEvent('chat:addTemplate') RegisterNetEvent('chat:addMessage') RegisterNetEvent('chat:addSuggestion') RegisterNetEvent('chat:addSuggestions') RegisterNetEvent('chat:addMode') RegisterNetEvent('chat:removeMode') RegisterNetEvent('chat:removeSuggestion') RegisterNetEvent('chat:clear') -- internal events RegisterNetEvent('__cfx_internal:serverPrint') RegisterNetEvent('_chat:messageEntered') --deprecated, use chat:addMessage AddEventHandler('chatMessage', function(author, color, text) local args = { text } if author ~= "" then table.insert(args, 1, author) end SendNUIMessage({ type = 'ON_MESSAGE', message = { color = color, multiline = true, args = args } }) end) AddEventHandler('__cfx_internal:serverPrint', function(msg) print(msg) SendNUIMessage({ type = 'ON_MESSAGE', message = { templateId = 'print', multiline = true, args = { msg }, mode = '_global' } }) end) -- addMessage local addMessage = function(message) if type(message) == 'string' then message = { args = { message } } end SendNUIMessage({ type = 'ON_MESSAGE', message = message }) end exports('addMessage', addMessage) AddEventHandler('chat:addMessage', addMessage) -- addSuggestion local addSuggestion = function(name, help, params) SendNUIMessage({ type = 'ON_SUGGESTION_ADD', suggestion = { name = name, help = help, params = params or nil } }) end exports('addSuggestion', addSuggestion) AddEventHandler('chat:addSuggestion', addSuggestion) AddEventHandler('chat:addSuggestions', function(suggestions) for _, suggestion in ipairs(suggestions) do SendNUIMessage({ type = 'ON_SUGGESTION_ADD', suggestion = suggestion }) end end) AddEventHandler('chat:removeSuggestion', function(name) SendNUIMessage({ type = 'ON_SUGGESTION_REMOVE', name = name }) end) AddEventHandler('chat:addMode', function(mode) SendNUIMessage({ type = 'ON_MODE_ADD', mode = mode }) end) AddEventHandler('chat:removeMode', function(name) SendNUIMessage({ type = 'ON_MODE_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 if data.message:sub(1, 1) == '/' then ExecuteCommand(data.message:sub(2)) else TriggerServerEvent('_chat:messageEntered', GetPlayerName(id), { r, g, b }, data.message, data.mode) end end cb('ok') end) local function refreshCommands() if GetRegisteredCommands then local registeredCommands = GetRegisteredCommands() local suggestions = {} for _, command in ipairs(registeredCommands) do if IsAceAllowed(('command.%s'):format(command.name)) and command.name ~= 'toggleChat' then table.insert(suggestions, { name = '/' .. command.name, help = '' }) end end TriggerEvent('chat:addSuggestions', suggestions) end end local function refreshThemes() local themes = {} for resIdx = 0, GetNumResources() - 1 do local resource = GetResourceByFindIndex(resIdx) if GetResourceState(resource) == 'started' then local numThemes = GetNumResourceMetadata(resource, 'chat_theme') if numThemes > 0 then local themeName = GetResourceMetadata(resource, 'chat_theme') local themeData = json.decode(GetResourceMetadata(resource, 'chat_theme_extra') or 'null') if themeName and themeData then themeData.baseUrl = 'nui://' .. resource .. '/' themes[themeName] = themeData end end end end SendNUIMessage({ type = 'ON_UPDATE_THEMES', themes = themes }) end AddEventHandler('onClientResourceStart', function(resName) Wait(500) SetTextChatEnabled(true) -- refreshCommands() -- refreshThemes() end) AddEventHandler('onClientResourceStop', function(resName) Wait(500) -- refreshCommands() -- refreshThemes() end) RegisterNUICallback('loaded', function(data, cb) -- TriggerServerEvent('chat:init') -- refreshCommands() -- refreshThemes() chatLoaded = true cb('ok') end) local CHAT_HIDE_STATES = { SHOW_WHEN_ACTIVE = 0, ALWAYS_SHOW = 1, ALWAYS_HIDE = 2 } local kvpEntry = GetResourceKvpString('hideState') local chatHideState = kvpEntry and tonumber(kvpEntry) or CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE local isFirstHide = true -- if not isRDR then -- if RegisterKeyMapping then -- RegisterKeyMapping('toggleChat', 'Toggle chat', 'keyboard', 'l') -- end -- -- RegisterCommand('toggleChat', function() -- if chatHideState == CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE then -- chatHideState = CHAT_HIDE_STATES.ALWAYS_SHOW -- elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_SHOW then -- chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE -- elseif chatHideState == CHAT_HIDE_STATES.ALWAYS_HIDE then -- chatHideState = CHAT_HIDE_STATES.SHOW_WHEN_ACTIVE -- end -- -- isFirstHide = false -- -- SetResourceKvp('hideState', tostring(chatHideState)) -- end, false) -- end -- Citizen.CreateThread(function() SetTextChatEnabled(false) SetNuiFocus(false) local lastChatHideState = -1 local origChatHideState = -1 while true do Wait(0) if not chatInputActive then if IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) --[[ INPUT_MP_TEXT_CHAT_ALL ]] then chatInputActive = false chatInputActivating = false -- SendNUIMessage({ -- type = 'ON_OPEN' -- }) end end if chatInputActivating then if not IsControlPressed(0, isRDR and `INPUT_MP_TEXT_CHAT_ALL` or 245) then SetNuiFocus(false) chatInputActivating = false end end if chatLoaded then local forceHide = IsScreenFadedOut() or IsPauseMenuActive() local wasForceHide = false if chatHideState ~= CHAT_HIDE_STATES.ALWAYS_HIDE then if forceHide then origChatHideState = chatHideState chatHideState = CHAT_HIDE_STATES.ALWAYS_HIDE end elseif not forceHide and origChatHideState ~= -1 then chatHideState = origChatHideState origChatHideState = -1 wasForceHide = true end if chatHideState ~= lastChatHideState then lastChatHideState = chatHideState SendNUIMessage({ type = 'ON_SCREEN_STATE_CHANGE', hideState = chatHideState, fromUserInteraction = not forceHide and not isFirstHide and not wasForceHide }) isFirstHide = false end end end end)
尋找差異