Skip to content
Merged
Changes from all commits
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
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