Jump to content

Sending color arguments to function


Hoffmann

Recommended Posts

Hello, community!
Can you help me? What is the best method to send RGB/HEX colors in function?
 

function meChat(thePlayer, cmd, ...)
    ProxDetector(30, thePlayer, ..., color1, color2, color3, color4, color5)
end
addCommandHandler("do", meChat)

function ProxDetector(radius, thePlayer, ..., color1)
    local text = table.concat({...}," ")
    local oldposx, oldposy, oldposz = getElementPosition(thePlayer)
	for k, v in pairs(getElementsByType("player")) do
	    local posx, posy, posz = getElementPosition(v)
		if getElementDimension(v) == getElementDimension(thePlayer) then
			local getRadius = getDistanceBetweenPoints3D(oldposx, oldposy, oldposz, posx, posy, posz)
			if (getRadius < radius / 16) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, color1, false)
			elseif (getRadius < radius / 8) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, color2, false)
			elseif(getRadius < radius / 4) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, color3, false)
			elseif(getRadius < radius / 2) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, color4, false)
			elseif(getRadius < radius) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, color5, false)
			end
		end
	end
	return true
end

I tried something like COLOR_PURPLE = 0xC2A2DAAA and then convert in to RGB in outputchatBox function but it says that ")" expected near "," in function string.

Link to comment
7 hours ago, Yazir said:

Means you didn't close a bracket (

I'm looking at the code and I don't really know what you want to do.

I want to use colors to send them in my function ProxDetector. But there are trg colors, idk how to define and use them. Maybe table and unpack?

Link to comment
function meChat(thePlayer, cmd,arg1,arg2,arg3,arg4,arg5)
    ProxDetector(30, thePlayer, arg1, arg2, arg3, arg4, arg5)
end
addCommandHandler("do", meChat)

function ProxDetector(radius, thePlayer,arg1,arg2,arg3,arg4,arg5)
    local text = table.concat({...}," ")
    local oldposx, oldposy, oldposz = getElementPosition(thePlayer)
	for k, v in pairs(getElementsByType("player")) do
	    local posx, posy, posz = getElementPosition(v)
		if getElementDimension(v) == getElementDimension(thePlayer) then
			local getRadius = getDistanceBetweenPoints3D(oldposx, oldposy, oldposz, posx, posy, posz)
			if (getRadius < radius / 16) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg1, false)
			elseif (getRadius < radius / 8) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg2, false)
			elseif(getRadius < radius / 4) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg3, false)
			elseif(getRadius < radius / 2) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg4, false)
			elseif(getRadius < radius) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg5, false)
			end
		end
	end
	return true
end

If rest of your code is right try this.

I see it still won't work.

https://wiki.multitheftauto.com/wiki/RGBToHex

Add this behind every outputchatbox with arg.

Edited by Yazir
Link to comment
On 04.02.2017 at 16:27, Yazir said:

function meChat(thePlayer, cmd,arg1,arg2,arg3,arg4,arg5)
    ProxDetector(30, thePlayer, arg1, arg2, arg3, arg4, arg5)
end
addCommandHandler("do", meChat)

function ProxDetector(radius, thePlayer,arg1,arg2,arg3,arg4,arg5)
    local text = table.concat({...}," ")
    local oldposx, oldposy, oldposz = getElementPosition(thePlayer)
	for k, v in pairs(getElementsByType("player")) do
	    local posx, posy, posz = getElementPosition(v)
		if getElementDimension(v) == getElementDimension(thePlayer) then
			local getRadius = getDistanceBetweenPoints3D(oldposx, oldposy, oldposz, posx, posy, posz)
			if (getRadius < radius / 16) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg1, false)
			elseif (getRadius < radius / 8) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg2, false)
			elseif(getRadius < radius / 4) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg3, false)
			elseif(getRadius < radius / 2) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg4, false)
			elseif(getRadius < radius) then
			    outputChatBox(getPlayerName(thePlayer).." "..text, v, arg5, false)
			end
		end
	end
	return true
end

If rest of your code is right try this.

I see it still won't work.

https://wiki.multitheftauto.com/wiki/RGBToHex

Add this behind every outputchatbox with arg.

Thank you but I have already solved my problem and made solution!

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