Help with draw.WordBox

I’m trying to make a radar gun swep for cops on my server and I’m using this code:

ply:SendLua("draw.WordBox(8, … ScrW() /2, ScrH()/2, "…

But, there seems to be no error nor a wordbox on the screen.
Any method to fix this?

I need the wordbox to show up for a few seconds then disappear.

What you need to understand is that draw.WordBox is a draw function, and thus needs to be called in a draw hook.

What you should do is create a clientside script and add a hook like this:
[lua]hook.Add(“HUDPaint”, function()
draw.WordBox(…)
end)[/lua]

HUDPaint is the most common hook for drawing HUD stuff.

I want to call it from the server…how should I go about doing that?

You don’t.

I didn’t mean literally call it…I meant like…On a server side script, I want to send a message to a player that shows up in the center of their screen for a few seconds. That is my aim.

You use the net library to send a message to the client, who then draws the info inside their HUDPaint hook. I wrote up a sample for you, hopefully it makes sense. It’s not centered but I’ll leave that to you.

If you put this inside lua/autorun, call it anything (I tested by calling it testNetMsg.lua), then in your serverside code you will be able to call the TellUserToShow() function.



if SERVER then

	--tell client they want this file
	AddCSLuaFile()
	
	--setup our message name
	util.AddNetworkString("user_showthis")
	
	function TellUserToShow(ply,strMsg) --our function for sending a message
	
		if not IsValid(ply) then return end
		
		--Start a 'net message' with our message name
		net.Start("user_showthis")
			--write our string into the net message
			net.WriteString(strMsg)
		--send the message to the player
		net.Send(ply)
		
	end
	
	function TellAllUsersToShow(strMsg) --our function for sending a message
		
		--Start a 'net message' with our message name
		net.Start("user_showthis")
			--write our string into the net message
			net.WriteString(strMsg)
		--send the message to the player
		net.Broadcast()
		
	end
	
	--a testing concommand, serverside
	concommand.Add("msgme", function(ply,cmd,args)
		if IsValid(ply) then
			TellUserToShow(ply, "This is a message from the server")
		end
	end)
	
elseif CLIENT then

	--we record the time the message was received, so we can fade out
	local msgText = nil
	local showMsgUntil = 0
	local showMessageFor = 5
	
	--our simple hud
	local function myhud()
		if msgText and showMsgUntil>CurTime() then
			local timeRemaining = showMsgUntil-CurTime()
			local alpha = timeRemaining/showMessageFor * 255
			draw.WordBox( 8, 50, ScrH()/2, msgText, "default", Color(0,0,0,alpha), Color(255,255,255,alpha) )
		end
	end
	hook.Add("HUDPaint", "My HUD Hook", myhud)
	
	--our function for receiving the net message
	local function receiveOurMsg()
		local textFromServer = net.ReadString()
		showMsgUntil = CurTime()+showMessageFor
		msgText = textFromServer
	end
	
	--actually listen for the message, and call our function when we receive it
	net.Receive("user_showthis", receiveOurMsg)
	
end


Thanks alot whiterabbit! I’ll make it work!