Jump to content

[HELP] How to fix this bug?


Tokio

Recommended Posts

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

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

 
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.

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 

Link to post

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