Tokio

[HELP] How to fix this bug?

Recommended Posts

Posted (edited)

When i write a message to chatbox the picture appears in the right place, but when a another player output something in chatbox, the picture jumps up more than my message.. How to fix this bug?!

Client:

emotes = {}

function showEmotes(originaltext,emote,emoteID)	
	local totaltextwidth = getImageOffsets(originaltext)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local originalmultiplier = math.floor(totaltextwidth/chatwidth)

	local text,_ = string.gsub(originaltext,tostring(emoteID..".*"),"")
	local width = getImageOffsets(text)
	
	local multiplier = math.floor(width/chatwidth)
	local width = width-multiplier*chatwidth
	table.insert(emotes,{emote,width,lines-(originalmultiplier-multiplier),false})
	
	local _,index1 = string.gsub(originaltext,emoteID,emoteID)
	if index1>1 then
		local text,index = string.gsub(originaltext,emoteID,"-00",1)
		showEmotes(text,emote,emoteID)
	end
end
addEvent("triggerChat",true)
addEventHandler("triggerChat",root,showEmotes)

function getImageOffsets(text)
	lines = getChatboxLayout()["chat_lines"]
	local chatboxscale = getChatboxLayout()["text_scale"]
	local fontint = getChatboxLayout()["chat_font"]
	scaleX = getChatboxLayout()["chat_scale"][1]
	scaleY = getChatboxLayout()["chat_scale"][2]
		if fontint == 0 then
			font = "default"
		end
		if fontint == 1 then
			font = "clear"
		end
		if fontint == 2 then
			font = "default-bold"
		end
		if fontint == 3 then
			font = "arial"
		end
	fontheight = dxGetFontHeight(chatboxscale,font)
	local width = (dxGetTextWidth(text,chatboxscale,font)+chatxoffset)*scaleX
	return width
end

local screenWidth, screenHeight = guiGetScreenSize ( )
chatxoffset = screenWidth * 0.0145
chatyoffset = screenHeight * 0.0145
function createText ( )
	for index,item in ipairs(emotes) do
		local line = item[3]
		local width = item[2]
		local height = (chatyoffset + (line-1)*fontheight)*scaleY
		if (item[3]<1) then 
			table.remove(emotes,index)
		else
		dxDrawImage(width,height,20,20,"a.png",0,0,0,tocolor(255,255,255,255),true)
		end
	end
end

function emotesOnOff()
	if emotesVisible then
		removeEventHandler ( "onClientRender", root, createText )
		emotesVisible = false
	else
		addEventHandler ( "onClientRender", root, createText )
		emotesVisible = true
	end
end

function HandleTheRendering ( )
	addEventHandler ( "onClientRender", root, createText )
	emotesVisible = true
	addCommandHandler ("emotes", emotesOnOff )
end
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )

function onClientChatMessageHandler(text)
	local width = getImageOffsets(text)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local multiplier = math.floor(width/chatwidth)+1
	
	for index,item in ipairs(emotes) do
		if item[4] then
			item[3] = item[3]-1*multiplier
		end
		item[4] = true
	end
end
addEventHandler("onClientChatMessage", getRootElement(), onClientChatMessageHandler)

Server:

emotes = {
	{"a","-23"}
}
	
function playerChat(text, messageType)	
	if (messageType ~= 0) then return end

     local accName = getAccountName ( getPlayerAccount ( source ) )
if isObjectInACLGroup ("user."..accName, aclGetGroup ( "tesztr" ) ) then

	local originalText = removeColorCodes(getPlayerName(source))

	for index,item in ipairs(emotes) do
		text,item[3] = string.gsub(originalText,item[1],item[2])
	end
	
	for index,item in ipairs(emotes) do
			triggerClientEvent("triggerChat",source,"[HU]"..originalText,item[1],item[2])
	end
	
	for index,item in ipairs(emotes) do
		originalText,item[3] = string.gsub(originalText,item[1],"      ")
	end
	
	end
end
addEventHandler("onPlayerChat", root, playerChat)

function removeColorCodes(str)
  return (string.gsub(str, "#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]", ""))
end

 

Edited by Nerve

Share this post


Link to post
34 minutes ago, Dimos7 said:

You want to be all same location? 

Yes, next to my message.

Share this post


Link to post
emotes = {}

function showEmotes(originaltext,emote,emoteID)	
	local totaltextwidth = getImageOffsets(originaltext)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local originalmultiplier = math.floor(totaltextwidth/chatwidth)

	local text,_ = string.gsub(originaltext,tostring(emoteID..".*"),"")
	local width = getImageOffsets(text)
		local multiplier = math.floor(width/chatwidth)
	local width = width-multiplier*chatwidth
	table.insert(emotes,{emote,width,lines-(originalmultiplier-multiplier),false})
	
	local _,index1 = string.gsub(originaltext,emoteID,emoteID)
	if index1>1 then
		local text,index = string.gsub(originaltext,emoteID,"-00",1)
		showEmotes(text,emote,emoteID)
	end
end
addEvent("triggerChat",true)
addEventHandler("triggerChat",root,showEmotes)

function getImageOffsets(text)
	lines = getChatboxLayout()["chat_lines"]
	local chatboxscale = getChatboxLayout()["text_scale"]
	local fontint = getChatboxLayout()["chat_font"]
	scaleX = getChatboxLayout()["chat_scale"][1]
	scaleY = getChatboxLayout()["chat_scale"][2]
		if fontint == 0 then
			font = "default"
		end
		if fontint == 1 then
			font = "clear"
		end
		if fontint == 2 then
			font = "default-bold"
		end
		if fontint == 3 then
			font = "arial"
		end
	fontheight = dxGetFontHeight(chatboxscale,font)
	local width = (dxGetTextWidth(text,chatboxscale,font)+chatxoffset)*scaleX
	return width
end

local screenWidth, screenHeight = guiGetScreenSize ( )
chatxoffset = screenWidth * 0.0145
chatyoffset = screenHeight * 0.0145
function createText ( )
	for index,item in ipairs(emotes) do
		local line = item[3]
		local width = item[2]
		local height = (chatyoffset + (line-1)*fontheight)*scaleY
		if (item[3]<1) then 
			table.remove(emotes,index)
		else
		dxDrawImage(20,20, width, height, "a.png",0,0,0,tocolor(255,255,255,255),true)
		end
	end
end

function emotesOnOff()
	if emotesVisible then
		removeEventHandler ( "onClientRender", root, createText )
		emotesVisible = false
	else
		addEventHandler ( "onClientRender", root, createText )
		emotesVisible = true
	end
end

function HandleTheRendering ( )
	addEventHandler ( "onClientRender", root, createText )
	emotesVisible = true
	addCommandHandler ("emotes", emotesOnOff )
end
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )

function onClientChatMessageHandler(text)
	local width = getImageOffsets(text)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local multiplier = math.floor(width/chatwidth)+1
	
	for index,item in ipairs(emotes) do
		if item[4] then
			item[3] = item[3]-1*multiplier
		end
		item[4] = true
	end
end
addEventHandler("onClientChatMessage", getRootElement(), onClientChatMessageHandler)

Maybe its this

Share this post


Link to post
5 hours ago, Dimos7 said:

emotes = {}

function showEmotes(originaltext,emote,emoteID)	
	local totaltextwidth = getImageOffsets(originaltext)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local originalmultiplier = math.floor(totaltextwidth/chatwidth)

	local text,_ = string.gsub(originaltext,tostring(emoteID..".*"),"")
	local width = getImageOffsets(text)
		local multiplier = math.floor(width/chatwidth)
	local width = width-multiplier*chatwidth
	table.insert(emotes,{emote,width,lines-(originalmultiplier-multiplier),false})
	
	local _,index1 = string.gsub(originaltext,emoteID,emoteID)
	if index1>1 then
		local text,index = string.gsub(originaltext,emoteID,"-00",1)
		showEmotes(text,emote,emoteID)
	end
end
addEvent("triggerChat",true)
addEventHandler("triggerChat",root,showEmotes)

function getImageOffsets(text)
	lines = getChatboxLayout()["chat_lines"]
	local chatboxscale = getChatboxLayout()["text_scale"]
	local fontint = getChatboxLayout()["chat_font"]
	scaleX = getChatboxLayout()["chat_scale"][1]
	scaleY = getChatboxLayout()["chat_scale"][2]
		if fontint == 0 then
			font = "default"
		end
		if fontint == 1 then
			font = "clear"
		end
		if fontint == 2 then
			font = "default-bold"
		end
		if fontint == 3 then
			font = "arial"
		end
	fontheight = dxGetFontHeight(chatboxscale,font)
	local width = (dxGetTextWidth(text,chatboxscale,font)+chatxoffset)*scaleX
	return width
end

local screenWidth, screenHeight = guiGetScreenSize ( )
chatxoffset = screenWidth * 0.0145
chatyoffset = screenHeight * 0.0145
function createText ( )
	for index,item in ipairs(emotes) do
		local line = item[3]
		local width = item[2]
		local height = (chatyoffset + (line-1)*fontheight)*scaleY
		if (item[3]<1) then 
			table.remove(emotes,index)
		else
		dxDrawImage(20,20, width, height, "a.png",0,0,0,tocolor(255,255,255,255),true)
		end
	end
end

function emotesOnOff()
	if emotesVisible then
		removeEventHandler ( "onClientRender", root, createText )
		emotesVisible = false
	else
		addEventHandler ( "onClientRender", root, createText )
		emotesVisible = true
	end
end

function HandleTheRendering ( )
	addEventHandler ( "onClientRender", root, createText )
	emotesVisible = true
	addCommandHandler ("emotes", emotesOnOff )
end
addEventHandler ( "onClientResourceStart", resourceRoot, HandleTheRendering )

function onClientChatMessageHandler(text)
	local width = getImageOffsets(text)
	local chatwidth = getChatboxLayout()["chat_width"]*317*scaleX
	local multiplier = math.floor(width/chatwidth)+1
	
	for index,item in ipairs(emotes) do
		if item[4] then
			item[3] = item[3]-1*multiplier
		end
		item[4] = true
	end
end
addEventHandler("onClientChatMessage", getRootElement(), onClientChatMessageHandler)

Maybe its this

 

Same problem

 

Share this post


Link to post

Does another player have a different monitor resolution than yours?

Share this post


Link to post
48 minutes ago, XaskeL said:

Does another player have a different monitor resolution than yours?

Yes.

Share this post


Link to post

Use absolute positioning (your resolution whole numbers) then calculate the relative position with this

local devx, devy = 1366, 768 -- your resolution
local clientx, clienty = guiGetScreenSize() -- everyone's resolution

function absoluteToRelativeDX(x, y, w, h)
	return x/devx*clientx, y/devy*clienty, w/devx*clientx, h/devy*clienty
end

Hopefully this helps you.

Share this post


Link to post
48 minutes ago, Nerve said:

Да.

Then try what @ShayF suggested

Share this post


Link to post
25 minutes ago, ShayF said:

Use absolute positioning (your resolution whole numbers) then calculate the relative position with this


local devx, devy = 1366, 768 -- your resolution
local clientx, clienty = guiGetScreenSize() -- everyone's resolution

function absoluteToRelativeDX(x, y, w, h)
	return x/devx*clientx, y/devy*clienty, w/devx*clientx, h/devy*clienty
end

Hopefully this helps you.

I tried that, but the wrench image also jump 2-3 messages up.. :S 

Share this post


Link to post
7 hours ago, Tokio said:

Кто-нибудь может помочь в этом?

give me full resource in pm

Share this post


Link to post
12 hours ago, XaskeL said:

give me full resource in pm

I sent

Share this post


Link to post

You have to use relative positioning on everything you draw.

Share this post


Link to post
22 hours ago, ShayF said:

You have to use relative positioning on everything you draw.

I tried, but same problem

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.