Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion gamemode/core/libs/cl_menu.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
-- @module nut.menu
-- @moduleCommentStart
-- Library functions for nut.menu
-- @moduleCommentEnd

nut.menu = nut.menu or {}
nut.menu.list = nut.menu.list or {}

-- @type function nut.menu.add(options, positions, onRemove)
-- @typeCommentStart
-- Adds a new menu to the list of drawn menus.
-- @typeCommentEnd
-- @realm client
-- @table options A table of button text as keys and their callbacks as values.
-- @vector position The position of the menu or an entity to follow.
-- @function onRemove A function to call after the menu has faded out.
-- @treturn number The index of the menu in the list.
function nut.menu.add(options, position, onRemove)
-- Set up the width of the menu.
local width = 0
Expand Down Expand Up @@ -43,7 +56,11 @@ end
-- Gradient for subtle effects.
local gradient = Material("vgui/gradient-u")

-- @type function nut.menu.drawAll()
-- @typeCommentStart
-- A function to draw all of the active menus or hide them when needed.
-- @typeCommentEnd
-- @realm client
function nut.menu.drawAll()
local frameTime = FrameTime() * 30
local mX, mY = ScrW() * 0.5, ScrH() * 0.5
Expand Down Expand Up @@ -151,7 +168,13 @@ function nut.menu.drawAll()
end
end

-- Determines which menu is being looked at
-- @type function nut.menu.getActiveMenu()
-- @typeCommentStart
-- Determines which menu is being looked at.
-- @typeCommentEnd
-- @realm client
-- @treturn table The active menu.
-- @treturn function The currently hovered option callback.
function nut.menu.getActiveMenu()
local mX, mY = ScrW() * 0.5, ScrH() * 0.5
local position2 = LocalPlayer():GetPos()
Expand Down Expand Up @@ -209,7 +232,14 @@ function nut.menu.getActiveMenu()
end
end

-- @type function nut.menu.onButtonPressed(menu, callback)
-- @typeCommentStart
-- Handles whenever a button has been pressed.
-- @typeCommentEnd
-- @realm client
-- @int menu The menu index.
-- @func callback The callback that checks whether the button can be pressed.
-- @treturn bool Whether or not the button can be pressed.
function nut.menu.onButtonPressed(menu, callback)
table.remove(nut.menu.list, menu)

Expand Down
25 changes: 25 additions & 0 deletions gamemode/core/libs/cl_networking.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-- @module Entity
-- @moduleCommentStart
-- Entity meta functions.
-- @moduleCommentEnd

-- there isnt an entity meta file so its just gonna be here for now

local entityMeta = FindMetaTable("Entity")
local playerMeta = FindMetaTable("Player")

Expand Down Expand Up @@ -28,6 +35,15 @@ function getNetVar(key, default)
return value ~= nil and value or default
end

-- @type method Entity:getNetVar(key, default)
-- @typeCommentStart
-- Returns the networked variable of the entity.
-- @typeCommentEnd
-- @realm client
-- @classmod Entity
-- @string key The key of the networked variable.
-- @string default The default value to return if the networked variable is not set.
-- @treturn any The networked variable.
function entityMeta:getNetVar(key, default)
local index = self:EntIndex()

Expand All @@ -38,4 +54,13 @@ function entityMeta:getNetVar(key, default)
return default
end

-- @type method Entity:getLocalVar(key, value)
-- @typeCommentStart
-- Returns the networked variable of a player.
-- @typeCommentEnd
-- @realm client
-- @classmod Player
-- @string key The key of the networked variable.
-- @string default The default value to return if the networked variable is not set.
-- @treturn any The networked variable.
playerMeta.getLocalVar = entityMeta.getNetVar
38 changes: 36 additions & 2 deletions gamemode/core/libs/sh_anims.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-- @module nut.anim
-- @moduleCommentStart
-- Library functions for nut.anim
-- @moduleCommentEnd

nut.anim = nut.anim or {}

nut.anim.citizen_male = {
Expand Down Expand Up @@ -330,6 +335,13 @@ nut.anim.fastZombie = {

local translations = {}

-- @type function nut.anim.setModelClass(model, class)
-- @typeCommentStart
-- Sets the animation class for a specified model.
-- @typeCommentEnd
-- @realm shared
-- @string model The model for which to set the animation class.
-- @string class The animation class to set.
function nut.anim.setModelClass(model, class)
if (!nut.anim[class]) then
error("'"..tostring(class).."' is not a valid animation class!")
Expand All @@ -342,6 +354,13 @@ end
local stringLower = string.lower
local stringFind = string.find

-- @type function nut.anim.getModelClass(model)
-- @typeCommentStart
-- Gets the animation class for a specified model. If an animation class has not yet been set for the model, it sets a default animation class based on the model's name.
-- @typeCommentEnd
-- @realm shared
-- @string model The model for which to get the animation class.
-- @treturn string The animation class for the specified model.
function nut.anim.getModelClass(model)
model = stringLower(model)
local class = translations[model]
Expand All @@ -355,7 +374,6 @@ function nut.anim.getModelClass(model)
class = "citizen_male"
end

nut.anim.setModelClass(model, class)
return class
end

Expand All @@ -367,13 +385,23 @@ nut.anim.setModelClass("models/vortigaunt.mdl", "vort")
nut.anim.setModelClass("models/vortigaunt_blue.mdl", "vort")
nut.anim.setModelClass("models/vortigaunt_doctor.mdl", "vort")
nut.anim.setModelClass("models/vortigaunt_slave.mdl", "vort")
nut.anim.setModelClass("models/vortigaunt_slave.mdl", "vort")
nut.anim.setModelClass("models/alyx.mdl", "citizen_female")
nut.anim.setModelClass("models/mossman.mdl", "citizen_female")

do
local playerMeta = FindMetaTable("Player")

-- @type method Player:forceSequence(sequence, callback, time, noFreeze)
-- @typeCommentStart
-- Forces the player to play a specific animation sequence.
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @string sequence The name of the sequence to play.
-- @func callback An optional function to call when the animation sequence is finished.
-- @int[opt] number time The time in seconds to play the animation sequence. If not set, it will use the default time for the sequence.
-- @bool[opt] noFreeze Whether to freeze the player during the animation sequence.
-- @treturn number The time in seconds for the animation sequence to complete, or false if the sequence is invalid.
function playerMeta:forceSequence(sequence, callback, time, noFreeze)
hook.Run("OnPlayerEnterSequence", self, sequence, callback, time, noFreeze)

Expand Down Expand Up @@ -409,6 +437,12 @@ do
return false
end

-- @type method Player:leaveSequence()
-- @typeCommentStart
-- Forces the player to leave the current animation sequence they are playing.
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
function playerMeta:leaveSequence()
hook.Run("OnPlayerLeaveSequence", self)

Expand Down
55 changes: 55 additions & 0 deletions gamemode/core/libs/sh_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ if (CLIENT) then
end
end

-- @type function nut.char.new(data, id, client, steamID)
-- @typeCommentStart
-- Creates a new character object with the given data and metadata.
-- @typeCommentEnd
-- @realm shared
-- @classmod Character
-- @table data A table containing the character data.
-- @int[default=0] id The ID of the character.
-- @Player client The player associated with the character.
-- @string[opt] steamID The SteamID of the player associated with the character.
-- @treturn table The newly created character object.
function nut.char.new(data, id, client, steamID)
local character = setmetatable({vars = {}}, nut.meta.character)
for k, v in pairs(nut.char.vars) do
Expand Down Expand Up @@ -419,13 +430,42 @@ end
-- Additions to the player metatable here.
do
local playerMeta = FindMetaTable("Player")
-- @type method Player:steamName()
-- @typeCommentStart
-- Returns the players Steam name.
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn string The player's Steam name.
playerMeta.steamName = playerMeta.steamName or playerMeta.Name

-- @type method Player:SteamName()
-- @typeCommentStart
-- Returns the players Steam name. Alias to Player:steamName().
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn string The player's Steam name.
playerMeta.SteamName = playerMeta.steamName

-- @type method Player:getChar()
-- @typeCommentStart
-- Returns the character associated with the player.
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn table The character object associated with the player, or nil if no character is associated.
function playerMeta:getChar()
return nut.char.loaded[self.getNetVar(self, "char")]
end

-- @type method Player:Name()
-- @typeCommentStart
-- Returns the name of the player's character, or the player's Steam name if the character is not available.
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn string The name of the player's character or the player's Steam name if no character is available.
function playerMeta:Name()
local character = self.getChar(self)

Expand All @@ -434,6 +474,21 @@ do
or self.steamName(self)
end

-- @type method Player:Nick()
-- @typeCommentStart
-- Returns the name of the player's character, or the player's Steam name if the character is not available. Alias to Player:Name().
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn string The name of the player's character or the player's Steam name if no character is available.
playerMeta.Nick = playerMeta.Name

-- @type method Player:GetName()
-- @typeCommentStart
-- Returns the name of the player's character, or the player's Steam name if the character is not available. Alias to Player:Name().
-- @typeCommentEnd
-- @realm shared
-- @classmod Player
-- @treturn string The name of the player's character or the player's Steam name if no character is available.
playerMeta.GetName = playerMeta.Name
end
5 changes: 5 additions & 0 deletions gamemode/core/libs/sh_player.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-- @module Player
-- @moduleCommentStart
-- Player meta functions.
-- @moduleCommentEnd

local playerMeta = FindMetaTable("Player")

nut.util.include("nutscript/gamemode/core/meta/sh_player.lua")
Expand Down