Hex namespace - common hub functions

The Hex namespace contains functions that will allow you to obtain information about the hub. And other tasks like sending data to all users and so forth.

Hex.Broadcast(sData)

Sends sData to all clients that is connected to the hub.
This function does not return a value.
Your are prohibited from sending "$ConnectToMe" and "$RevConnectTome"

Parameters:

Hex.Broadcast("<LuaScript> Hello World!|")

Hex.OpchatMessage(sData)

Posts a message to OpChat.
This function does not return a value.

Parameters:

Hex.OpchatMessage("Hi there operators!")

Hex.UserCount()

This function returns the number of connected users.

local iUsercount = Hex.UserCount()

Hex.GetTopic()

This function returns the current hub topic.

local sTopic = Hex.GetTopic()

Hex.SetTopic(sTopic)

This function sets the hub topic.
This function does not return a value.

Parameters:

Hex.SetTopic("This hub is powered by Hex Script")

Hex.GetMOTD()

This function returns the current MOTD (message of the day).

local sMotd = Hex.GetMOTD()

Hex.SetMOTD(sMotd)

Sets the MOTD (message of the day).
This function does not return a value.

Parameters:

Hex.SetMOTD("Welcome to my hub")

Hex.Uptime()

This function returns the hubs uptime in seconds.

local iUptime = Hex.Uptime()

Hex._GetVersion()

This function returns a string with the version of hexhub.

local sVersion = Hex._GetVersion()

Hex.GetScriptsFolder()

This function returns the path to the scripts directory.

local sFolder = Hex.GetScriptsFolder()

Hex.Bot()

This function returns a new object of type Bot
For more information read the Bot class section.

mybot = Hex.Bot()

Hex.HelpString(iSection, sLanguage)

This function returns a new object of type HelpString (shown in !help).
The HelpString class is initialized with two parameters. For more information read the HelpString class section.

myhelpstring = Hex.HelpString(0, "EN")

Hex.User(iUserId)

This function returns a new object of type User.

To iterate through all users connected to the hub use a value of -1 when initializing the object (Hex.User(-1)).
The object returned will be set to the first user found. User:GetUserID will return -1 if no users were found

In Hex Script 1.2.0.1-unstable and greater you can also use a value of -2 to iterate master users (users that has master status over the hex script plugin).

For more information read the User class section.

local usr = Hex.User(iUserId)

Hex.Right(iUserId)

This function returns a new object of type Right.

For more information read the Right class section.

local usrrights = Hex.Right(iUserId)

Hex.UserCommand()

This function returns a new object of type UserCommand.
For more information read the UserCommand class section.

usercommand = Hex.UserCommand()

Hex.UserCommandEx()

This function returns a new object of type UserCommandEx.
For more information read the UserCommandEx class section.

Remarks:
This function is only availabe in Hex Script versions >= 1.2.0.0

usercommandex = Hex.UserCommandEx()

Hex.Trigger()

This function returns a new object of type Trigger.
For more information read the Trigger class section.

mytrigger = Hex.Trigger()

Hex.Profile(iProfileId)

This function returns a new object of type Profile.

To iterate through all account profiles use a value of -1 when initializing the object (Hex.Profile(-1)).
The object returned will be set to the first profile found.
For more information read the Profile class section.

local profile = Hex.Profile(User:GetProfileID())

Hex.Timer()

This function returns a new object of type Timer.
For more information read the Timer class section.

mytimer = Hex.Timer()

Hex.GetUserID(sNickname)

This function returns the identifier of a user. If the use was not found it returns -1.
For more information read the Hex.User(iUserId) section.

Parameters:

local iUserId = Hex.GetUserID("nickname")
if iUserId == -1 then
	-- not found
end

Hex.SetAboutString(sAbout)

This function sets the copyright text shown in !about trigger

Parameters:

Hex.SetAboutText("Surname Lastname, 2007-2008")

Hex.Execute(sFile, sParameters, sCallback)

This function starts a asynchronous execute operation.
When a asynchronous operation has successfully been initiated there is no way to cancel it

Remarks:
When a script is stopped for what ever reason, all asynchronous operations will be canceled and complete with an error code regardless of their state.
For the executer this means that the program executed will be terminated immediately.
There is no limit on the number of async operations allowed other than hardware such as memory.

Parameters:

Return values:

Callback:
-- iExitCode = the exit code of the program, or -1 on error executing
-- if the callback returns true the output dumpfile (console output) will be deleted.
function ExecuteCompleted(iExitCode, sFilename)
	return true
end

Example:

if Hex.Execute("C:\\file.exe", "", "OnExecuted") ~= 1 then
	print("Could not execute file!")
end

function OnExecuted(iExitCode, sFilename)
	if iExitCode ~= -1 then
		print("File was executed, output is in: "..sFilename)
	else
		print("Execute failed!")
	end
	
	-- read file with output from this program
	
	-- true == delete file
	return true
end

Hex.SendScriptMessage(sReceiver, iMessageCode, sData)

This function schedules a message to be sent to another script, the message is guaranteed to be delivered unless the receiving script is not running or does not exist.
If you need to get notification of delivery the receiver script can send you a message back.
Remarks:
When a script is stopped for what ever reason, all asynchronous operations will be canceled and any messages in the queue will be dropped to the bit can.
There is no limit on the number of async operations allowed other than hardware such as memory.
The receiving script has to have The OnScriptMessage(iMessageCode, sSender, sData) callback

Parameters:

Example sender script:

-- File: ScriptA.lua

mytimer = Hex.Timer()
mytimer:Start(1000, 1000, "MyTimerProc")

function MyTimerProc(iTimerId)
	Hex.SendScriptMessage(Hex.GetScriptsFolder().."ScriptB.lua", 1, "Hello script B")
end

Example receiving script:

-- File: ScriptB.lua
function OnScriptMessage(iMessageCode, sSender, sData)
	print("Message recived from: "..sSender.." with message code: "..iMessageCode.." Message: "..sData)
end

Hex.GetDefaultLanguage()

This function returns a 2-letter language code specifying the default language of the hub.

local slang = Hex.GetDefaultLanguage()

Hex.GetHexScriptVersionInt()

This function returns the version of the current Hex Script implemtation in use. The return value is an integer.

Remarks:
This function is only available in Hex Script versions >= 1.2.0.0

-- For Hex Script 1.2.0.0 iVersion would be set to 1200
local iVersion = Hex.GetHexScriptVersionInt()

Hex.GetHexScriptVersionString()

This function returns the string version of the current Hex Script implemtation in use.

Remarks:
This function is only available in Hex Script versions >= 1.2.0.0

-- For Hex Script 1.2.0.0 sVersion would be set to "Hex Script 1.2.0.0"
local sVersion = Hex.GetHexScriptVersionString()

Hex.Halt()

This function stops a scripts execution.

Remarks:
This function is only available in Hex Script versions >= 1.2.0.0

Hex.GetHubInfo(sWhat)

This function returns information about the hub, the following is avaiable acording to HeXHub's plugins.txt

Remarks:
This function is only available in Hex Script versions >= 1.2.0.1

This function does always return a string, on error a empty ("") string is returned.

Parameters:

Example:

local hubname = Hex.GetHubInfo("hub_name")
local hubTopic = Hex.GetHubInfo("hub_topic")


Hex.SetHubInfo(sWhat, sData)

This function returns information about the hub, the following is avaiable acording to HeXHub's plugins.txt

Remarks:
This function is only available in Hex Script versions >= 1.2.0.1

This function returns -1 on error, otherwise success is indicated.

Parameters:

Example:

if Hex.SetHubInfo("hub_name", "new hub name for this hub here") == -1 then
  -- error
end



Generated on Sat Aug 22 21:09:31 2009 for Hex Script by  doxygen 1.5.8