Globals globals
Global functions of Catwork
Summary
Functions
library.NewClass.print.util.TableToJSON writes without losing anything.Functions
AddWorldTip(entIndex, text, dieTime, position, entity)
client gamemodes/catwork/gamemode/core/cl_kernel.lua:61Shows a world tip only to the player who owns the entity, and only while they hold the toolgun.
Replaces the engine AddWorldTip, which is kept as cw.AddWorldTip. The entity must have a
GetPlayerName method whose result matches the local player's name.
Parameters
- entIndex Number Index of the entity the tip belongs to
- text String Text of the tip
- dieTime Number Time the tip disappears
- position Vector Position of the tip
- entity Entity The entity the tip belongs to
Creates a global class; the short form of library.NewClass.
class 'CItem'
Parameters
- strName String Name of the class
- CExtends Map optional, defaults to
nilBase class to inherit from - tParent Map optional, defaults to
_GTable the class is stored in
Returns
- Map The class table
Aliases
classMeta
Creates a color from components, a hexadecimal string or a CSS color name.
Replaces the engine Color, which is kept as cw.oldColor. A string starting with # is
passed to util.HexToColor, a known CSS color name (such as 'tomato', case-insensitive)
returns that color, and any other string returns white.
Color(255, 0, 0)
Color('#ff000080')
Color('steelblue')
Parameters
- r Number Red component 0 to 255, or a color string
- g Number Green component; ignored for strings
- b Number Blue component; ignored for strings
- a Number optional, defaults to
255Alpha component; ignored for strings
Returns
- Color The color
Prints its arguments; an alias of print.
Parameters
- ... Any Values to print
Derma_NumRequest(strTitle, strText, nDefaultValue, min, max, dec, fnEnter, fnCancel, strButtonText, strButtonCancelText)
client gamemodes/catwork/gamemode/core/cl_kernel.lua:3320Opens a modal dialog that asks for a number with a slider.
Derma_NumRequest('Volume', 'Choose a volume.', 50, 0, 100, 0, function(value)
RunConsoleCommand('volume', value / 100)
end)
Parameters
- strTitle String Window title
- strText String Message above the slider
- nDefaultValue Number optional, defaults to
0Initial value - min Number optional, defaults to
0Minimum value - max Number optional, defaults to
256Maximum value - dec Number optional, defaults to
0Number of decimals - fnEnter Function Called with the value when the player confirms
- fnCancel Function optional, defaults to
nilCalled with the value when the player cancels - strButtonText String optional, defaults to
'#DermaRequest_OK'Text of the confirm button - strButtonCancelText String optional, defaults to
'#DermaRequest_confirmQuery_Cancel'Text of the cancel button
Returns
- Panel The dialog window
Returns a copy of a table that util.TableToJSON writes without losing anything.
A table whose keys are exactly 1 to n stays a list and becomes a JSON array. Any other table becomes a JSON
object, with its keys turned into strings by EncodeKey. Values that JSON cannot hold (entities, functions,
userdata, keys that are neither strings nor numbers, a table inside itself) are left out.
Parameters
- tTable Map The table
- visiting Map The tables that are being encoded right now
- skipped Map Filled with the kinds of values that were left out
Returns
- Map The table to save, or
nilwhen the table contains itself
Returns how long the server has been loading Catwork, in seconds.
Measured with os.clock from the start of init.lua, which resets the start time on every Lua refresh.
Returns
- Number Seconds since the framework started booting, rounded to three decimals
On the server
Builds a phrase string to send to clients, which translate it themselves.
Returns #Identifier:arg1,arg2;, which the client's L and cw.lang:TranslateText
understand. Can also be called without the player, as L(identifier, ...).
cw.player:Notify(player, L('CashSetTarget', '#CashSet_Cash', amount, playerName))
Parameters
- player Player The player the text is for (unused), or the identifier when called without one
- identifier String Phrase identifier without the leading
# - ... Any Arguments for
#1,#2... in the phrase; converted withtostring
Returns
- String The phrase string, or
nilwhen there is no identifier
On the client
Translates a phrase for the local player.
The identifier can carry arguments in the networked form built by the server's L:
#Identifier:arg1,arg2;.
L('#Attribute_MaximumReached')
L('#Scoreboard_Ping:'..self.player:Ping()..';')
Parameters
- identifier String Phrase identifier, with optional arguments
Returns
- String The translated text, or an empty string when
identifierisnil
See also
Defined in
Prints a C-style formatted string.
Parameters
- str String Format string for
Format - ... Any Values for the format string
Runs a console command, ignoring calls without a command name.
Wraps the engine RunConsoleCommand, which is kept as cw.RunConsoleCommand, so that a nil
command does nothing instead of raising an error.
Parameters
- command String The command name
- ... Any The command's arguments
Returns whether the screen has the given aspect ratio.
The aspect ratio is measured once when the file loads.
Parameters
- w Number Width part of the ratio, such as
16 - h Number Height part of the ratio, such as
9
Returns
- Boolean Whether the ratio matches exactly
SimpleBan(name, steamId, duration, reason, fullTime)
server gamemodes/catwork/gamemode/shared.lua:117Adds a ban to the in-memory ban list without saving it to the database.
Used at boot to apply hard-coded bans. The entry is written to cw.bans.stored, so it is lost on restart.
Parameters
- name String Steam name to show for the ban
- steamId String Steam ID of the banned player
- duration Number Ban length in seconds, or the unban time when
fullTimeis set - reason String Reason for the ban
- fullTime Boolean optional, defaults to
nilWhetherdurationis already an absoluteos.timetimestamp
Returns the lowercase name of a value's type.
Parameters
- obj Any The value to check
Returns
- String The result of
typein lowercase, such as'player'or'string'