Tokio Posted March 17, 2019 Share Posted March 17, 2019 (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 March 17, 2019 by Nerve Link to comment
Dimos7 Posted March 18, 2019 Share Posted March 18, 2019 You want to be all same location? Link to comment
Tokio Posted March 18, 2019 Author Share Posted March 18, 2019 34 minutes ago, Dimos7 said: You want to be all same location? Yes, next to my message. Link to comment
Dimos7 Posted March 19, 2019 Share Posted March 19, 2019 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 comment
Tokio Posted March 19, 2019 Author Share Posted March 19, 2019 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 comment
XaskeL Posted March 23, 2019 Share Posted March 23, 2019 Does another player have a different monitor resolution than yours? Link to comment
Tokio Posted March 23, 2019 Author Share Posted March 23, 2019 48 minutes ago, XaskeL said: Does another player have a different monitor resolution than yours? Yes. Link to comment
ShayF2 Posted March 23, 2019 Share Posted March 23, 2019 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 comment
XaskeL Posted March 23, 2019 Share Posted March 23, 2019 48 minutes ago, Nerve said: Да. Then try what @ShayF suggested Link to comment
Tokio Posted March 23, 2019 Author Share Posted March 23, 2019 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.. Link to comment
Tokio Posted March 24, 2019 Author Share Posted March 24, 2019 Anyone can help in this? Link to comment
XaskeL Posted March 24, 2019 Share Posted March 24, 2019 7 hours ago, Tokio said: Кто-нибудь может помочь в этом? give me full resource in pm Link to comment
Tokio Posted March 25, 2019 Author Share Posted March 25, 2019 12 hours ago, XaskeL said: give me full resource in pm I sent Link to comment
ShayF2 Posted March 31, 2019 Share Posted March 31, 2019 You have to use relative positioning on everything you draw. Link to comment
Tokio Posted April 1, 2019 Author Share Posted April 1, 2019 22 hours ago, ShayF said: You have to use relative positioning on everything you draw. I tried, but same problem Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now