GM:OnLuaError

From Garry's Mod
Jump to: navigation, search
 GM:OnLuaError( )

Contents

Description

Called when a Lua error occurs, only works in the Menu realm.

WARNING Modify menu state Lua code at your own risk!

Arguments

string error

The error that occurred.

Arguments

number realm

Where the Lua error took place

Arguments

string name

Title of the addon that is creating the Lua errors

Arguments

number id

Steam Workshop ID of the addon creating Lua errors, if it is an addon.

Examples

Example

Code from garrysmod/lua/menu/errors.lua

hook.Add( "OnLuaError", "MenuErrorHandler", function( str, realm, addontitle, addonid )

	local text = "Something is creating script errors"

	--
	-- This error is caused by a specific addon
	--
	if ( isstring( addonid ) ) then

		--
		-- Down Vote
		--
		-- steamworks.Vote( addonid, false )

		--
		-- Disable Naughty Addon
		--
		--timer.Simple( 5, function()
		--	MsgN( "Disabling addon '", addontitle, "' due to lua errors" )
		--	steamworks.SetShouldMountAddon( addonid, false )
		--	steamworks.ApplyAddons()
		--end )

		text = "The addon \"" .. addontitle .. "\" is creating errors, check the console for details"

	end

	if  ( addonid == nil ) then addonid = 0 end

	if ( Errors[ addonid ] ) then

		Errors[ addonid ].times	= Errors[ addonid ].times + 1
		Errors[ addonid ].last	= SysTime()

		return
	end

	local error =
	{
		first	= SysTime(),
		last	= SysTime(),
		times	= 1,
		title	= addontitle,
		x		= 32,
		text	= text
	}

	Errors[ addonid ] = error

end )


Personal tools
Navigation