a lua file which holds a set of hubsoft independent lua functions.
I called it ExtendedApi.lua
copy it into your scripts folder and start your script with:
dofile("ExtendedApi.lua")
And all functions are available
Note that there's 2 tables reserved by it, namely tTimers and tExtUserInfo so don't declare variables with that name yourself ;)
The file's attached, here's the API
Quote
This is the Interface for ExtendedApi.lua by CrazyGuy
Current version = 1.0
Global functions:
LuaCompat() -- Call this function to make non LUA 5.1.x functions compatible ( as much as possible )
Serialize(tTable, sTable, sTab) -- Returns a string in Table format for storage to file
GetExtApiVer() -- Returns this script's version number as string
Loading and Saving related functions:
LoadStringFile(fFile) -- Loads a textfile
SaveStringFile(sString, fFile, sMode) -- Saves a textfile. (sMode can be the LUA modes for append, overwrite, update etc)
LoadTableFile(tTable,fFile) -- Loads a table from a file
SaveTableFile(tTable, sTable, fFile) -- Serializes and saves a table to a file
Multi Timers related functions: Timers are stored in a table called tTimers
AddTimer(iInterval, sTimerName) -- Adds a timer and returns its ID or nil on error
RemoveTimer(iTimerID) -- Removes a timer and returns 1 on success or nil on error
GetTimerByName(sTimerName) -- Returns a timers ID or nil on error
GetTimerByID(iTimerID) -- Returns a timers Name or nil on error
GetTimerIntByID(iTimerID) -- Returns a timers Interval or nil on error
GetTimerValueByID(iTimerID) -- Returns a timers current Value or nil on error
GetTimerStateByID(iTimerID) -- Returns a timers current State (1/0) or nil on error
StartTimerByID(iTimerID) -- Starts a timer by ID, returns 1 on success, 0 on is already started or nil on error
StopTimerByID(iTimerID) -- Stops a timer by ID, returns 1 on success, 0 on is already stopped or nil on error
SetTimerIntByID(iTimerID, iInterval) -- Changes a timers Interval, returns 1 on success, nil on error
SetTimerName(iTimerID, sTimerName) -- Changes a timers Name, returns 1 on success, nil on error
ResetTimer(iTimerID) -- Resets a timers Value back to 0, returns 1on success, nil on error
Storing additional Userinfo functions: Userinfo is stored in a table called tExtUserInfo
AddExtUserInfo(sName,bBool,iInt,sString) -- Stores a set of 3 variables for the specefied user
RemoveExtUserInfo(sName) -- Removes a user from the table
GetExtUserBool(sName) -- Returns a boolean stored for sName or nil on error
GetExtUserInt(sName) -- Returns an integer value stored for sName or nil on error
GetExtUserText(sName) -- Returns a string value stored for sName or nil on error
SetExtUserBool(sName, bBool) -- Sets the boolean value for sName to bBool, returns 1 on success, 0 on already set, nil on error
SetExtUserInt(sName, iInt) -- Sets the integer value for sName to iInt, returns 1 on success, 0 on already set, nil on error
SetExtUserText(sName, sText) -- Sets the string value for sName to sText, returns 1 on success, nil on error
Lemmy know if something's not working correctly or any suggestions about what to add :)
Looks good mate, and even if its not used directly for scripts, it can be implemented or used to quickly debugg a script.
Thnx m8 ;D
When can we expect you back in the hub ???
As soon as i remember my pass ;D, i forgot it.
Very nice script!
Thnx guys :)
Quote
There are many examples of the following in this script
if variable ~= nil then
better as...
if variable then
no?
No effectual difference, just a little cleaner code
Hmm I think I did have problems with the slight difference between "if x ~= nil then" and "if x then"
However, that was a different script, a different LUA version and a less experienced me :P
So let's give that another try then 8)
Updated to version 1.1 on November 27th 2006
-Added table.maxn and collectgarbage to LuaCompat (Thnx Mutor)
-Cleaned up a few "~= nil" as suggested by Mutor
It depends on what pattern matching you use, something you have to check :
if user=="" then..
As im not using empty string checks, but pure nil checks, it should work out fine here then