⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@inaawaf
Copy link
Contributor

@inaawaf inaawaf commented Jan 12, 2026

This keeps the original behavior but improves it slightly by avoiding very dark colors and reducing the chance of duplicate nametag colors between players

This keeps the original behavior but improves it slightly by avoiding very dark colors and reducing the chance of duplicate nametag colors between players
@omar-o22
Copy link
Contributor

Why avoid dark nametag colors?

Copy link
Member

@Lpsd Lpsd left a comment

Choose a reason for hiding this comment

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

Not too sure about the approach here - also is there a specific issue you're trying to address by restricting darker colors?

r = math.random(lowerBound, upperBound)
g = math.random(lowerBound, upperBound)
b = math.random(lowerBound, upperBound)
until (r + g + b) > 200
Copy link
Member

Choose a reason for hiding this comment

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

For the most unlucky player in the history of MTA, this could return a value under 200 even if they waited for an infinite amount of time

The lower bound would need increasing to ensure the three values always have a sum larger than 200, or you would need to lower the check itself (i.e (r + g + b) > 149 given current lower bounds).

r, g, b = generateColor()
key = colorToKey(r, g, b)
if not usedColors[key] then
break
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem like the right approach.

Technically there are 206³ (8,741,816) possible keys (RGB color combinations) given 206 possible configurations (50-255 range) per value. However we're only attempting to generate a color 10 times before giving up if they've already been used.

Whilst technically not an issue given the huge amount of possible combinations/keys, it's still a logically flawed approach given the previously mentioned factor of luck; and the simple fact this isn't optimal/efficient.

A better approach would be to generate a limited size pool of random colors on resource start (equal to the max player count) and then select a random one to assign to a player. Once assigned, pop from the active pool, place into an "inactive" list/array (indexed by player) and return back to the pool once the player disconnects (so the color can be used again).

This ensures players are all assigned unique colors, without needing to iterate at all to find an unused value (since we generate one at random first try). You may also wish to implement additional logic to ensure the active pool colors aren't too similar when initially pre-allocating the pool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants