|  | 
| 1 |  | -local showColorCodes = true; 		-- Shows player's names colorcoded if set to true, and if set to false it doesn't | 
| 2 |  | -local defaultHexCode = "#4E5768"; 	-- Hex code for what color to output messages in (only used if showColorCodes is true) | 
| 3 |  | - | 
|  | 1 | +local resourceName = getResourceName(getThisResource()) | 
|  | 2 | +local settingPrefix = string.format("*%s.", resourceName) | 
|  | 3 | + | 
|  | 4 | +local showColorCodes = get("showColorCodes") == "true" 	-- Shows player"s names colorcoded if set to true, and if set to false it doesn"t | 
|  | 5 | +local defaultColor = get("defaultColor")				-- Hex code for what color to output messages in (only used if showColorCodes is true) | 
|  | 6 | +local fallbackHexCode = "#4E5768"						-- Fallback hex code for incorrectly input settings values | 
|  | 7 | + | 
|  | 8 | +function reloadSettings(settingName) | 
|  | 9 | +	-- Setting change affects this resource | 
|  | 10 | +	if (string.find(settingName, settingPrefix, 1, true)) then | 
|  | 11 | +		showColorCodes = get("showColorCodes") == "true" | 
|  | 12 | +		defaultColor = get("defaultColor") | 
|  | 13 | +	end | 
|  | 14 | +end | 
|  | 15 | +addEventHandler("onSettingChange", root, reloadSettings) | 
| 4 | 16 | 
 | 
| 5 | 17 | -- This function converts RGB colors to colorcodes like #ffffff | 
| 6 |  | -function RGBToHex(red, green, blue, alpha) | 
| 7 |  | - | 
|  | 18 | +function RGBToHex(red, green, blue) | 
| 8 | 19 | 	-- Make sure RGB values passed to this function are correct | 
| 9 |  | -	if( ( red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255 ) or ( alpha and ( alpha < 0 or alpha > 255 ) ) ) then | 
|  | 20 | +	if (not red or not green or not blue or (red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255)) then | 
| 10 | 21 | 		return nil | 
| 11 | 22 | 	end | 
| 12 | 23 | 
 | 
| 13 |  | -	-- Alpha check | 
| 14 |  | -	if alpha then | 
| 15 |  | -		return string.format("#%.2X%.2X%.2X%.2X", red, green, blue, alpha) | 
| 16 |  | -	else | 
| 17 |  | -		return string.format("#%.2X%.2X%.2X", red, green, blue) | 
| 18 |  | -	end | 
| 19 |  | - | 
|  | 24 | +	return string.format("#%.2X%.2X%.2X", red, green, blue) | 
| 20 | 25 | end | 
| 21 | 26 | 
 | 
| 22 |  | - | 
| 23 |  | -addEventHandler('onClientPlayerJoin', root, | 
| 24 |  | -	function() | 
| 25 |  | - | 
| 26 |  | -		if showColorCodes then | 
| 27 |  | -			outputChatBox(defaultHexCode .. '* ' .. RGBToHex(getPlayerNametagColor(source)) .. getPlayerName(source) .. defaultHexCode .. ' has joined the game', 255, 100, 100, true) | 
| 28 |  | -		else | 
| 29 |  | -			outputChatBox('* ' .. getPlayerName(source) .. ' has joined the game', 255, 100, 100) | 
| 30 |  | -		end | 
| 31 |  | - | 
|  | 27 | +function getDefaultColor() | 
|  | 28 | +	local hexColor = RGBToHex(defaultColor[1], defaultColor[2], defaultColor[3]) | 
|  | 29 | +	if (not hexColor) then | 
|  | 30 | +		return fallbackHexCode | 
| 32 | 31 | 	end | 
| 33 |  | -) | 
| 34 |  | - | 
| 35 | 32 | 
 | 
| 36 |  | -addEventHandler('onClientPlayerChangeNick', root, | 
| 37 |  | -	function(oldNick, newNick) | 
|  | 33 | +	return hexColor | 
|  | 34 | +end | 
| 38 | 35 | 
 | 
| 39 |  | -		if showColorCodes then | 
| 40 |  | -			outputChatBox(defaultHexCode .. '* ' .. RGBToHex(getPlayerNametagColor(source)) .. oldNick .. defaultHexCode .. ' is now known as ' .. RGBToHex(getPlayerNametagColor(source)) .. newNick, 255, 100, 100, true) | 
| 41 |  | -		else | 
| 42 |  | -			outputChatBox('* ' .. oldNick .. ' is now known as ' .. newNick, 255, 100, 100) | 
| 43 |  | -		end | 
|  | 36 | +function getHexFriendlyNick(player, nick) | 
|  | 37 | +	return RGBToHex(getPlayerNametagColor(player))..nick | 
|  | 38 | +end | 
| 44 | 39 | 
 | 
|  | 40 | +function joinMessage() | 
|  | 41 | +	if (showColorCodes) then | 
|  | 42 | +		outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, getPlayerName(source))..getDefaultColor().." has joined the game", root, 255, 100, 100, true) | 
|  | 43 | +	else | 
|  | 44 | +		outputChatBox("* "..getPlayerName(source).." has joined the game", root, 255, 100, 100) | 
| 45 | 45 | 	end | 
| 46 |  | -) | 
| 47 |  | - | 
| 48 |  | - | 
| 49 |  | -addEventHandler('onClientPlayerQuit', root, | 
| 50 |  | -	function(reason) | 
|  | 46 | +end | 
|  | 47 | +addEventHandler("onPlayerJoin", root, joinMessage) | 
| 51 | 48 | 
 | 
| 52 |  | -		if showColorCodes then | 
| 53 |  | -			outputChatBox(defaultHexCode .. '* ' .. RGBToHex(getPlayerNametagColor(source)) .. getPlayerName(source) .. defaultHexCode .. ' has left the game [' .. reason .. ']', 255, 100, 100, true) | 
| 54 |  | -		else | 
| 55 |  | -			outputChatBox('* ' .. getPlayerName(source) .. ' has left the game [' .. reason .. ']', 255, 100, 100) | 
| 56 |  | -		end | 
|  | 49 | +function nickChangeMessage(oldNick, newNick) | 
|  | 50 | +	if (showColorCodes) then | 
|  | 51 | +		outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, oldNick)..getDefaultColor().." is now known as "..getHexFriendlyNick(source, newNick), root, 255, 100, 100, true) | 
|  | 52 | +	else | 
|  | 53 | +		outputChatBox("* "..oldNick.." is now known as "..newNick, root, 255, 100, 100) | 
|  | 54 | +	end | 
|  | 55 | +end | 
|  | 56 | +addEventHandler("onPlayerChangeNick", root, nickChangeMessage) | 
| 57 | 57 | 
 | 
|  | 58 | +function leftMessage(reason) | 
|  | 59 | +	if (showColorCodes) then | 
|  | 60 | +		outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, getPlayerName(source))..getDefaultColor().." has left the game ["..reason.."]", root, 255, 100, 100, true) | 
|  | 61 | +	else | 
|  | 62 | +		outputChatBox("* "..getPlayerName(source).." has left the game ["..reason.."]", root, 255, 100, 100) | 
| 58 | 63 | 	end | 
| 59 |  | -) | 
|  | 64 | +end | 
|  | 65 | +addEventHandler("onPlayerQuit", root, leftMessage) | 
0 commit comments