Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
-- Table Library --[[ Documentation This is my extention of the Lua tables library. I hope you find them all useful. The following examples will all be interrelated and will create a very basic stats table. Here are descriptions of each function and how to use them: table.save(t, filename) -- t: <table> The table you'll be saving into a textfile. -- filename: <string> The name of the file you'll be saving this table to. Example: function OnScriptUnload() table.save(players, "players.data") end Notes: -- By default, table.save saves your table in "Documents\\My Games\\Halo\\data". table.load(filename) -- filename: <string> The name of the file you want to load a table from. Example: function OnScriptLoad(process, game, persistent) players = table.load("players.data") end function OnPlayerJoin(player) makestats(player) end function makestats(player) local hash = gethash(player) stats[hash] = table.load(hash .. ".data") players[hash] = players[hash] or {} players[hash].joins = players[hash].joins or 0 + 1 stats[hash].name = stats[hash].name or getname(player) stats[hash].kills = stats[hash].kills or {} stats[hash].kills.humanweap = stats[hash].kills.humanweap or 0 stats[hash].kills.covenantweap = stats[hash].kills.covenantweap or 0 end Notes: -- If the file doesn't exist or is empty, table.load returns an empty table {}. table.len(t) -- t: <table> Table you want to find the length of. Returns: Total length of table. Example: local total_players = table.len(players) Notes: -- The reason this function is necessary is because #t returns the length of a table as defined by ipairs. This means Lua begins at index 1 of table t and adds 1 to the index until the value at the current index is nil. If you have a table that is indexed by hashes, #players will return 0 because players[1] = nil. table.len returns the length of a table including non-numeric keys. table.find(t, v, [case]) -- t: <table> Table you're searching. -- v: <any type> Value you're searching for in the table. -- case: <boolean> Defines if the value should be case-sensitive (default = true). Returns: The key at which the specified value is found. Example: swears = {"balls", "boners", "poppycock"} -- My name is Nuggets and I (dis)approve of these words. function OnServerChat(player, type, message) if player then local words = tokenizestring(message) for k,v in ipairs(words) do if table.find(swears, v, false) then -- ensures that "boners" as well as "BONERS" and "bOnErS" are all blocked (poor boners). privatesay(player, "YOU HAVE SAID EVIL THINGS.") return false end end end end table.max(t) -- t: <table> Table you want to find the maximum value of. Returns: Key which contains the maximum value as well as the maximum value. Example: function OnPlayerKill(killer, victim, mode) local khash = gethash(killer) if humanweapon(killer) then -- making up a function here to get to the point stats[khash].kills.humanweap = stats[khash].kills.humanweap + 1 end local weaptype, kills = table.max(stats[khash].kills) privatesay(killer, "You have the most kills with " .. weaptype .. ": " .. kills) end >> You have the most kills with humanweap: 12 table.maxv(t) -- See table.max; the only difference is this function only returns the maximum value, not the key at which it was found. table.maxes(t) -- t: <table> Table of which you would like to find the keys which have the maximum values. Returns: A table of keys which all contain the maximum value of the table and the maximum value. Example: local t = {1, 2, 2, 5, 7, 2, 7, 3, 7, 7} local keys, max = table.maxes(t) for k,v in ipairs(keys) do hprintf(v) end hprintf("Max: " .. max) >> 5 >> 7 >> 9 >> 10 >> Max: 7 table.sum(t) -- t: <table> Table of which you would like to find the sum of all numerical values. Returns: Sum of all numerical values of the table specified and all tables nested within the table specified. Example: function OnPlayerKill(killer, victim, mode) local khash = gethash(killer) local total_kills = table.sum(stats[khash].kills) privatesay(killer, "You have " .. total_kills .. " total kills.") end If you have any questions about how any of these functions work, PM me (Nuggets) at phasor.proboards.com. --]] function table.save(t, filename) local dir = getprofilepath() local file = io.open(dir .. "\\data\\" .. filename, "w") local spaces = 0 local function tab() local str = "" for i = 1,spaces do str = str .. " " end return str end local function format(t) spaces = spaces + 4 local str = "{ " for k,v in opairs(t) do -- Key datatypes if type(k) == "string" then k = string.format("%q", k) elseif k == math.inf then k = "1 / 0" end -- Value datatypes if type(v) == "string" then v = string.format("%q", v) elseif v == math.inf then v = "1 / 0" end if type(v) == "table" then if table.len(v) > 0 then str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. format(v) .. "," else str = str .. "\n" .. tab() .. "[" .. k .. "] = {}," end else str = str .. "\n" .. tab() .. "[" .. k .. "] = " .. tostring(v) .. "," end end spaces = spaces - 4 return string.sub(str, 1, string.len(str) - 1) .. "\n" .. tab() .. "}" end file:write("return " .. format(t)) file:close() end function table.load(filename) local dir = getprofilepath() local file = loadfile(dir .. "\\data\\" .. filename) if file then return file() or {} end return {} end function table.len(t) local count = 0 for k,v in pairs(t) do count = count + 1 end return count end function table.find(t, v, case) if case == nil then case = true end for k,val in pairs(t) do if case then if v == val then return k end else if string.lower(v) == string.lower(val) then return k end end end end function table.max(t) local max = -math.inf local key for k,v in pairs(t) do if tonumber(v) then if tonumber(v) > max then key = k max = tonumber(v) end end end return key,max end function table.maxv(t) local max = -math.inf local key for k,v in pairs(t) do if tonumber(v) then if tonumber(v) > max then key = k max = tonumber(v) end end end return max end function table.maxes(t) local keys = {} local max = -math.inf for k,v in pairs(t) do if tonumber(v) then if tonumber(v) > max then max = tonumber(v) end end end for k,v in pairs(t) do if tonumber(v) == max then table.insert(keys, k) end end return keys,max end function table.sum(t, key) local sum = 0 for k,v in pairs(t) do if type(v) == "table" then sum = sum + table.sum(v, key) elseif tonumber(v) then if key then if key == k then sum = sum + tonumber(v) end else sum = sum + tonumber(v) end end end return sum end
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Exchange Exploit
JavaScript | 8 sec ago | 0.32 KB
✅ MAKE $500 IN 15 MIN
JavaScript | 14 sec ago | 0.32 KB
ChangeNOW Exploit
JavaScript | 19 sec ago | 0.32 KB
✅ MAKE $5OO IN 15 MIN L
JavaScript | 3 min ago | 0.31 KB
⭐ Free ETH Method ⭐ R
JavaScript | 3 min ago | 0.31 KB
✅ MAKE $9OO INSTANTLY E
JavaScript | 4 min ago | 0.31 KB
✅ Exploit 5OO$ in 15 Minutes Q
JavaScript | 4 min ago | 0.31 KB
⭐ Instant Profit Method ⭐ A
JavaScript | 4 min ago | 0.31 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!