Please read the COPYRIGHT notice of the bottom of this page. If you contribute to this repository, then you agree to the CONTRIBUTOR LICENSE AGREEMENT also at the bottom of this page.
Contribute to Swamp Cinema here! How to:
- 'Fork' this repo. This creates a copy of it you have edit permissions of.
- Clone your forked repo into garrysmod/addons (so it creates garrysmod/addons/contrib), edit it, and push it back. You'll need the GitHub desktop or commandline client. Look up GitHub tutorials for that.
- For clientside work, check out the devtools which allow you to work on the actual server environment.
- Make a pull request on this repo. Use the 'compare across forks' link to request to merge your changes on your forked repo to this repo. Accepted changes are installed automatically, although new files won't run until after a server reset.
- Minor, single-file changes can just be done in the web browser by clicking the pencil icon.
All models/materials/sounds in this repository will be automatically uploaded to our workshop addons, so don't worry about that.
- Please submit code that is clean and concise. You may want to run it through glualint. Do a good job!
- Make your code compatible with our loading system.
- Try to put cinema-specific code in gamemodes/cinema/ and generic (cross-server) code in lua/. Both folders are loaded using our loading system.
Name stuff like this. A lot of current code doesn't conform, but this is the style:
- local my_var = 1
- local function my_func()
- tab.data_member = 1
- GlobalVariable = 1
- function GlobalFunc()
- function tab:FunctionMember() -- use this naming for callable tables as well
- panel.ChildPanel = ui.Label()
- CONSTANT_VALUE = 1
Never use capital letters when naming local vars/functions
Shorthand for gamemode name
file: lua/autorun/swamp.lua
Int location ID
file: lua/cinema/location/sh_location.lua
String
file: lua/cinema/location/sh_location.lua
Location table
file: lua/cinema/location/sh_location.lua
Theater table
file: lua/cinema/location/sh_location.lua
Bool
file: lua/cinema/location/sh_location.lua
Global function to compute a location ID (avoid this, it doesn't cache)
file: lua/cinema/location/sh_location.lua
Will probably be deprecated
possible options:
pitch
crouchpitch
level
volume
channel
ent: emit from this ent instead of player
shared: emit on client without networking, assuming called in shared function
speech: move player lips (time to move lips, or auto if < 0)
file: lua/cinema/sound/sh_extsound.lua (hidden)
If we are "protected" from this attacker by theater protection. att
doesn't need to be passed, it's only used to let theater owners override protection and prevent killing out of a protected area.
file: lua/cinema/theater/sh_protection.lua (hidden)
Numeric player ranking (all players are zero, staff are 1+)
file: lua/swamp/admin/sh_init.lua (hidden)
Boolean
file: lua/swamp/admin/sh_init.lua (hidden)
Bool (typing a chat message)
file: lua/swamp/chat/sh_swampchat.lua (hidden)
Generates a font quickly. Caches so it can be used in paint hooks.
Example input: draw.DrawText("based", Font.Arial24)
file: lua/swamp/cl_font.lua
surface.GetTextSize with cached result
file: lua/swamp/cl_font.lua
Boolean
file: lua/swamp/clientcheck/sh_afk_detect.lua (hidden)
Boolean, NOT AFK and NOT BOT
file: lua/swamp/clientcheck/sh_afk_detect.lua (hidden)
Prints how long it takes to run a function, averaging over a large number of samples with minimal overhead
file: lua/swamp/dev/sh_bench.lua
For hacking/debugging. FindSinglePlayer but just returns nil if matches multiple.
file: lua/swamp/dev/sh_util.lua
Use this global instead of LocalPlayer()
It will be either nil or a valid entity. Don't write if IsValid(Me)
... , just write if Me
...
file: lua/swamp/extensions/cl_me.lua
Call the function when Me becomes valid
file: lua/swamp/extensions/cl_me.lua
Runs cam.Start3D2D(pos, ang, scale) callback() cam.End3D2D()
but only if the user is in front of the "screen" so they can see it.
file: lua/swamp/extensions/cl_render_extension.lua
Bool if we are currently drawing to the screen.
file: lua/swamp/extensions/cl_render_extension.lua
Sets the color modulation, calls your callback, then sets it back to what it was before.
file: lua/swamp/extensions/cl_render_extension.lua
Call this to make a DFrame dissapear if the user hits escape
file: lua/swamp/extensions/cl_vgui_function.lua
This defines the function vgui(classname, parent (optional), constructor) which creates and returns a panel.
The parent should only be passed when creating a root element (eg. a DFrame) which need a parent.
Child elements should be constructed using vgui() from within the parent's constructor, and their parent will be set automatically.
This is helpful for creating complex guis as the hierarchy of the layout is clearly reflected in the code structure.
Example: (a better example is in the file)\
vgui("Panel", function(p)\
-- p is the panel, set it up here\
vgui("DLabel", function(p)\
-- p is the label here\
end)\
end)\
file: lua/swamp/extensions/cl_vgui_function.lua
Makes an "anim" which smoothly interpolates a value
init = default value
force = acceleration towards target value
callback runs when value changes (return true to stop updating, but this happens automatically when target is reached)
returned table has functions __call() to get the current value, SetTarget(value) to set a target, SetInstant(value) to jump and set velocity to zero
file: lua/swamp/extensions/sh_anim.lua (hidden)
Anim which will set a named property on a subject (entity or panel)
The value is placed at ent.Key and the anim is at ent.KeyAnim
file: lua/swamp/extensions/sh_anim.lua (hidden)
A timer which will only call the callback (with the entity passed as the argument) if the ent is still valid
file: lua/swamp/extensions/sh_ent_timer.lua
A timer which will only call the callback (with the entity passed as the argument) if the ent is still valid
file: lua/swamp/extensions/sh_ent_timer.lua
A global cache of all entities, in subtables divided by classname.
Works on client and server. Much, much faster than ents.FindByClass
or even player.GetAll
Each subtable is ordered and will never be nil even if no entities were created.
To use it try something like this: for i,v in ipairs(Ents.prop_physics) do
...
file: lua/swamp/extensions/sh_ents_cache.lua
NWP="Networked Private"
A table on each player. Values written on server will automatically be replicated to that client. Won't be sent to other players. Read-only on client, read-write on server.
file: lua/swamp/extensions/sh_nwprivate.lua
IsPlayer and not IsBot
file: lua/swamp/extensions/sh_player_extension.lua
Faster than writing IsValid(ply:GetActiveWeapon()) and ply:GetActiveWeapon():GetClass()==class
file: lua/swamp/extensions/sh_player_extension.lua
Find a player whose name contains some text. If it finds exactly one matching player, returns that player. Otherwise, returns the number of found players (0 or >=2). To use this check isnumber() on the return.
file: lua/swamp/extensions/sh_playerbyname.lua
Turns a number of seconds into a string like hh:mm:ss or mm:ss
file: lua/swamp/extensions/sh_string.lua
Pop up the MOTD browser thing with this URL
file: lua/swamp/misc/cl_motd.lua
Show a notification (bottow center screen popup). OK to call on invalid players (does nothing).
file: lua/swamp/misc/sh_notify.lua
Return player's actual Steam name without any filters (eg removing swamp.sv). All default name functions have filters.
file: lua/swamp/misc/sh_player_name_filter.lua
Unlike the built-in function, this (along with player.GetBySteamID64 and player.GetByAccountID) is fast.
file: lua/swamp/misc/sh_playerbysteamid.lua
Get current title string or ""
file: lua/swamp/misc/sh_titles.lua
Rate limiter for net recievers and commands and whatnot. Interval is how many seconds between each action. Burst is how many we can do fast (default 1).
The function returns TRUE if the action should be blocked, FALSE if it should be ALLOWED. So do like if ply:RateLimit("thing", 1, 1) then return end
to rate limit everything after it.
Call it with no arguments to use a default reasonable value for clickable actions or whatever.
file: lua/swamp/misc/sv_swamp_misc.lua (hidden)
Boolean, mostly for players
file: lua/swamp/pony/sh_init.lua
A struct is a table with only string keys, and all string keys are kept on the NetworkString table. It's not as static as a C struct.
file: lua/swamp/sh_api.lua
Register a function which is called on the server and executed on the client. See this file for details.
file: lua/swamp/sh_api.lua
Global cache/generator for tables
Use to localize tables that can't be cleared on file refresh or have to sync in multiple files
local stuff = Table.MyWeaponStuff
file: lua/swamp/sh_init.lua
Returns a table such that when indexing the table, if the value doesn't exist, the constructor will be called with the key to initialize it.
function defaultdict(constructor, args)
assert(args==nil)
return setmetatable(args or {}, {
__index = function(tab, key)
local d = constructor(key)
tab[key] = d
return d
end,
__mode = mode
})
end
-- __mode = weak and "v" or nil
local memofunc = {
function(func)
return setmetatable({}, {
__index = function(tab, key)
local d = func(key)
tab[key] = d
return d
end
})
end
}
for i=2,10 do
local nextmemo = memofunc[i-1]
memofunc[i] = function(func, weak)
return memo(function(arg)
return nextmemo[funci(function(arg) return func(arg) end, weak)
end, weak)
end
end
file: lua/swamp/sh_init.lua
Just calls the function with the args
file: lua/swamp/sh_init.lua
Shorthand timer.Simple(0, callback) and also passes args
file: lua/swamp/sh_init.lua
Returns next power of 2 >= n
file: lua/swamp/sh_init.lua
Wraps a function with a cache to store computations when the same arguments are reused. Google: Memoization
The returned memo should be "called" by indexing it:
a = memo(function(x,y) return x*y end)
print(a[2][3]) --prints 6
If the function returns nil, nothing will be stored, and the second return value will be returned by the indexing.
params are extra things to put in the metatable (eg __mode), or index 1 can be a default initialization for the table
file: lua/swamp/sh_init.lua
Shorthand for empty function
file: lua/swamp/sh_init.lua
Check if tables contain the same data, even if they are different tables (deep copy OK)
file: lua/swamp/sh_init.lua
Convert a table of {k=v} to {v=k}
file: lua/swamp/sh_init.lua
Convert an ordered table {a,b,c} into a set {[a]=true,[b]=true,[c]=true}
file: lua/swamp/sh_init.lua
Copy table at the first layer only
file: lua/swamp/sh_init.lua
Returns the largest index such that tab[index] > val (or is the end)
file: lua/swamp/sh_init.lua
Selects the maximum value of an ordered table. See also: table.imin
file: lua/swamp/sh_init.lua
Sums an ordered table.
file: lua/swamp/sh_init.lua
Selects a range of an ordered table similar to string.sub
file: lua/swamp/sh_init.lua
Calls the function and if it fails, calls catch (default: ErrorNoHaltWithStack) with the error. Doesn't return anything
file: lua/swamp/sh_init.lua
weak reference, call it to get the thing or nil if its gone
file: lua/swamp/sh_init.lua
Omit FindMetaTable from your code because these globals always refer to their respective metatables.
Player/Entity are still callable and function the same as the default global functions.
file: lua/swamp/sh_meta.lua
Number of points
file: lua/swamp/shop/sh_init.lua (hidden)
If the player has at least this many points. Don't use it on the server if you are about to buy something; just do TryTakePoints
file: lua/swamp/shop/sh_init.lua (hidden)
Returns min,max such that the rotated bbox render.DrawWireframeBox(Vector(0,0,0), angle, min, max) tightly bounds the entity's model in world space. no angle means Angle(0,0,0). if offset it gets applied in world space
file: lua/swamp/shop/sh_modelbounds.lua (hidden)
Give points. callback
happens once the points are written. fcallback
= failed to write
file: lua/swamp/shop/sv_init.lua (hidden)
Take points, but only if they have enough.
callback
runs once the points have been taken.
fcallback
runs if they don't have enough points or it otherwise fails to take them
file: lua/swamp/shop/sv_init.lua (hidden)
Get the value of the stat with the given name. If default isn't given it is 0
file: lua/swamp/sql/sh_stats.lua
Call this like: Redis.Get("a", callback(value) end) or Redis({"get","a"}, {"get","b"}, callback(values) end)
file: lua/swamp/sql/sv_init_redis.lua (hidden)
Adds increment (or 1) to a stat with the given name
file: lua/swamp/sql/sv_stats.lua (hidden)
Sets the stat to 1 (cheaper storage than integer stats)
file: lua/swamp/sql/sv_stats.lua (hidden)
Adds the other player to the "partner set" by the given name. This way you can make stats that require interaction with many players.
file: lua/swamp/sql/sv_stats.lua (hidden)
Sets the stat with the given name to the max of its previous value and the record
file: lua/swamp/sql/sv_stats.lua (hidden)
Like WebMaterial
but sets it to an entity (only needs to be called once)
The material will load when the entity is close unless args.forceload=true
is passed.
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Like Entity:SetWebMaterial
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Assign a function to this ITexture which will be called(width,height) on the next PreDrawHUD and with the rendertarget/viewport stuff setup.
Finishes all painting in order on one frame and can be called recursively.
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Like CreateRenderTargetEx, but the args are a table with good defaults, you don't need a name, and if the ITexture gets garbage collected it can reuse the rendertarget for another call (since you can't delete RTs)
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
To use web materials, just call in your draw hook:
mat = WebMaterial(args)
Then set/override material to mat
args is a table with the following potential keys:\
- id: string, from
SanitizeImgurId
\ - owner: player/steamid or nil\
- pos: vector or nil - rendering position, used for delayed distance loading\
- stretch: bool = false (stretch to fill frame, or contain to maintain aspect)\
- shader: str = "VertexLitGeneric"\
- params: str = "{}" - A "table" of material parameters for CreateMaterial (NOT A TABLE, A STRING THAT CAN BE PARSED AS A TABLE)\
- pointsample: bool = false\
- nsfw: bool = false - (can be false, true, or "?")
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
a weak table is like a table that has paper hands and keeps dropping key/value pairs
file: lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Like SanitizeImgurId, but more powerful (if a url to an gallery is passed we'll try to look it up)
file: lua/swamp/webmaterials/sh_webmaterials.lua (hidden)
Converts an imgur id or url to an imgur id (nil if it doesn't work)
file: lua/swamp/webmaterials/sh_webmaterials.lua (hidden)
Like AsyncSanitizeImgurId but won't spam requests (waits until the previous request finished, and only the latest request can stay in the queue)
file: lua/swamp/webmaterials/sh_webmaterials.lua (hidden)
Call this to make a DFrame dissapear if the user hits escape
file: compile/lua/swamp/extensions/cl_vgui_function.lua (hidden)
This defines the function vgui(classname, parent (optional), constructor) which creates and returns a panel.
The parent should only be passed when creating a root element (eg. a DFrame) which need a parent.
Child elements should be constructed using vgui() from within the parent's constructor, and their parent will be set automatically.
This is helpful for creating complex guis as the hierarchy of the layout is clearly reflected in the code structure.
Example: (a better example is in the file)\
vgui("Panel", function(p)\
-- p is the panel, set it up here\
vgui("DLabel", function(p)\
-- p is the label here\
end)\
end)\
file: compile/lua/swamp/extensions/cl_vgui_function.lua (hidden)
Makes an "anim" which smoothly interpolates a value
init = default value
force = acceleration towards target value
callback runs when value changes (return true to stop updating, but this happens automatically when target is reached)
returned table has functions __call() to get the current value, SetTarget(value) to set a target, SetInstant(value) to jump and set velocity to zero
file: compile/lua/swamp/extensions/sh_anim.lua (hidden)
Anim which will set a named property on a subject (entity or panel)
The value is placed at ent.Key and the anim is at ent.KeyAnim
file: compile/lua/swamp/extensions/sh_anim.lua (hidden)
A global cache of all entities, in subtables divided by classname.
Works on client and server. Much, much faster than ents.FindByClass
or even player.GetAll
Each subtable is ordered and will never be nil even if no entities were created.
To use it try something like this: for i,v in ipairs(Ents.prop_physics) do
...
file: compile/lua/swamp/extensions/sh_ents_cache.lua (hidden)
Unlike the built-in function, this (along with player.GetBySteamID64 and player.GetByAccountID) is fast.
file: compile/lua/swamp/misc/sh_playerbysteamid.lua (hidden)
Get current title string or ""
file: compile/lua/swamp/misc/sh_titles.lua (hidden)
Rate limiter for net recievers and commands and whatnot. Interval is how many seconds between each action. Burst is how many we can do fast (default 1).
The function returns TRUE if the action should be blocked, FALSE if it should be ALLOWED. So do like if ply:RateLimit("thing", 1, 1) then return end
to rate limit everything after it.
Call it with no arguments to use a default reasonable value for clickable actions or whatever.
file: compile/lua/swamp/misc/sv_swamp_misc.lua (hidden)
A struct is a table with only string keys, and all string keys are kept on the NetworkString table. It's not as static as a C struct.
file: compile/lua/swamp/sh_api.lua (hidden)
Register a function which is called on the server and executed on the client. See this file for details.
file: compile/lua/swamp/sh_api.lua (hidden)
Global cache/generator for tables
Use to localize tables that can't be cleared on file refresh or have to sync in multiple files
local stuff = Table.MyWeaponStuff
file: compile/lua/swamp/sh_init.lua (hidden)
Returns a table such that when indexing the table, if the value doesn't exist, the constructor will be called with the key to initialize it.
function defaultdict(constructor, args)
assert(args==nil)
return setmetatable(args or {}, {
__index = function(tab, key)
local d = constructor(key)
tab[key] = d
return d
end,
__mode = mode
})
end
-- __mode = weak and "v" or nil
local memofunc = {
function(func)
return setmetatable({}, {
__index = function(tab, key)
local d = func(key)
tab[key] = d
return d
end
})
end
}
for i=2,10 do
local nextmemo = memofunc[i-1]
memofunc[i] = function(func, weak)
return memo(function(arg)
return nextmemo[funci(function(arg) return func(arg) end, weak)
end, weak)
end
end
file: compile/lua/swamp/sh_init.lua (hidden)
Just calls the function with the args
file: compile/lua/swamp/sh_init.lua (hidden)
Shorthand timer.Simple(0, callback) and also passes args
file: compile/lua/swamp/sh_init.lua (hidden)
Returns next power of 2 >= n
file: compile/lua/swamp/sh_init.lua (hidden)
Wraps a function with a cache to store computations when the same arguments are reused. Google: Memoization
The returned memo should be "called" by indexing it:
a = memo(function(x,y) return x*y end)
print(a[2][3]) --prints 6
If the function returns nil, nothing will be stored, and the second return value will be returned by the indexing.
params are extra things to put in the metatable (eg __mode), or index 1 can be a default initialization for the table
file: compile/lua/swamp/sh_init.lua (hidden)
Shorthand for empty function
file: compile/lua/swamp/sh_init.lua (hidden)
Check if tables contain the same data, even if they are different tables (deep copy OK)
file: compile/lua/swamp/sh_init.lua (hidden)
Convert a table of {k=v} to {v=k}
file: compile/lua/swamp/sh_init.lua (hidden)
Convert an ordered table {a,b,c} into a set {[a]=true,[b]=true,[c]=true}
file: compile/lua/swamp/sh_init.lua (hidden)
Copy table at the first layer only
file: compile/lua/swamp/sh_init.lua (hidden)
Returns the largest index such that tab[index] > val (or is the end)
file: compile/lua/swamp/sh_init.lua (hidden)
Selects the maximum value of an ordered table. See also: table.imin
file: compile/lua/swamp/sh_init.lua (hidden)
Sums an ordered table.
file: compile/lua/swamp/sh_init.lua (hidden)
Selects a range of an ordered table similar to string.sub
file: compile/lua/swamp/sh_init.lua (hidden)
Calls the function and if it fails, calls catch (default: ErrorNoHaltWithStack) with the error. Doesn't return anything
file: compile/lua/swamp/sh_init.lua (hidden)
weak reference, call it to get the thing or nil if its gone
file: compile/lua/swamp/sh_init.lua (hidden)
Give points. callback
happens once the points are written. fcallback
= failed to write
file: compile/lua/swamp/shop/sv_init.lua (hidden)
Take points, but only if they have enough.
callback
runs once the points have been taken.
fcallback
runs if they don't have enough points or it otherwise fails to take them
file: compile/lua/swamp/shop/sv_init.lua (hidden)
Get the value of the stat with the given name. If default isn't given it is 0
file: compile/lua/swamp/sql/sh_stats.lua (hidden)
Call this like: Redis.Get("a", callback(value) end) or Redis({"get","a"}, {"get","b"}, callback(values) end)
file: compile/lua/swamp/sql/sv_init_redis.lua (hidden)
Adds increment (or 1) to a stat with the given name
file: compile/lua/swamp/sql/sv_stats.lua (hidden)
Sets the stat to 1 (cheaper storage than integer stats)
file: compile/lua/swamp/sql/sv_stats.lua (hidden)
Adds the other player to the "partner set" by the given name. This way you can make stats that require interaction with many players.
file: compile/lua/swamp/sql/sv_stats.lua (hidden)
Sets the stat with the given name to the max of its previous value and the record
file: compile/lua/swamp/sql/sv_stats.lua (hidden)
Like WebMaterial
but sets it to an entity (only needs to be called once)
The material will load when the entity is close unless args.forceload=true
is passed.
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Like Entity:SetWebMaterial
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Assign a function to this ITexture which will be called(width,height) on the next PreDrawHUD and with the rendertarget/viewport stuff setup.
Finishes all painting in order on one frame and can be called recursively.
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Like CreateRenderTargetEx, but the args are a table with good defaults, you don't need a name, and if the ITexture gets garbage collected it can reuse the rendertarget for another call (since you can't delete RTs)
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
To use web materials, just call in your draw hook:
mat = WebMaterial(args)
Then set/override material to mat
args is a table with the following potential keys:\
- id: string, from
SanitizeImgurId
\ - owner: player/steamid or nil\
- pos: vector or nil - rendering position, used for delayed distance loading\
- stretch: bool = false (stretch to fill frame, or contain to maintain aspect)\
- shader: str = "VertexLitGeneric"\
- params: str = "{}" - A "table" of material parameters for CreateMaterial (NOT A TABLE, A STRING THAT CAN BE PARSED AS A TABLE)\
- pointsample: bool = false\
- nsfw: bool = false - (can be false, true, or "?")
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
a weak table is like a table that has paper hands and keeps dropping key/value pairs
file: compile/lua/swamp/webmaterials/cl_webmaterials.lua (hidden)
Shorthand for gamemode name
file: repos/contrib/lua/autorun/swamp.lua (hidden)
Int location ID
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
String
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
Location table
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
Theater table
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
Bool
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
Global function to compute a location ID (avoid this, it doesn't cache)
file: repos/contrib/lua/cinema/location/sh_location.lua (hidden)
Generates a font quickly. Caches so it can be used in paint hooks.
Example input: draw.DrawText("based", Font.Arial24)
file: repos/contrib/lua/swamp/cl_font.lua (hidden)
surface.GetTextSize with cached result
file: repos/contrib/lua/swamp/cl_font.lua (hidden)
Prints how long it takes to run a function, averaging over a large number of samples with minimal overhead
file: repos/contrib/lua/swamp/dev/sh_bench.lua (hidden)
For hacking/debugging. FindSinglePlayer but just returns nil if matches multiple.
file: repos/contrib/lua/swamp/dev/sh_util.lua (hidden)
Use this global instead of LocalPlayer()
It will be either nil or a valid entity. Don't write if IsValid(Me)
... , just write if Me
...
file: repos/contrib/lua/swamp/extensions/cl_me.lua (hidden)
Call the function when Me becomes valid
file: repos/contrib/lua/swamp/extensions/cl_me.lua (hidden)
Runs cam.Start3D2D(pos, ang, scale) callback() cam.End3D2D()
but only if the user is in front of the "screen" so they can see it.
file: repos/contrib/lua/swamp/extensions/cl_render_extension.lua (hidden)
Bool if we are currently drawing to the screen.
file: repos/contrib/lua/swamp/extensions/cl_render_extension.lua (hidden)
Sets the color modulation, calls your callback, then sets it back to what it was before.
file: repos/contrib/lua/swamp/extensions/cl_render_extension.lua (hidden)
Call this to make a DFrame dissapear if the user hits escape
file: repos/contrib/lua/swamp/extensions/cl_vgui_function.lua (hidden)
This defines the function vgui(classname, parent (optional), constructor) which creates and returns a panel.
The parent should only be passed when creating a root element (eg. a DFrame) which need a parent.
Child elements should be constructed using vgui() from within the parent's constructor, and their parent will be set automatically.
This is helpful for creating complex guis as the hierarchy of the layout is clearly reflected in the code structure.
Example: (a better example is in the file)\
vgui("Panel", function(p)\
-- p is the panel, set it up here\
vgui("DLabel", function(p)\
-- p is the label here\
end)\
end)\
file: repos/contrib/lua/swamp/extensions/cl_vgui_function.lua (hidden)
A timer which will only call the callback (with the entity passed as the argument) if the ent is still valid
file: repos/contrib/lua/swamp/extensions/sh_ent_timer.lua (hidden)
A timer which will only call the callback (with the entity passed as the argument) if the ent is still valid
file: repos/contrib/lua/swamp/extensions/sh_ent_timer.lua (hidden)
A global cache of all entities, in subtables divided by classname.
Works on client and server. Much, much faster than ents.FindByClass
or even player.GetAll
Each subtable is ordered and will never be nil even if no entities were created.
To use it try something like this: for i,v in ipairs(Ents.prop_physics) do
...
file: repos/contrib/lua/swamp/extensions/sh_ents_cache.lua (hidden)
NWP="Networked Private"
A table on each player. Values written on server will automatically be replicated to that client. Won't be sent to other players. Read-only on client, read-write on server.
file: repos/contrib/lua/swamp/extensions/sh_nwprivate.lua (hidden)
IsPlayer and not IsBot
file: repos/contrib/lua/swamp/extensions/sh_player_extension.lua (hidden)
Faster than writing IsValid(ply:GetActiveWeapon()) and ply:GetActiveWeapon():GetClass()==class
file: repos/contrib/lua/swamp/extensions/sh_player_extension.lua (hidden)
Find a player whose name contains some text. If it finds exactly one matching player, returns that player. Otherwise, returns the number of found players (0 or >=2). To use this check isnumber() on the return.
file: repos/contrib/lua/swamp/extensions/sh_playerbyname.lua (hidden)
Turns a number of seconds into a string like hh:mm:ss or mm:ss
file: repos/contrib/lua/swamp/extensions/sh_string.lua (hidden)
Pop up the MOTD browser thing with this URL
file: repos/contrib/lua/swamp/misc/cl_motd.lua (hidden)
Show a notification (bottow center screen popup). OK to call on invalid players (does nothing).
file: repos/contrib/lua/swamp/misc/sh_notify.lua (hidden)
Return player's actual Steam name without any filters (eg removing swamp.sv). All default name functions have filters.
file: repos/contrib/lua/swamp/misc/sh_player_name_filter.lua (hidden)
Unlike the built-in function, this (along with player.GetBySteamID64 and player.GetByAccountID) is fast.
file: repos/contrib/lua/swamp/misc/sh_playerbysteamid.lua (hidden)
Get current title string or ""
file: repos/contrib/lua/swamp/misc/sh_titles.lua (hidden)
Boolean, mostly for players
file: repos/contrib/lua/swamp/pony/sh_init.lua (hidden)
A struct is a table with only string keys, and all string keys are kept on the NetworkString table. It's not as static as a C struct.
file: repos/contrib/lua/swamp/sh_api.lua (hidden)
Register a function which is called on the server and executed on the client. See this file for details.
file: repos/contrib/lua/swamp/sh_api.lua (hidden)
Global cache/generator for tables
Use to localize tables that can't be cleared on file refresh or have to sync in multiple files
local stuff = Table.MyWeaponStuff
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Returns a table such that when indexing the table, if the value doesn't exist, the constructor will be called with the key to initialize it.
function defaultdict(constructor, args)
assert(args==nil)
return setmetatable(args or {}, {
__index = function(tab, key)
local d = constructor(key)
tab[key] = d
return d
end,
__mode = mode
})
end
-- __mode = weak and "v" or nil
local memofunc = {
function(func)
return setmetatable({}, {
__index = function(tab, key)
local d = func(key)
tab[key] = d
return d
end
})
end
}
for i=2,10 do
local nextmemo = memofunc[i-1]
memofunc[i] = function(func, weak)
return memo(function(arg)
return nextmemo[funci(function(arg) return func(arg) end, weak)
end, weak)
end
end
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Just calls the function with the args
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Shorthand timer.Simple(0, callback) and also passes args
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Returns next power of 2 >= n
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Wraps a function with a cache to store computations when the same arguments are reused. Google: Memoization
The returned memo should be "called" by indexing it:
a = memo(function(x,y) return x*y end)
print(a[2][3]) --prints 6
If the function returns nil, nothing will be stored, and the second return value will be returned by the indexing.
params are extra things to put in the metatable (eg __mode), or index 1 can be a default initialization for the table
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Shorthand for empty function
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Check if tables contain the same data, even if they are different tables (deep copy OK)
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Convert a table of {k=v} to {v=k}
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Convert an ordered table {a,b,c} into a set {[a]=true,[b]=true,[c]=true}
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Copy table at the first layer only
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Returns the largest index such that tab[index] > val (or is the end)
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Selects the maximum value of an ordered table. See also: table.imin
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Sums an ordered table.
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Selects a range of an ordered table similar to string.sub
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Calls the function and if it fails, calls catch (default: ErrorNoHaltWithStack) with the error. Doesn't return anything
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
weak reference, call it to get the thing or nil if its gone
file: repos/contrib/lua/swamp/sh_init.lua (hidden)
Omit FindMetaTable from your code because these globals always refer to their respective metatables.
Player/Entity are still callable and function the same as the default global functions.
file: repos/contrib/lua/swamp/sh_meta.lua (hidden)
Get the value of the stat with the given name. If default isn't given it is 0
file: repos/contrib/lua/swamp/sql/sh_stats.lua (hidden)
Will probably be deprecated
possible options:
pitch
crouchpitch
level
volume
channel
ent: emit from this ent instead of player
shared: emit on client without networking, assuming called in shared function
speech: move player lips (time to move lips, or auto if < 0)
file: repos/restricted/lua/cinema/sound/sh_extsound.lua (hidden)
If we are "protected" from this attacker by theater protection. att
doesn't need to be passed, it's only used to let theater owners override protection and prevent killing out of a protected area.
file: repos/restricted/lua/cinema/theater/sh_protection.lua (hidden)
Bool (typing a chat message)
file: repos/restricted/lua/swamp/chat/sh_swampchat.lua (hidden)
Makes an "anim" which smoothly interpolates a value
init = default value
force = acceleration towards target value
callback runs when value changes (return true to stop updating, but this happens automatically when target is reached)
returned table has functions __call() to get the current value, SetTarget(value) to set a target, SetInstant(value) to jump and set velocity to zero
file: repos/restricted/lua/swamp/extensions/sh_anim.lua (hidden)
Anim which will set a named property on a subject (entity or panel)
The value is placed at ent.Key and the anim is at ent.KeyAnim
file: repos/restricted/lua/swamp/extensions/sh_anim.lua (hidden)
Number of points
file: repos/restricted/lua/swamp/shop/sh_init.lua (hidden)
If the player has at least this many points. Don't use it on the server if you are about to buy something; just do TryTakePoints
file: repos/restricted/lua/swamp/shop/sh_init.lua (hidden)
Returns min,max such that the rotated bbox render.DrawWireframeBox(Vector(0,0,0), angle, min, max) tightly bounds the entity's model in world space. no angle means Angle(0,0,0). if offset it gets applied in world space
file: repos/restricted/lua/swamp/shop/sh_modelbounds.lua (hidden)
Note: docs above are generated from luadoc-style code comments. README.md is autogenerated from readme_format.md
COPYRIGHT: This repository and most of its content is copyrighted and owned by Swamp Servers LLC. All other content is, to the best of our knowledge, used under license. If your copyrighted work is here without permission, please contact the email shown here. This repository DOES NOT license its contents to be used for other purposes, nor does its existence on GitHub imply such a license. This repository is almost entirely comprised of client/shared code and assets, which can already be extracted from GMod directly (eg. with gluasteal), so this repository does not grant new access to our content.
CONTRIBUTOR LICENSE AGREEMENT: This repository is solely for game assets/code used by Swamp Servers LLC to operate our online games. By submitting your work to this repository (via commits/pull requests), you agree that we have a PERMANENT, IRREVOCABLE, WORLDWIDE, TRANSFERABLE LICENSE to use, modify, and distribute all of your submitted work as we see fit. By submitting work created by a third party, you attest that the creator of that work also agrees that we have a permanent, irrevocable, worldwide, transferable license to use, modify, and distribute their submitted work as we see fit. Do not submit work from a third party without their agreement to these terms. Note that work publicly available on sites like "Steam Workshop" may already be distributed under agreements conducive to this.