Jump to content

(QUESTION) HOW TO DO THIS??


y453bh

Recommended Posts

function hex2rgb (hex)
    local hex = hex:gsub("#","")
    if hex:len() == 3 then
      return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255
    else
      return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255
    end
end

-- exemple usage: (NOT TESTED the command) but the function works fine

addEventHandler("onPlayerCommand",root,
    function(command, player)
	if (command == "convert") then
	    outputConsole("Result: " .. hex2rgb("#ffffff"),player)
	end
end)

:)

Edited by Santi
Link to comment
7 hours ago, Santi said:

function hex2rgb (hex)
    local hex = hex:gsub("#","")
    if hex:len() == 3 then
      return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255
    else
      return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255
    end
end

-- exemple usage: (NOT TESTED the command) but the function works fine

addEventHandler("onPlayerCommand",root,
    function(command, player)
	if (command == "convert") then
	    outputConsole("Result: " .. hex2rgb("#ffffff"),player)
	end
end)

:)

Not working

Link to comment
On 26/03/2020 at 19:36, Santi said:

function hex2rgb (hex)
    local hex = hex:gsub("#","")
    if hex:len() == 3 then
      return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255
    else
      return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255
    end
end

-- exemple usage: (NOT TESTED the command) but the function works fine

addEventHandler("onPlayerCommand",root,
    function(command, player)
	if (command == "convert") then
	    outputConsole("Result: " .. hex2rgb("#ffffff"),player)
	end
end)

:)

Use addCommandHandler to create a command, also the source of onPlayerCommand is the player. so you don't need to add player as a parameter.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...