Jump to content

topbarchat


Recommended Posts

local sX, sY = guiGetScreenSize()
local dxMessages = {}
local dxMessagesY = {-25, -25, -25, -25}
local dxMessagesTick = {}
local isMoving = false

function drawMessages()
	for index, messageData in pairs(dxMessages) do
		dxDrawText(messageData[1], sX / 4 + 1, (sY / 900) * (dxMessagesY[index] * 2) + 1, (sX / 4) * 3 + 1, (sY / 900) * 25 + 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  + 1, (sY / 900) * (dxMessagesY[index] * 2) - 1, (sX / 4) * 3 + 1, (sY / 900) * 25 - 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  - 1, (sY / 900) * (dxMessagesY[index] * 2) + 1, (sX / 4) * 3 - 1, (sY / 900) * 25 + 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  - 1, (sY / 900) * (dxMessagesY[index] * 2) - 1, (sX / 4) * 3 - 1, (sY / 900) * 25 - 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4, (sY / 900) * (dxMessagesY[index] * 2), (sX / 4) * 3, (sY / 900) * 25, tocolor(messageData[2], messageData[3], messageData[4], 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
	end
end
addEventHandler("onClientRender", root, drawMessages)

function new(message, r, g, b)
	message = tostring(message)
	if (dxGetTextWidth(message, (sX / 1440), "default-bold") > 750) then
		new(message:sub(1, 747).."...", 255, 0, 0)
		return
	end
	r, g, b = r or 255, g or 255, b or 255
	if (#dxMessages == 4 or isMoving) then
		Timer(new, 1000, 1, message, r, g, b)
		return
	end
	table.insert(dxMessages, {message, r, g, b})
	dxMessagesTick[#dxMessages] = getTickCount()
	addEventHandler("onClientRender", root, addMessage)
	isMoving = true
	outputConsole(message)
end
addEvent("dx.new", true)
addEventHandler("dx.new", root, new)

function addMessage()
	local index = #dxMessages
	local difference = (sY / 900) * 1.5
	dxMessagesY[index] = dxMessagesY[index] + difference
	if dxMessagesY[index] >= (index - 1) * 25 then
		dxMessagesY[index] = (index - 1) * 25
		if #dxMessages == 4 then
			isMoving = true
			addEventHandler("onClientRender", root, removeMessage)
			removeEventHandler("onClientRender", root, addMessage)
		else
			isMoving = false
			removeEventHandler("onClientRender", root, addMessage)
		end
	end
end

function removeMessage()
	local difference = (sY / 900) * 1.5
	for index = 1, #dxMessages do
		dxMessagesY[index] = dxMessagesY[index] - difference
	end
	if dxMessagesY[1] <= -25 then
		for index = 1, #dxMessages do
			dxMessages[index] = dxMessages[index + 1]
			dxMessagesTick[index] = dxMessagesTick[index + 1]
			dxMessagesY[index] = (index - 1) * 25
		end
		isMoving = false
		removeEventHandler("onClientRender", root, removeMessage)
		for index = 1, #dxMessagesY do
			if not dxMessages[index] then dxMessagesY[index] = -25 end
		end
	end
end

function removeReadMessages()
	for index, message in pairs(dxMessages) do
		local currentTick = getTickCount()
		if currentTick - dxMessagesTick[index] >= 7500 then
			removeMessage()
		end
	end
end
addEventHandler("onClientRender", root, removeReadMessages)

function clear()
	for i = 1, #dxMessages do
		removeMessage()
	end
	dxMessages = {}
	dxMessagesY = {-25, -25, -25, -25}
	dxMessagesTick = {}
	isMoving = false
	if (#getEventHandlers("onClientRender", root, removeMessage) > 0) then
		removeEventHandler("onClientRender", root, removeMessage)
	end
	if (#getEventHandlers("onClientRender", root, addMessage) > 0) then
		removeEventHandler("onClientRender", root, addMessage)
	end
end
addCommandHandler("cleardx", clear, false, false)

Hello, I am trying to add a dxretangle to this topbarchat so that it comes out with messages

But I get an error, does someone help me?

the first attempt went well, but when 2 texts come out together, the rentague is bugge

Link to comment
3 hours ago, IIYAMA said:

Where is your rectangle?

Quote



---local screenW, screenH = guiGetScreenSize()


        dxDrawLine((screenW * 0.2922) - 1, (screenH * 0.0065) - 1, (screenW * 0.2922) - 1, screenH * 0.0339, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(screenW * 0.7125, (screenH * 0.0065) - 1, (screenW * 0.2922) - 1, (screenH * 0.0065) - 1, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine((screenW * 0.2922) - 1, screenH * 0.0339, screenW * 0.7125, screenH * 0.0339, tocolor(0, 0, 0, 255), 1, false)
        dxDrawLine(screenW * 0.7125, screenH * 0.0339, screenW * 0.7125, (screenH * 0.0065) - 1, tocolor(0, 0, 0, 255), 1, false)

        dxDrawRectangle(screenW * 0.2922, screenH * 0.0065, screenW * 0.4203, screenH * 0.0273, tocolor(0, 0, 0, 93), false)--

 

dakHdcs.png?1

Link to comment
  • Moderators

There is no need to do complex stuff. It can be very simple if you spend some time on finding a logic solution.

 

Untested code.

 

local blockSize = (sY / 900) * 10

Define the block size


 

local index = #dxMessages + 1

dxMessages[index] = {message = "hi"}

-- set position data
dxMessages[index].positionY = blockSize * (index - 1)

Define it's position if item is added last

 

local index = 1

-- move all items 1 down
for i=1, #dxMessages do
	dxMessages[i].positionY = dxMessages[i].positionY + blockSize
end

-- insert at the start of the table and push all other items to the next index.
table.insert(dxMessages, index, {message = "hi"})

-- set position data
dxMessages[index].positionY = blockSize

Define it's position(s) if item is added first.

 

 


While rendering:

for index = 1, #dxMessages do
	local messageData = dxMessages[index] 
end

--reverse
for index = #dxMessages, 1, -1 do
	local messageData = dxMessages[index] 
end

Just use a normal loop. So you have full control over it.

 

And now you can rock!

 

 

Box/text from bottom to top. Please edit to your layout.

 

dxDrawRectangle(sX / 4 + 1, sX - blockSize, (sX / 4) * 3 + 1, 0, tocolor(0, 0, 0, 93), false)

Loop

local startX, startY = sX / 4 + 1, sY - messageData.positionY - blockSize

local endX, endY = (sX / 4) * 3 + 1, startY - blockSize * #dxMessages

dxDrawText(messageData.message, startX, startY, endX, endY, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)

 

 

Something like that...

Link to comment
5 hours ago, IIYAMA said:

There is no need to do complex stuff. It can be very simple if you spend some time on finding a logic solution.

 

Untested code.

 


local blockSize = (sY / 900) * 10

Define the block size


 


local index = #dxMessages + 1dxMessages[index] = {message = "hi"}-- set position datadxMessages[index].positionY = blockSize * (index - 1)

Define it's position if item is added last

 


local index = 1-- move all items 1 downfor i=1, #dxMessages do	dxMessages[i].positionY = dxMessages[i].positionY + blockSizeend-- insert at the start of the table and push all other items to the next index.table.insert(dxMessages, index, {message = "hi"})-- set position datadxMessages[index].positionY = blockSize

Define it's position(s) if item is added first.

 

 


While rendering:


for index = 1, #dxMessages do	local messageData = dxMessages[index] end--reversefor index = #dxMessages, 1, -1 do	local messageData = dxMessages[index] end

Just use a normal loop. So you have full control over it.

 

And now you can rock!

 

 

Box/text from bottom to top. Please edit to your layout.

 


dxDrawRectangle(sX / 4 + 1, sX - blockSize, (sX / 4) * 3 + 1, 0, tocolor(0, 0, 0, 93), false)

Loop


local startX, startY = sX / 4 + 1, sY - messageData.positionY - blockSizelocal endX, endY = (sX / 4) * 3 + 1, startY - blockSize * #dxMessagesdxDrawText(messageData.message, startX, startY, endX, endY, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)

 

 

Something like that...

Hello friend, I do not understand your code

I just want to add the dxRetangle that post to my code 

Here I show you the error

local sX, sY = guiGetScreenSize()
local dxMessages = {}
local dxMessagesY = {-25, -25, -25, -25}
local dxMessagesTick = {}
local isMoving = false

function drawMessages()
	for index, messageData in pairs(dxMessages) do
		dxDrawText(messageData[1], sX / 4 + 1, (sY / 900) * (dxMessagesY[index] * 2) + 1, (sX / 4) * 3 + 1, (sY / 900) * 25 + 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  + 1, (sY / 900) * (dxMessagesY[index] * 2) - 1, (sX / 4) * 3 + 1, (sY / 900) * 25 - 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  - 1, (sY / 900) * (dxMessagesY[index] * 2) + 1, (sX / 4) * 3 - 1, (sY / 900) * 25 + 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4  - 1, (sY / 900) * (dxMessagesY[index] * 2) - 1, (sX / 4) * 3 - 1, (sY / 900) * 25 - 1, tocolor(0, 0, 0, 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
		dxDrawText(messageData[1], sX / 4, (sY / 900) * (dxMessagesY[index] * 2), (sX / 4) * 3, (sY / 900) * 25, tocolor(messageData[2], messageData[3], messageData[4], 255), (sX / 1440) * 1.1, "default-bold", "center", "center", false, true, false)
     
          dxDrawRectangle(sX * 0.2922, sY * 0.0065 * (dxMessagesY[index] * 2), sX * 0.4203, sY * 0.0273, tocolor(0, 0, 0, 93), false)--DXRETANGLE ----LOOK

	end
end
addEventHandler("onClientRender", root, drawMessages)

function new(message, r, g, b)
	message = tostring(message)
	if (dxGetTextWidth(message, (sX / 1440), "default-bold") > 750) then
		new(message:sub(1, 747).."...", 255, 0, 0)
		return
	end
	r, g, b = r or 255, g or 255, b or 255
	if (#dxMessages == 4 or isMoving) then
		Timer(new, 1000, 1, message, r, g, b)
		return
	end
	table.insert(dxMessages, {message, r, g, b})
	dxMessagesTick[#dxMessages] = getTickCount()
	addEventHandler("onClientRender", root, addMessage)
	isMoving = true
	outputConsole(message)
end
addEvent("dx.new", true)

cbxlNci.jpg

Link to comment
  • Moderators

I do not understand the decisions you made in your code either, especially if you do not write comments. So I do recommend you to rewrite your code or at least write some comments in it.

 


 

AFAIK you can use the same Y start point of the text for your rectangle. How about you give it a try?

(sY / 900) * (dxMessagesY[index] * 2) + 1

 

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