Skip to content

Commit

Permalink
Fix chat messages sent twice (#566)
Browse files Browse the repository at this point in the history
* .

* change playercolors onPlayerChat

* comment
  • Loading branch information
Fernando-A-Rocha authored Nov 13, 2024
1 parent eb94ca3 commit 0547cf7
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions [gameplay]/playercolors/playercolors.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local lowerBound, upperBound = unpack(get("color_range"))

function randomizePlayerColor(player)
local freeroamRunning = false

local function randomizePlayerColor(player)
player = player or source
local r, g, b = math.random(lowerBound, upperBound), math.random(lowerBound, upperBound), math.random(lowerBound, upperBound)
setPlayerNametagColor(player, r, g, b)
Expand All @@ -16,13 +18,29 @@ local function setAllPlayerColors()
end
end
end
addEventHandler("onResourceStart", resourceRoot, setAllPlayerColors)
addEventHandler("onGamemodeMapStart", root, setAllPlayerColors) -- mapmanager resets player colors to white when the map ends
addEventHandler("onResourceStop", resourceRoot, setAllPlayerColors)
-- mapmanager resets player colors to white when the map ends
addEventHandler("onGamemodeMapStart", root, setAllPlayerColors)

local function handleResourceStartStop(res)
if res == resource then
local freeroamResource = getResourceFromName("freeroam")
if freeroamResource then
freeroamRunning = getResourceState(freeroamResource) == "running"
end
setAllPlayerColors()
elseif getResourceName(res) == "freeroam" then
freeroamRunning = eventName == "onResourceStart"
end
end
addEventHandler("onResourceStart", root, handleResourceStartStop)
addEventHandler("onResourceStop", root, handleResourceStartStop)

addEventHandler('onPlayerChat', root,
function(msg, type)
if type == 0 then
if freeroamRunning then
return -- Let freeroam handle chat
end
cancelEvent()
local r, g, b = getPlayerColor(source)
local name = getPlayerName(source)
Expand Down

0 comments on commit 0547cf7

Please sign in to comment.