Jump to content

Help


Guest

Recommended Posts

what is wrong with this?

function info ( message )
	removeEventHandler ( "onClientRender", getRootElement(  ), dx )
	function dx ()
local screenW, screenH = guiGetScreenSize ()
local localPlayerName = getPlayerName(getLocalPlayer())
        dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
        dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false)
	end
	addEventHandler("onClientRender", getRootElement(  ), dx )
end
	if command == "info" then
		addEventHandler("onClientRender", getRootElement(), drawText) 
	elseif command == "stopinfo" then
		removeEventHandler("onClientRender", getRootElement(), drawText)
end
addCommandHandler("info", info) 
addCommandHandler("stopinfo", info)

 

Link to comment

If you formatted your indentation correctly, you would quickly realise what the problem is:

function info ( message )
  removeEventHandler ( "onClientRender", getRootElement(  ), dx )
  function dx ()
    local screenW, screenH = guiGetScreenSize ()
    local localPlayerName = getPlayerName(getLocalPlayer())
    dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
    dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false)
  end
  addEventHandler("onClientRender", getRootElement(  ), dx )
end
if command == "info" then
  addEventHandler("onClientRender", getRootElement(), drawText) 
elseif command == "stopinfo" then
  removeEventHandler("onClientRender", getRootElement(), drawText)
end
addCommandHandler("info", info) 
addCommandHandler("stopinfo", info)

You've ended the function 'info' on line 10 and then added if command statements outside the function.

 

What you probably wanted was this

function dx ()
  local screenW, screenH = guiGetScreenSize ()
  local localPlayerName = getPlayerName(getLocalPlayer())
  dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
  dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false)
end
addEventHandler("onClientRender", getRootElement(  ), dx ) -- start off with info showing

function info ( command )
  if command == "info" then
    addEventHandler("onClientRender", getRootElement(), dx)
    -- note that this will cause debugscript errors saying that the function is already
    -- handled if you type /info more than once in sequence without a /stopinfo in between.
    -- If you want to prevent that, use a variable to determine whether you've already 
    -- added the handler, or use getEventHandlers()
  elseif command == "stopinfo" then
  removeEventHandler("onClientRender", getRootElement(), dx)
  end
end
addCommandHandler("info", info) 
addCommandHandler("stopinfo", info)

 

Edited by MrTasty
Link to comment

Try to separate functions next time. Here:

function info ( command,msg )
	if command == "info" then
		message = msg
		addEventHandler("onClientRender", getRootElement(), drawText) 
	elseif command == "stopinfo" then
		removeEventHandler("onClientRender", getRootElement(), drawText)
		message = nil
	end
end
addCommandHandler("info", info) 
addCommandHandler("stopinfo", info)

function drawText()
	local screenW, screenH = guiGetScreenSize ()
	local localPlayerName = getPlayerName(getLocalPlayer())
	dxDrawText(""..message.." Hosted by: "..localPlayerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
	dxDrawText(""..message.." Hosted by: "..localPlayerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false)
end

 

Edited by Juuve
Link to comment

try this

local playerName = ""
local message = ""

function dx ()
local screenW, screenH = guiGetScreenSize ()
dxDrawText(""..message.." Hosted by: "..playerName.."", (screenW * 0.0000) + 1, (screenH * 0.0000) + 1, (screenW * 0.4539) + 1, (screenH * 0.0260) + 1, tocolor(0, 0, 0, 255), 1.00, "default", "left", "top", false, false, false, false, false)
dxDrawText(""..message.." Hosted by: "..playerName.."", screenW * 0.0000, screenH * 0.0000, screenW * 0.4539, screenH * 0.0260, tocolor(255, 255, 255, 255), 1.00, "default", "left", "top", false, false, false, false, false)
end

	function info (message_)
	removeEventHandler ( "onClientRender", getRootElement(  ), dx )
	addEventHandler("onClientRender", getRootElement(  ), dx )
	message = message_
	playerName = getPlayerName(getLocalPlayer())
	end
	
	function stopinfo ()
	removeEventHandler ( "onClientRender", getRootElement(  ), dx )
	end
	
addCommandHandler("info", info) 
addCommandHandler("stopinfo", stopinfo)

 

Edited by xMKHx
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...