Jump to content

MapInfo text overwriting itself


koragg

Recommended Posts

Hello, I'm facing a small but really annoying problem with the mapinfo script I'm using. Problem's that when I press the key (F5) to show mapinfo while text is still being drawn at the moment (fades away slowly) it just starts from the beginning again. This makes a really bad effect and also gets annoying if you just want to check toptimes as the mapinfo starts over and over again and again. I tried messing with timers and some booleans but no deal. Help? :)

function prerenderfix()
	fade = 0
	width, height = guiGetScreenSize()
	setTimer(function()
	check = 0
	end,50,1)
	if isEventHandlerAdded("onClientRender",getRootElement(),renderText) == false then
		addEventHandler("onClientRender",getRootElement(),renderText)
	end
end
bindKey("F5","down",prerenderfix)
-------------------------------------------------------------------------------------------------------------------------
function renderText()
	if fade <= 253 and check == 0 then
		fade = fade + 2
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 0 then
		check = 1
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 1 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 1 then
		check = 2
	elseif fade <= 253 and check == 2 then
		fade = fade + 2
		
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 2 then
		check = 3
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 3 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 3 then
		check = 4
	elseif fade <= 253 and check == 4 then
		fade = fade + 2
		
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 4 then
		check = 5
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 5 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 5 then
		check = 6
	end
end

 

Edited by koragg
Link to comment

@myonlake that was just part of the code responsible for drawing. Here's full:

local name, author, mode
-------------------------------------------------------------------------------------------------------------------------
function handleMapInfo(mapInfo)
	name            = mapInfo.name or "Unknown"
	author          = mapInfo.author or "Unknown"
	mode            = mapInfo.modename ~= "Race" and mapInfo.modename or "Destruction derby" 
end
addEvent("onClientMapStarting",true)
addEventHandler("onClientMapStarting",getRootElement(),handleMapInfo)
-------------------------------------------------------------------------------------------------------------------------
function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY)
  bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default"
  if alignX then
    if alignX == "center" then
      ax = ax + (bx - ax - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font))/2
    elseif alignX == "right" then
      ax = bx - dxGetTextWidth(str:gsub("#%x%x%x%x%x%x",""), scale, font)
    end
  end
  if alignY then
    if alignY == "center" then
      ay = ay + (by - ay - dxGetFontHeight(scale, font))/2
    elseif alignY == "bottom" then
      ay = by - dxGetFontHeight(scale, font)
    end
  end
  local alpha = string.format("%08X", color):sub(1,2)
  local pat = "(.-)#(%x%x%x%x%x%x)"
  local s, e, cap, col = str:find(pat, 1)
  local last = 1
  while s do
    if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end
    if s ~= 1 or cap ~= "" then
      local w = dxGetTextWidth(cap, scale, font)
      dxDrawText(cap, ax, ay, ax + w, by, color, scale, font)
      ax = ax + w
      color = tocolor(getColorFromString("#"..col..alpha))
    end
    last = e + 1
    s, e, cap, col = str:find(pat, last)
  end
  if last <= #str then
    cap = str:sub(last)
    dxDrawText(cap, ax, ay, ax + dxGetTextWidth(cap, scale, font), by, color, scale, font)
  end
end
-------------------------------------------------------------------------------------------------------------------------
addEvent("onClientMapStarting",true)
function prerender()
	fade = 0
	width, height = guiGetScreenSize()
	setTimer(function()
	check = 0
	end,3650,1)
	if isEventHandlerAdded("onClientRender",getRootElement(),renderText) == false then 
	addEventHandler("onClientRender",getRootElement(),renderText)
	end
end
addEventHandler("onClientMapStarting",getRootElement(), prerender)
-------------------------------------------------------------------------------------------------------------------------
function prerenderfix()
	fade = 0
	width, height = guiGetScreenSize()
	setTimer(function()
	check = 0
	end,50,1)
	if isEventHandlerAdded("onClientRender",getRootElement(),renderText) == false then 
	addEventHandler("onClientRender",getRootElement(),renderText)
	end
end
-------------------------------------------------------------------------------------------------------------------------
function renderText()
	if fade <= 253 and check == 0 then
		fade = fade + 2
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 0 then
		check = 1
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 1 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Map: "..name, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFMap: #FEFE22"..name, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 1 then
		check = 2
	elseif fade <= 253 and check == 2 then
		fade = fade + 2
		
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 2 then
		check = 3
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 3 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Author(s): "..author, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFAuthor(s): #FEFE22"..author, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 3 then
		check = 4
	elseif fade <= 253 and check == 4 then
		fade = fade + 2
		
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif check == 4 then
		check = 5
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,255), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,255), (width/1660)*3, "sans", "center", "bottom")
		fade = 254
	elseif fade <= 254 and check == 5 and fade ~= 0 then
		fade = fade - 2
		dxDrawColorText("Gamemode: "..mode, 1, 1, width+1, height+1, tocolor(0,0,0,fade), (width/1660)*3, "sans", "center", "bottom")
		dxDrawColorText("#00FFFFGamemode: #FEFE22"..mode, 0, 0, width, height, tocolor(255,255,255,fade), (width/1660)*3, "sans", "center", "bottom")
	elseif fade == 0 and check == 5 then
		check = 6
	end
end
bindKey("F5","down",prerenderfix,renderText)
-------------------------------------------------------------------------------------------------------------------------
function isEventHandlerAdded(sEventName, pElementAttachedTo, func)
 if type(sEventName) == 'string' and
  isElement(pElementAttachedTo) and
  type(func) == 'function'
 then
  local aAttachedFunctions = getEventHandlers(sEventName, pElementAttachedTo)
  if type(aAttachedFunctions) == 'table' and #aAttachedFunctions > 0 then
   for i, v in ipairs(aAttachedFunctions) do
    if v == func then
     return true
    end
   end
  end
 end
 return false
end

Well, when I press F5 the text fades in, stays a few seconds on screen and then fades out. And if I press F5 while the text is showing, it starts from the beginning again. I wanna make it so that if there's any text (map name, author or gamemode) on screen it wouldn't do anything when I press F5.

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