Jump to content

Hex to RGB


Best-Killer

Recommended Posts

i tried and  i tested it and i got just r (255)

code 

function myTeamColor(Player,Command) -- adding the function
      local ab = "#ffffff"
          if ab  then
             outputChatBox("your team color is : "..hex2rgb(ab))
          end
   end
addCommandHandler("myteamcolor",myTeamColor) -- adding command handler
function hex2rgb(hex) 
  hex = hex:gsub("#","") 
  return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) 
end 

0 errors

Link to comment

Try this and it should work ;

function myTeamColor ( Player ) 
      local ab = '#ffffff'
          if ab  then
    local r,g,b = hex2rgb ( ab )
             outputChatBox( 'your team color is : '..r..','..g..','..b..'',Player,g,b )
          end
   end
addCommandHandler ( 'myteamcolor',myTeamColor ) 

function hex2rgb(hex) 
  hex = hex:gsub("#","") 
  return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) 
end 

 

Link to comment

Thx Dude , i'm learning and you gave me a idea to make what i want really thx ^^ <3 

what is problem here guys ?

rRoot = getResourceRootElement(getThisResource())
addEventHandler( 'onResourceStart', rRoot,
	function( )
		executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Marker_System ( name VARCHAR(20) ,posX VARCHAR(40), posY VARCHAR(40), posZ VARCHAR(40), r VARCHAR(40), g, VARCHAR(40) b VARCHAR(40), models VARCHAR(40), rotation VARCHAR(40), ID VARCHAR(40))' )
		creatMarkerSystem()		
	end
)

function creatMarkerSystem()
	local GetAllMarker = executeSQLQuery( "SELECT * FROM Marker_System" )
	if ( type ( GetAllMarker ) == "table" and #GetAllMarker > 0 ) then
		for i = 1, #GetAllMarker do
		    local n = {GetAllMarker[i]["posX"], GetAllMarker[i]["posY"], GetAllMarker[i]["posZ"], GetAllMarker[i]["r"], GetAllMarker[i]["g"],GetAllMarker[i]["b"]}
            for ii = 1, #n do n[ ii ] = tonumber( n[ ii ] ) end			
			local marker = createMarker( n[1], n[2],   n[3], 'cylinder', 1.25, n[4], n[5], n[6], 255 )
			setElementData( marker, 'id', i )
            setElementData( marker, 'giveCarSystem', true )			
  		end
	end
end


addEvent( 'CreateMarker', true )
addEventHandler( 'CreateMarker', root, 
function( X, Y, Z, r, g, b)
if getPedOccupiedVehicle( source ) then Z = Z else Z = Z - 1 end
local AllMarker = executeSQLQuery( "SELECT * FROM Marker_System" )
id = #AllMarker + 1
executeSQLQuery( "INSERT INTO Marker_System ( posX, posY, posZ, r, g, b, ID ) VALUES ( "..X..", "..Y..", "..Z..", "..r..", "..g..", "..b..", "..id..")" )
local marker = createMarker( X, Y, Z, 'cylinder', 1.25, r, g, b, 255 )
setElementData( marker, 'giveCarSystem', true )
setElementData( marker, 'id', id )
outputChatBox( "Marker Was Created", source, 255, 255, 0 )
end
)

errors : line:27/29: Database query failed: no such table: Marker_system

Link to comment

Because you are creating the table with the wrong way and you are using my script so it should be like this :

 

executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Marker_System ( posX, posY, posZ, r, g, b, ID)' )

 

Full server code from my resource :

 

--][
-- ** Vehicle Marker System
-- ** Ver (1)
-- ** Scripted By Mr.Pres[T]ege
-- ** 26 Fep
--][

rRoot = getResourceRootElement(getThisResource())
Cars = {}
antiFloodMarker = {}
local cmd = 'RemoveMarker' --- Delete Marker Command 
local allowedGroup = 'Admin'
local vehicleIDS = { -- Vehicle ID  
602, 545 , 517, 401, 410, 518, 527, 436, 589, 580, 419, 439, 549, 526, 491,474, 445, 467, 604, 426, 507, 547, 585,405, 587, 409
}

addEventHandler( 'onResourceStart', rRoot,
	function( )
		executeSQLQuery( 'CREATE TABLE IF NOT EXISTS Marker_System ( posX, posY, posZ, r, g, b, ID)' )
        for i, player in ipairs( getElementsByType( 'player' ) ) do
			if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then
				setElementData( player, 'OpenMakerPanel', true)
			else
				setElementData( player, 'OpenMakerPanel', nil)
			end
		end	
		creatMarkerSystem()		
	end
)

function creatMarkerSystem()
	local GetAllMarker = executeSQLQuery( "SELECT * FROM Marker_System" )
	if ( type ( GetAllMarker ) == "table" and #GetAllMarker > 0 ) then
		for i = 1, #GetAllMarker do
		    local n = {GetAllMarker[i]["posX"], GetAllMarker[i]["posY"], GetAllMarker[i]["posZ"], GetAllMarker[i]["r"], GetAllMarker[i]["g"],GetAllMarker[i]["b"]}
            for ii = 1, #n do n[ ii ] = tonumber( n[ ii ] ) end			
			local marker = createMarker( n[1], n[2],   n[3], 'cylinder', 1.25, n[4], n[5], n[6], 255 )
			setElementData( marker, 'id', i )
            setElementData( marker, 'giveCarSystem', true )			
  		end
	end
end

addEventHandler( 'onMarkerHit', rRoot, function( player )
    if getElementType( player ) == 'player' and not getPedOccupiedVehicle( player ) then
      if getElementData( source, 'giveCarSystem' ) then
	  		randomCarID = tonumber(vehicleIDS[math.random(#vehicleIDS)])
			if Cars[player] and getElementType(Cars[player]) == "vehicle" then destroyElement(Cars[player]) end
				x,y,z = getElementPosition(player)
					Cars[player] = createVehicle(randomCarID, x+1,y,z)
				if Cars[player] then
					warpPedIntoVehicle(player,Cars[player])
			end	
      end
    end
end)

addEventHandler( 'onPlayerJoin', root, function()
	setElementData( source, 'OpenMakerPanel', nil)
end )

addEventHandler( 'onPlayerLogin', root, function( _, acc )
	if isObjectInACLGroup( 'user.'..getAccountName( acc ), aclGetGroup( allowedGroup ) ) then
		setElementData( source, 'OpenMakerPanel', true)
	else
		setElementData( source, 'OpenMakerPanel', nil)	
    end
end
)

addEventHandler( 'onPlayerLogout', root, function( _, acc )
    triggerClientEvent( source, 'LogOutSetVisible', root)
    setElementData( source, 'OpenMakerPanel', nil) 
end )

addEvent( 'CreateMarker', true )
addEventHandler( 'CreateMarker', root, 
function( X, Y, Z, r, g, b)
if antiFloodMarker[source] then return outputChatBox( "Please wait 6 seconds before creating new marker", source, 255, 255, 0 ) end
antiFloodMarker[source] = true
if getPedOccupiedVehicle( source ) then Z = Z else Z = Z - 1 end
local AllMarker = executeSQLQuery( "SELECT * FROM Marker_System" )
id = #AllMarker + 1
executeSQLQuery( "INSERT INTO Marker_System ( posX, posY, posZ, r, g, b, ID ) VALUES ( "..X..", "..Y..", "..Z..", "..r..", "..g..", "..b..", "..id..")" )
local marker = createMarker( X, Y, Z, 'cylinder', 1.25, r, g, b, 255 )
setElementData( marker, 'giveCarSystem', true )
setElementData( marker, 'id', id )
outputChatBox( "Marker Was Created", source, 255, 255, 0 )
setTimer(removeFlood, 6000, 1, source)
end
)

function removeFlood(plr)
if antiFloodMarker[plr] then antiFloodMarker[plr] = false end
end

addEventHandler("onPlayerQuit",root,function()
if Cars[source] then destroyElement(Cars[source]) Cars[source] = nil end
end)

addEventHandler("onVehicleExplode",root,function()
setTimer(destroyElement,2000,1,source)
end)

addCommandHandler( cmd, function(player, Command)
    if isObjectInACLGroup( 'user.'..getAccountName( getPlayerAccount( player ) ), aclGetGroup( allowedGroup ) ) then
		local mrker = getMarkerByHit( player )
		if mrker then
			local id = tonumber ( getElementData( mrker, 'id') or 0 )
			if id == 0 then return end
			if executeSQLQuery("DELETE FROM `Marker_System` WHERE `ID`=?", id) then
				destroyElement( mrker )
				outputChatBox( "Marker Was Deleted", player, 255, 255, 0 )
			else
				outputChatBox( "error", player, 255, 255, 0 )		
			end
		end
	else
		outputChatBox( "Access denied", player, 255, 255, 0 )	
	end	
end
)

function getMarkerByHit( plr )
  for i, v in ipairs( getElementsByType( 'marker', rRoot ) ) do
    if isElementWithinMarker(plr, v) then
      return v
    end
  end
  return false,outputChatBox( "Error: Please enter the marker", plr, 255, 255, 0 )
end

 

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...