Skip to content
This repository was archived by the owner on Apr 7, 2023. It is now read-only.

Chat Visibility Toggle #12

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Chat Visibility Toggle
/togglechat
  • Loading branch information
TheStonedTurtle committed Aug 19, 2017
commit 54404fbab5f3738183c0b265525fca6727d1865c
70 changes: 49 additions & 21 deletions resources/[system]/chat/cl_chat.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
local chatInputActive = false
local chatInputActivating = false
local chatVisibilityToggle = false

RegisterNetEvent('chatMessage')
RegisterNetEvent('chat:addTemplate')
RegisterNetEvent('chat:addMessage')
RegisterNetEvent('chat:addSuggestion')
RegisterNetEvent('chat:removeSuggestion')
RegisterNetEvent('chat:clear')
RegisterNetEvent('chat:toggleChat')

-- internal events
RegisterNetEvent('__cfx_internal:serverPrint')
Expand All @@ -19,34 +21,41 @@ AddEventHandler('chatMessage', function(author, color, text)
if author ~= "" then
table.insert(args, 1, author)
end
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = color,
multiline = true,
args = args
}
})

if(not chatVisibilityToggle)then
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = color,
multiline = true,
args = args
}
})
end
end)

AddEventHandler('__cfx_internal:serverPrint', function(msg)
print(msg)

SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = { 0, 0, 0 },
multiline = true,
args = { msg }
}
})
if(not chatVisibilityToggle)then
SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = { 0, 0, 0 },
multiline = true,
args = { msg }
}
})
end
end)

AddEventHandler('chat:addMessage', function(message)
SendNUIMessage({
type = 'ON_MESSAGE',
message = message
})
if(not chatVisibilityToggle)then
SendNUIMessage({
type = 'ON_MESSAGE',
message = message
})
end
end)

AddEventHandler('chat:addSuggestion', function(name, help, params)
Expand Down Expand Up @@ -83,6 +92,25 @@ AddEventHandler('chat:clear', function(name)
})
end)

AddEventHandler('chat:toggleChat',function()
chatVisibilityToggle = not chatVisibilityToggle

Copy link

@murfasa murfasa Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add TriggerEvent('chat:clear') so it clears everything beforehand. Tested and it works.

local state = (chatVisibilityToggle == true) and "^1disabled" or "^2enabled"

SendNUIMessage({
type = 'ON_MESSAGE',
message = {
color = {255,255,255},
multiline = true,
args = {"Chat Visibility has been "..state}
}
})
end)

RegisterCommand("togglechat",function()
TriggerEvent('chat:toggleChat')
end)

RegisterNUICallback('chatResult', function(data, cb)
chatInputActive = false
SetNuiFocus(false)
Expand Down Expand Up @@ -135,4 +163,4 @@ Citizen.CreateThread(function()
end
end
end
end)
end)