Modules/IRCEcho/ircDisconnect

From Multi Theft Auto: Wiki
Revision as of 14:41, 13 January 2008 by VRocker (talk | contribs) (New page: __NOTOC__ Disconnects an open IRC Connection ==Syntax== <syntaxhighlight lang="lua"> function ircDisconnect ( IRCConnection irc ) </syntaxhighlight> ===Required arguments=== * '''irc:''' The IRCConnection you wish...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Disconnects an open IRC Connection

Syntax

function ircDisconnect ( IRCConnection irc )

Required arguments

  • irc: The IRCConnection you wish to disconnect

Example

Example 1: This example connects to a server on ResourceStart and disconnects on ResourceStop

szChans = {} --Init an array of channels for storage

function onResourceStart( res )
	if res == getThisResource() then -- If the starting resource is this one
		ircInit( ) -- Initialize the module for this resource
		pIRC = ircOpen( "irc.gtanet.com", 6667, "WikiTest", "#channel" ) -- Open the IRC connection
		if pIRC then -- If opening connection was successful
			szChans[ pIRC ] = "#channel" -- Add the channel to the table
		end
	end
end

function onResourceStop( res )
	if res == getThisResource () then -- If the stopping resource is this one
		if pIRC then -- If theres an IRC Connection
			ircDisconnect( pIRC ) -- Disconnect the connection
			szChans[ pIRC ] = nil -- Removes the channel from the array
			pIRC = nil -- Set the connection to nil
		end
	end
end

addEventHandler( "onResourceStart", getRootElement(), onResourceStart )
addEventHandler( "onResourceStop", getRootElement(), onResourceStop )

See also