utilities - DoktorSAS/IW6X-S1X-Scripting-Guide GitHub Wiki
Utilities
The utilities are functions already made by some users to simplify the development. In this area you can find some useful functions to perform some simple operations in a correct way.
Array Utilities
Array Utilities are arrays of information that you can call directly without having to remember certain information.
Colors
local colors = { red = "^1",
green = "^2",
yellow = "^3",
blue = "^4",
cyan = "^5",
ping = "^6",
white = "^7",
team_color = "^8",
grey = "^9",
black = "^0",
rainbow = "^0"
}
Teams
local teams = { spectator = "spectator",
axis = "axis",
allies = "allies"
}
Sessionstate
local sessionstate = { spectator = "spectator",
dead = "dead",
playing = "playing"
}
String Utilities
Since a lot of work is done with lua, there are some functions that can simplify a scripter's work. These functions can also be found online. But to simplify your search I'll put some of them here.
Split
function split(pString, pPattern)
Table = {} -- NOTE: use {n = 0} in Lua-5.0
fpat = "(.-)" .. pPattern
last_end = 1
s, e, cap = pString:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(Table,cap)
end
last_end = e+1
s, e, cap = pString:find(fpat, last_end)
end
if last_end <= #pString then
cap = pString:sub(last_end)
table.insert(Table, cap)
end
return Table
end
String/Double to int
function toint(n)
local s = tostring(n)
local i, j = s:find('%.')
if i then
return tonumber(s:sub(1, i-1))
else
return n
end
end