Guest Posted July 23, 2018 Share Posted July 23, 2018 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
Addlibs Posted July 23, 2018 Share Posted July 23, 2018 (edited) 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 July 23, 2018 by MrTasty Link to comment
JeViCo Posted July 23, 2018 Share Posted July 23, 2018 (edited) 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 July 23, 2018 by Juuve Link to comment
Guest Posted July 23, 2018 Share Posted July 23, 2018 (edited) Hey i'm begginer @Juuve i wan't to ask you: function name was " info " why here addEventHandler("onClientRender", getRootElement(), drawText) you wrote " drawText " instead of " info " ? Edited July 23, 2018 by Guest Link to comment
Addlibs Posted July 23, 2018 Share Posted July 23, 2018 Perhaps because that's what you wrote in the beginning, on lines 12 and 14 in your original post. Link to comment
Guest Posted July 23, 2018 Share Posted July 23, 2018 tbh i copied it from another script but idk Link to comment
xMKHx Posted July 23, 2018 Share Posted July 23, 2018 (edited) 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 July 23, 2018 by xMKHx 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