Error Messages / Hints

I am looking to add a Hint in a little script for Inscript, but I know GM:AddNotify is sandbox/derivatives only. Is there any way to display an error in that manner WITHOUT it being sandbox/derivatives? Thanks.

[editline]11:41PM[/editline]

Also, just tried this.


	if( string.len( self:GetString("name") ) ) < 32 then
		RunConsoleCommand("setinfo", "name", self:GetString("name") or "" )
	else
	-- GM:AddNotify("You have reached the character limit for your name (32)!", NOTIFY_ERROR, 5);
	chat.AddText(Color(255,0,0), "[INSCRIPT ERROR] You have reached the character limit for your name (32 characters)!")
	chat.PlaySound()
	end

It’s spamming the chat noise with no chat msg.

Well, you didnt set the alpha of the text. You could also just use ply:ChatPrint(“lol error”)

Thanks. I followed the GMod Wiki :(.

Anyway, I’m getting this error.


attempt to index global 'ply' (a nil value)


Post your full code.

Basically, it means that you didn’t have it in the function’s arguments.

function THIS_IS_A_TEST(<arguments go here>)


function Snitch(killer, victim) -- args
	print( .. victim .. "was killed by ".. killer .. "!")
end

hook.Add("PlayerDeath", "SnitchForMe", Snitch)


An example.

[lua]PLUGIN.Name = “In-game Name Override”
PLUGIN.DefaultOn = false
PLUGIN.Description = “Overrides your in-game Steam name.”

function PLUGIN:LoadParameters()
self:AddParameter(“name_label”, { Type = “label”, Text = “Override name :” } )
self:AddParameter(“name”, { Type = “textentry”, Defaults = “<none>” } )
end

function PLUGIN:Load()
end

– This function is automatically hooked on Mount, and unhooked on Unmount.
function PLUGIN.HOOK:Think()
if( string.len( self:GetString(“name”) ) ) < 32 then
RunConsoleCommand(“setinfo”, “name”, self:GetString(“name”) or “” )
else
ply:ChatPrint("[INSCRIPT ERROR] You have reached the character limit for your name (32 characters)!")
chat.PlaySound()
end
end

function PLUGIN:Unload()
end[/lua]

I think I just need to have it stop checking, or just erase the text box if it’s too large.

Im pretty sure it shouldnt be function PLUGIN.HOOK:Think(), just PLUGIN:Think().

No, ply is not defined in the think function.

Am I missing something or is this client-side?

… was talking about the “HOOK” part.

It’s a clientside script set.

Just copy the cl_notices.lua file from sandbox and implement it in your gamemode then you can use AddNotify. Thats what I did.

[lua]

NOTIFY_GENERIC = 0
NOTIFY_ERROR = 1
NOTIFY_UNDO = 2
NOTIFY_HINT = 3
NOTIFY_CLEANUP = 4

local NoticeMaterial = {}
NoticeMaterial[ NOTIFY_GENERIC ] = surface.GetTextureID( “vgui/notices/generic” )
NoticeMaterial[ NOTIFY_ERROR ] = surface.GetTextureID( “vgui/notices/error” )
NoticeMaterial[ NOTIFY_UNDO ] = surface.GetTextureID( “vgui/notices/undo” )
NoticeMaterial[ NOTIFY_HINT ] = surface.GetTextureID( “vgui/notices/hint” )
NoticeMaterial[ NOTIFY_CLEANUP ] = surface.GetTextureID( “vgui/notices/cleanup” )

local HUDNote_c = 0
local HUDNote_i = 1
local HUDNotes = {}

function GM:AddNotify( str, type, length )

local tab = {}
tab.text 	= str
tab.recv 	= SysTime()
tab.len 	= length
tab.velx	= -5
tab.vely	= 0
tab.x		= ScrW() + 200
tab.y		= ScrH()
tab.a		= 255
tab.type	= type

table.insert( HUDNotes, tab )

HUDNote_c = HUDNote_c + 1
HUDNote_i = HUDNote_i + 1

end

local function DrawNotice( self, k, v, i )

local H = ScrH() / 1024
local x = v.x - 75 * H
local y = v.y - 300 * H

if ( !v.w ) then

	surface.SetFont( "GModNotify" )
	v.w, v.h = surface.GetTextSize( v.text )

end

local w = v.w
local h = v.h

w = w + 16
h = h + 16

draw.RoundedBox( 4, x - w - h + 8, y - 8, w + h, h, Color( 30, 30, 30, v.a * 0.4 ) )

// Draw Icon

surface.SetDrawColor( 255, 255, 255, v.a )
surface.SetTexture( NoticeMaterial[ v.type ] )
surface.DrawTexturedRect( x - w - h + 16, y - 4, h - 8, h - 8 ) 


draw.SimpleText( v.text, "GModNotify", x+1, y+1, Color(0,0,0,v.a*0.8), TEXT_ALIGN_RIGHT )
draw.SimpleText( v.text, "GModNotify", x-1, y-1, Color(0,0,0,v.a*0.5), TEXT_ALIGN_RIGHT )
draw.SimpleText( v.text, "GModNotify", x+1, y-1, Color(0,0,0,v.a*0.6), TEXT_ALIGN_RIGHT )
draw.SimpleText( v.text, "GModNotify", x-1, y+1, Color(0,0,0,v.a*0.6), TEXT_ALIGN_RIGHT )
draw.SimpleText( v.text, "GModNotify", x, y, Color(255,255,255,v.a), TEXT_ALIGN_RIGHT )

local ideal_y = ScrH() - (HUDNote_c - i) * (h + 4)
local ideal_x = ScrW()

local timeleft = v.len - (SysTime() - v.recv)

// Cartoon style about to go thing
if ( timeleft &lt; 0.8  ) then
	ideal_x = ScrW() - 50
end
 
// Gone!
if ( timeleft &lt; 0.5  ) then

	ideal_x = ScrW() + w * 2

end

local spd = RealFrameTime() * 15

v.y = v.y + v.vely * spd
v.x = v.x + v.velx * spd

local dist = ideal_y - v.y
v.vely = v.vely + dist * spd * 1
if (math.abs(dist) &lt; 2 && math.abs(v.vely) &lt; 0.1) then v.vely = 0 end
local dist = ideal_x - v.x
v.velx = v.velx + dist * spd * 1
if (math.abs(dist) &lt; 2 && math.abs(v.velx) &lt; 0.1) then v.velx = 0 end

// Friction.. kind of FPS independant.
v.velx = v.velx * (0.95 - RealFrameTime() * 8 )
v.vely = v.vely * (0.95 - RealFrameTime() * 8 )

end

function GM:PaintNotes()

if ( !HUDNotes ) then return end
	
local i = 0
for k, v in pairs( HUDNotes ) do

	if ( v != 0 ) then
	
		i = i + 1
		DrawNotice( self, k, v, i)		
	
	end
	
end

for k, v in pairs( HUDNotes ) do

	if ( v != 0 && v.recv + v.len &lt; SysTime() ) then
	
		HUDNotes[ k ] = 0
		HUDNote_c = HUDNote_c - 1
		
		if (HUDNote_c == 0) then HUDNotes = {} end
	
	end

end

end

[/lua]

If this is a client side script, can’t you use LocalPlayer():ChatPrint()?

Thanks, that worked! Now it keeps spamming chat though, so how would I set the text box to empty or text like “Name too Large”, or remove the last few characters? Or just limit the text box length?

Sorry, Lua NOOB here.

Well, it is in the Think hook. Think is getting called every tick, and servers are typical 66 ticks/sec.

The example shown here: **[Gamemode.Think

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.Think)** is actually what you need.

Obviously, but I didn’t think that was the issue.

Its getting called every frame.

Yea I knew I’d messed that up somehow.

You are erroring but not taking action. Thus it will keep on erroring.