diff --git a/lilia/gamemode/core/meta/character.lua b/lilia/gamemode/core/meta/character.lua index f0adfdc47..4cc374345 100644 --- a/lilia/gamemode/core/meta/character.lua +++ b/lilia/gamemode/core/meta/character.lua @@ -22,7 +22,7 @@ debug.getregistry().Character = lia.meta.character -- @treturn String A string in the format "character[ID]", where ID is the character's unique identifier. -- @usage -- print(lia.char.loaded[1]) --- -- Output: "character[1]" +-- Output: "character[1]" function characterMeta:__tostring() return "character[" .. (self.id or 0) .. "]" end @@ -35,7 +35,7 @@ end -- local char1 = lia.char.loaded[1] -- local char2 = lia.char.loaded[2] -- print(char1 == char2) --- -- Output: false +-- Output: false function characterMeta:__eq(other) return self:getID() == other:getID() end @@ -46,7 +46,7 @@ end -- @usage -- local charID = character:getID() -- print(charID) --- -- Output: 1 +-- Output: 1 function characterMeta:getID() return self.id end @@ -164,7 +164,7 @@ if SERVER then -- @string flags A string containing one or more flags to assign to the character. -- @usage -- character:setFlags("petr") - -- -- This sets the character's flags to 'p', 'e', 't', 'r' + -- This sets the character's flags to 'p', 'e', 't', 'r' function characterMeta:setFlags(flags) self:setData("f", flags) end @@ -174,7 +174,7 @@ if SERVER then -- @string flags A string containing one or more flags to add. -- @usage -- character:giveFlags("pet") - -- -- Adds 'p', 'e', and 't' flags to the character + -- Adds 'p', 'e', and 't' flags to the character function characterMeta:giveFlags(flags) local addedFlags = "" for i = 1, #flags do @@ -193,9 +193,9 @@ if SERVER then -- @realm server -- @string flags A string containing one or more flags to remove. -- @usage - -- -- For a character with "pet" flags + -- For a character with "pet" flags -- character:takeFlags("p") - -- -- The character now only has 'e' and 't' flags + -- The character now only has 'e' and 't' flags function characterMeta:takeFlags(flags) local oldFlags = self:getFlags() local newFlags = oldFlags diff --git a/lilia/gamemode/core/meta/inventory.lua b/lilia/gamemode/core/meta/inventory.lua index 7670a6c63..7d38b40b0 100644 --- a/lilia/gamemode/core/meta/inventory.lua +++ b/lilia/gamemode/core/meta/inventory.lua @@ -102,7 +102,7 @@ end -- @see lia.inventory.newType -- @usage -- inventory:register("grid") --- -- This sets the inventory's type to 'grid' +-- This sets the inventory's type to 'grid' function Inventory:register(typeID) assert(isstring(typeID), "Expected argument #1 of " .. self.className .. ".register to be a string") self.typeID = typeID @@ -136,7 +136,7 @@ end -- @treturn String A string representation of the inventory, including its class name and ID. -- @usage -- print(tostring(inventory)) --- -- Output: "Inventory[123]" +-- Output: "Inventory[123]" function Inventory:__tostring() return self.className .. "[" .. tostring(self.id) .. "]" end diff --git a/lilia/gamemode/core/meta/item.lua b/lilia/gamemode/core/meta/item.lua index fd41d92c4..69ec56591 100644 --- a/lilia/gamemode/core/meta/item.lua +++ b/lilia/gamemode/core/meta/item.lua @@ -51,7 +51,7 @@ end -- @treturn String String representation. -- @usage -- print(tostring(lia.item.instances[1])) --- -- Output: "item[uniqueID][1]" +-- Output: "item[uniqueID][1]" function ITEM:__tostring() return "item[" .. self.uniqueID .. "][" .. self.id .. "]" end diff --git a/lilia/gamemode/core/meta/player.lua b/lilia/gamemode/core/meta/player.lua index 54194d5cf..1bb590fb9 100644 --- a/lilia/gamemode/core/meta/player.lua +++ b/lilia/gamemode/core/meta/player.lua @@ -16,17 +16,24 @@ do -- @realm shared -- @treturn[1] Character Currently loaded character -- @treturn[2] nil If this player has no character loaded + -- @usage + -- local char = player:getChar() + -- if char then + -- print("Character Name:", char:getName()) + -- end function playerMeta:getChar() - return lia.char.loaded[self.getNetVar(self, "char")] + return lia.char.loaded[self:getNetVar("char")] end --- Returns this player's current name. -- @realm shared - -- @treturn[1] string Name of this player's currently loaded character - -- @treturn[2] string Steam name of this player if the player has no character loaded + -- @treturn String Name of this player's currently loaded character + -- @treturn String Steam name of this player if the player has no character loaded + -- @usage + -- print("Player Name:", player:Name()) function playerMeta:Name() - local character = self.getChar(self) - return character and character.getName(character) or self.steamName(self) + local character = self:getChar() + return character and character:getName() or self.steamName() end playerMeta.GetCharacter = playerMeta.getChar @@ -36,8 +43,12 @@ end --- Checks if the player has a specified CAMI privilege. -- @realm shared --- @param privilegeName string The name of the privilege to check. --- @treturn boolean True if the player has the privilege, false otherwise. +-- @string privilegeName The name of the privilege to check. +-- @treturn Boolean True if the player has the privilege, false otherwise. +-- @usage +-- if player:HasPrivilege("admin") then +-- print("Player is an admin.") +-- end function playerMeta:HasPrivilege(privilegeName) return CAMI.PlayerHasAccess(self, privilegeName, nil) end @@ -45,6 +56,11 @@ end --- Gets the current vehicle the player is in, if any. -- @realm shared -- @treturn Entity|nil The current vehicle entity, or nil if the player is not in a vehicle. +-- @usage +-- local vehicle = player:getCurrentVehicle() +-- if vehicle then +-- print("Player is in a vehicle:", vehicle:GetClass()) +-- end function playerMeta:getCurrentVehicle() local vehicle = self:GetVehicle() if vehicle and IsValid(vehicle) then return vehicle end @@ -57,25 +73,33 @@ end --- Checks if the player is in a valid vehicle. -- @realm shared --- @treturn bool true if the player is in a valid vehicle, false otherwise. +-- @treturn Boolean True if the player is in a valid vehicle, false otherwise. +-- @usage +-- if player:hasValidVehicle() then +-- print("Player is in a valid vehicle.") +-- end function playerMeta:hasValidVehicle() return IsValid(self:getCurrentVehicle()) end --- Checks if the player is currently observing. -- @realm shared --- @treturn bool Whether the player is currently observing. +-- @treturn Boolean Whether the player is currently observing. +-- @usage +-- if player:isObserving() then +-- print("Player is observing.") +-- end function playerMeta:isObserving() - if self:GetMoveType() == MOVETYPE_NOCLIP and not self:hasValidVehicle() then - return true - else - return false - end + return self:GetMoveType() == MOVETYPE_NOCLIP and not self:hasValidVehicle() end --- Checks if the player is currently moving. -- @realm shared --- @treturn bool Whether the player is currently moving. +-- @treturn Boolean Whether the player is currently moving. +-- @usage +-- if player:isMoving() then +-- print("Player is moving.") +-- end function playerMeta:isMoving() if not IsValid(self) or not self:Alive() then return false end local keydown = self:KeyDown(IN_FORWARD) or self:KeyDown(IN_BACK) or self:KeyDown(IN_MOVELEFT) or self:KeyDown(IN_MOVERIGHT) @@ -84,7 +108,11 @@ end --- Checks if the player is currently outside (in the sky). -- @realm shared --- @treturn bool Whether the player is currently outside (in the sky). +-- @treturn Boolean Whether the player is currently outside (in the sky). +-- @usage +-- if player:isOutside() then +-- print("Player is outside.") +-- end function playerMeta:isOutside() local trace = util.TraceLine({ start = self:GetPos(), @@ -96,7 +124,11 @@ end --- Checks if the player is currently in noclip mode. -- @realm shared --- @treturn bool Whether the player is in noclip mode. +-- @treturn Boolean Whether the player is in noclip mode. +-- @usage +-- if player:isNoClipping() then +-- print("Player is in noclip mode.") +-- end function playerMeta:isNoClipping() return self:GetMoveType() == MOVETYPE_NOCLIP end @@ -104,17 +136,30 @@ end --- Retrieves the player's DarkRP money. -- This is used as compatibility for DarkRP Vars. -- @realm shared --- @tparam string var The DarkRP variable to fetch (only "money" is allowed). --- @treturn number|nil The player's money if the variable is valid, or nil if not. +-- @string var The DarkRP variable to fetch (only "money" is allowed). +-- @treturn Integer|nil The player's money if the variable is valid, or nil if not. +-- @usage +-- local money = player:getDarkRPVar("money") +-- if money then +-- print("Player Money:", money) +-- end function playerMeta:getDarkRPVar(var) local char = self:getChar() - if var ~= "money" then self:ChatPrint("Invalid variable requested! Only 'money' can be fetched. Please refer to our Discord for help.") end + if var ~= "money" then + self:ChatPrint("Invalid variable requested! Only 'money' can be fetched. Please refer to our Discord for help.") + return nil + end + if char and char.getMoney then return char:getMoney() end end --- Checks if the player has a valid ragdoll entity. -- @realm shared --- @treturn bool Whether the player has a valid ragdoll entity. +-- @treturn Boolean Whether the player has a valid ragdoll entity. +-- @usage +-- if player:hasRagdoll() then +-- print("Player has a ragdoll.") +-- end function playerMeta:hasRagdoll() return IsValid(self.liaRagdoll) end @@ -122,6 +167,11 @@ end --- Returns the player's ragdoll entity if valid. -- @realm shared -- @treturn Entity|nil The player's ragdoll entity if it exists and is valid, otherwise nil. +-- @usage +-- local ragdoll = player:getRagdoll() +-- if ragdoll then +-- print("Ragdoll found:", ragdoll:GetClass()) +-- end function playerMeta:getRagdoll() if not self:hasRagdoll() then return end return self.liaRagdoll @@ -129,7 +179,11 @@ end --- Checks if the player is stuck. -- @realm shared --- @treturn bool Whether the player is stuck. +-- @treturn Boolean Whether the player is stuck. +-- @usage +-- if player:isStuck() then +-- print("Player is stuck.") +-- end function playerMeta:isStuck() return util.TraceEntity({ start = self:GetPos(), @@ -141,24 +195,34 @@ end --- Calculates the squared distance from the player to the specified entity. -- @realm shared -- @entity entity The entity to calculate the distance to. --- @treturn number The squared distance from the player to the entity. +-- @treturn Float The squared distance from the player to the entity. +-- @usage +-- local sqDist = player:squaredDistanceFromEnt(entity) +-- print("Squared Distance:", sqDist) function playerMeta:squaredDistanceFromEnt(entity) - return self:GetPos():DistToSqr(entity) + return self:GetPos():DistToSqr(entity:GetPos()) end --- Calculates the distance from the player to the specified entity. -- @realm shared -- @entity entity The entity to calculate the distance to. --- @treturn number The distance from the player to the entity. +-- @treturn Float The distance from the player to the entity. +-- @usage +-- local dist = player:distanceFromEnt(entity) +-- print("Distance:", dist) function playerMeta:distanceFromEnt(entity) - return self:GetPos():Distance(entity) + return self:GetPos():Distance(entity:GetPos()) end --- Checks if the player is near another entity within a specified radius. -- @realm shared -- @int radius The radius within which to check for proximity. -- @entity entity The entity to check proximity to. --- @treturn bool Whether the player is near the specified entity within the given radius. +-- @treturn Boolean Whether the player is near the specified entity within the given radius. +-- @usage +-- if player:isNearPlayer(100, targetPlayer) then +-- print("Player is near the target.") +-- end function playerMeta:isNearPlayer(radius, entity) local squaredRadius = radius * radius local squaredDistance = self:GetPos():DistToSqr(entity:GetPos()) @@ -168,8 +232,13 @@ end --- Retrieves entities near the player within a specified radius. -- @realm shared -- @int radius The radius within which to search for entities. --- @bool[opt] playerOnly If true, only return player entities. --- @treturn table A table containing the entities near the player. +-- @bool playerOnly If true, only return player entities. +-- @treturn Table A table containing the entities near the player. +-- @usage +-- local nearbyPlayers = player:entitiesNearPlayer(200, true) +-- for _, p in ipairs(nearbyPlayers) do +-- print("Nearby Player:", p:Nick()) +-- end function playerMeta:entitiesNearPlayer(radius, playerOnly) local nearbyEntities = {} for _, v in ipairs(ents.FindInSphere(self:GetPos(), radius)) do @@ -182,18 +251,23 @@ end --- Retrieves the active weapon item of the player. -- @realm shared -- @treturn Entity|nil The active weapon entity of the player, or nil if not found. +-- @usage +-- local weapon, item = player:getItemWeapon() +-- if weapon then +-- print("Active Weapon:", weapon:GetClass()) +-- end function playerMeta:getItemWeapon() local character = self:getChar() local inv = character:getInv() local items = inv:getItems() local weapon = self:GetActiveWeapon() - if not IsValid(weapon) then return false end + if not IsValid(weapon) then return nil end for _, v in pairs(items) do if v.class then if v.class == weapon:GetClass() and v:getData("equip", false) then return weapon, v else - return false + return nil end end end @@ -204,7 +278,13 @@ end -- It is designed to be compatible with the DarkRP `canAfford` method. -- @realm shared -- @int amount The amount of money to check. --- @treturn bool Whether the player's character can afford the specified amount of money. +-- @treturn Boolean Whether the player's character can afford the specified amount of money. +-- @usage +-- if player:canAfford(500) then +-- print("Player can afford the item.") +-- else +-- print("Player cannot afford the item.") +-- end function playerMeta:canAfford(amount) local character = self:getChar() return character and character:hasMoney(amount) @@ -216,6 +296,11 @@ end -- If the total amount exceeds the configured money limit, the excess is spawned as an item in the world. -- @realm shared -- @int amount The amount of money to add. +-- @tab receivers Players who should receive updates about the quantity change. +-- @bool noCheckEntity If true, entity checks will be skipped. +-- @treturn void +-- @usage +-- player:addMoney(1000, {player}, false) function playerMeta:addMoney(amount) local character = self:getChar() if not character then return end @@ -242,6 +327,9 @@ end --- Takes money from the player's character. -- @realm shared -- @int amount The amount of money to take. +-- @treturn void +-- @usage +-- player:takeMoney(200) function playerMeta:takeMoney(amount) local character = self:getChar() if character then character:giveMoney(-amount) end @@ -249,7 +337,10 @@ end --- Retrieves the amount of money owned by the player's character. -- @realm shared --- @treturn number The amount of money owned by the player's character. +-- @treturn Integer The amount of money owned by the player's character. +-- @usage +-- local money = player:getMoney() +-- print("Player Money:", money) function playerMeta:getMoney() local character = self:getChar() return character and character:getMoney() or 0 @@ -257,14 +348,22 @@ end --- Checks if the player is running. -- @realm shared --- @treturn bool Whether the player is running. +-- @treturn Boolean Whether the player is running. +-- @usage +-- if player:isRunning() then +-- print("Player is running.") +-- end function playerMeta:isRunning() return vectorMeta.Length2D(self:GetVelocity()) > (self:GetWalkSpeed() + 10) end --- Checks if the player's character is female based on the model. -- @realm shared --- @treturn bool Whether the player's character is female. +-- @treturn Boolean Whether the player's character is female. +-- @usage +-- if player:isFemale() then +-- print("Player character is female.") +-- end function playerMeta:isFemale() local model = self:GetModel():lower() return model:find("female") or model:find("alyx") or model:find("mossman") or lia.anim.getModelClass(model) == "citizen_female" @@ -273,6 +372,9 @@ end --- Calculates the position to drop an item from the player's inventory. -- @realm shared -- @treturn Vector The position to drop an item from the player's inventory. +-- @usage +-- local dropPos = player:getItemDropPos() +-- item:spawn(dropPos, Angle(0, 0, 0)) function playerMeta:getItemDropPos() local data = {} data.start = self:GetShootPos() @@ -288,7 +390,14 @@ end --- Retrieves the items of the player's character inventory. -- @realm shared --- @treturn table|nil A table containing the items in the player's character inventory, or nil if not found. +-- @treturn Table|nil A table containing the items in the player's character inventory, or nil if not found. +-- @usage +-- local items = player:getItems() +-- if items then +-- for _, item in ipairs(items) do +-- print("Item:", item.uniqueID) +-- end +-- end function playerMeta:getItems() local character = self:getChar() if character then @@ -300,18 +409,28 @@ end --- Retrieves the entity traced by the player's aim. -- @realm shared -- @treturn Entity|nil The entity traced by the player's aim, or nil if not found. +-- @usage +-- local target = player:getTracedEntity() +-- if target then +-- print("Traced Entity:", target:GetClass()) +-- end function playerMeta:getTracedEntity() local data = {} data.start = self:GetShootPos() data.endpos = data.start + self:GetAimVector() * 96 data.filter = self - local target = util.TraceLine(data).Entity - return target + local targetEntity = util.TraceLine(data).Entity + return targetEntity end --- Performs a trace from the player's view. -- @realm shared --- @treturn table A table containing the trace result. +-- @treturn Table A table containing the trace result. +-- @usage +-- local trace = player:getTrace() +-- if trace.Hit then +-- print("Trace hit:", trace.Entity:GetClass()) +-- end function playerMeta:getTrace() local data = {} data.start = self:GetShootPos() @@ -325,8 +444,13 @@ end --- Retrieves the entity within the player's line of sight. -- @realm shared --- @int[opt] distance The maximum distance to consider. +-- @int distance The maximum distance to consider. -- @treturn Entity|nil The entity within the player's line of sight, or nil if not found. +-- @usage +-- local eyeEnt = player:getEyeEnt(200) +-- if eyeEnt then +-- print("Entity in sight:", eyeEnt:GetClass()) +-- end function playerMeta:getEyeEnt(distance) distance = distance or 150 local e = self:GetEyeTrace().Entity @@ -335,8 +459,13 @@ end if SERVER then --- Loads Lilia data for the player from the database. - -- @func[opt] callback Function to call after the data is loaded, passing the loaded data as an argument. -- @realm server + -- @func callback Function to call after the data is loaded, passing the loaded data as an argument. + -- @treturn void + -- @usage + -- player:loadLiliaData(function(data) + -- print("Data loaded:", data) + -- end) function playerMeta:loadLiliaData(callback) local name = self:steamName() local steamID64 = self:SteamID64() @@ -367,6 +496,9 @@ if SERVER then --- Saves the player's Lilia data to the database. -- @realm server + -- @treturn void + -- @usage + -- player:saveLiliaData() function playerMeta:saveLiliaData() if self:IsBot() then return end local name = self:steamName() @@ -380,29 +512,69 @@ if SERVER then end --- Sets a key-value pair in the player's Lilia data. - -- @string key The key for the data. - -- @param value The value to set. - -- @bool[opt] noNetworking If true, suppresses network broadcasting of the update. -- @realm server - function playerMeta:setLiliaData(key, value, noNetworking) + -- @string key The key for the data. + -- @tparam any[opt=nil] value The value to set. + -- @tab[opt=nil] receivers The players to replicate the data on. + -- @bool noSave Whether to disable saving the data in the database or not. + -- @bool noCheckEntity Whether to disable setting the data on the entity, if applicable. + -- @treturn void + -- @usage + -- player:setLiliaData("score", 1500, {player1, player2}, false, false) + function playerMeta:setLiliaData(key, value, receivers, noSave, noCheckEntity) self.liaData = self.liaData or {} self.liaData[key] = value - if not noNetworking then netstream.Start(self, "liaData", key, value) end + if not noCheckEntity then + local entity = self:getEntity() + if IsValid(entity) then entity:setNetVar("data", self.liaData) end + end + + if receivers or self:getOwner() then netstream.Start(receivers or self:getOwner(), "invData", self:getID(), key, value) end + if noSave or not lia.db then return end + if key == "x" or key == "y" then + value = tonumber(value) + if MYSQLOO_PREPARED then + lia.db.preparedCall("item" .. key, nil, value, self:getID()) + else + lia.db.updateTable({ + ["_" .. key] = value + }, nil, "items", "_itemID = " .. self:getID()) + end + return + end + + local x, y = self.data.x, self.data.y + self.data.x, self.data.y = nil, nil + if MYSQLOO_PREPARED then + lia.db.preparedCall("itemData", nil, self.data, self:getID()) + else + lia.db.updateTable({ + _data = self.data + }, nil, "items", "_itemID = " .. self:getID()) + end + + self.data.x, self.data.y = x, y end - --- Displays a notification for this player in the chatbox. + --- Notifies the player with a message. -- @realm server - -- @string message Text to display in the notification + -- @string message The message to notify the player. + -- @treturn void + -- @usage + -- player:chatNotify("Welcome to the server!") function playerMeta:chatNotify(message) net.Start("chatNotify") net.WriteString(message) net.Send(self) end - --- Displays a notification for this player in the chatbox with the given language phrase. + --- Notifies the player with a localized message. -- @realm server - -- @string message ID of the phrase to display to the player - -- @param ... Arguments to pass to the phrase + -- @string message ID of the phrase to display to the player. + -- @tparam ... any Arguments to pass to the phrase. + -- @treturn void + -- @usage + -- player:chatNotifyLocalized("welcome_message", player:Nick()) function playerMeta:chatNotifyLocalized(message, ...) message = L(message, self, ...) net.Start("chatNotify") @@ -411,10 +583,13 @@ if SERVER then end --- Retrieves a value from the player's Lilia data. - -- @string key The key for the data. - -- @param default[opt=nil] The default value to return if the key does not exist. -- @realm server + -- @string key The key for the data. + -- @tparam any[opt=nil] default The default value to return if the key does not exist. -- @treturn any The value corresponding to the key, or the default value if the key does not exist. + -- @usage + -- local level = player:getLiliaData("level", 1) + -- print("Player Level:", level) function playerMeta:getLiliaData(key, default) if key == true then return self.liaData end local data = self.liaData and self.liaData[key] @@ -427,18 +602,25 @@ if SERVER then --- Sets the player's ragdoll entity. -- @realm server - -- @tparam Entity entity The entity to set as the player's ragdoll. + -- @entity entity The entity to set as the player's ragdoll. + -- @treturn void + -- @usage + -- local ragdoll = player:createServerRagdoll() + -- player:setRagdoll(ragdoll) function playerMeta:setRagdoll(entity) self.liaRagdoll = entity end --- Sets an action bar for the player. + -- @realm server -- @string text The text to display on the action bar. - -- @int[opt] time The duration for the action bar to display, defaults to 5 seconds. Set to 0 or nil to remove the action bar immediately. - -- @func[opt] callback Function to execute when the action bar timer expires. + -- @int[opt=5] time The duration for the action bar to display in seconds. Set to 0 or nil to remove the action bar immediately. + -- @func callback Function to execute when the action bar timer expires. -- @int[opt] startTime The start time of the action bar, defaults to the current time. -- @int[opt] finishTime The finish time of the action bar, defaults to startTime + time. - -- @realm server + -- @treturn void + -- @usage + -- player:setAction("Processing...", 10, function(p) print("Action completed for", p:Nick()) end) function playerMeta:setAction(text, time, callback, startTime, finishTime) if time and time <= 0 then if callback then callback(self) end @@ -461,6 +643,9 @@ if SERVER then --- Stops the action bar for the player. -- Removes the action bar currently being displayed. -- @realm server + -- @treturn void + -- @usage + -- player:stopAction() function playerMeta:stopAction() timer.Remove("liaAct" .. self:SteamID64()) netstream.Start(self, "actBar") @@ -469,9 +654,12 @@ if SERVER then --- Plays a sound for the player. -- @realm server -- @string sound The sound to play. - -- @int[opt] volume The volume of the sound (default 75). - -- @int[opt] pitch The pitch of the sound (default 100). - -- @bool[opt] shouldEmit Whether to emit sound server-side or send it to the client. + -- @int[opt=75] volume The volume of the sound. + -- @int[opt=100] pitch The pitch of the sound. + -- @bool shouldEmit Whether to emit sound server-side or send it to the client. + -- @treturn void + -- @usage + -- player:PlaySound("ambient/alarms/warningbell1.wav", 100, 100, false) function playerMeta:PlaySound(sound, volume, pitch, shouldEmit) volume = volume or 75 pitch = pitch or 100 @@ -488,7 +676,10 @@ if SERVER then --- Opens a VGUI panel for the player. -- @realm server - -- @param panel The name of the VGUI panel to open. + -- @string panel The name of the VGUI panel to open. + -- @treturn void + -- @usage + -- player:openUI("InventoryPanel") function playerMeta:openUI(panel) net.Start("OpenVGUI") net.WriteString(panel) @@ -499,6 +690,9 @@ if SERVER then --- Opens a web page for the player. -- @realm server -- @string url The URL of the web page to open. + -- @treturn void + -- @usage + -- player:openPage("https://example.com") function playerMeta:openPage(url) net.Start("OpenPage") net.WriteString(url) @@ -511,6 +705,11 @@ if SERVER then -- @string subTitle The subtitle of the request. -- @tab options The table of options to choose from. -- @func callback The function to call upon receiving the selected option. + -- @treturn void + -- @usage + -- player:requestDropdown("Choose Option", "Select one of the following:", {"Option1", "Option2"}, function(selected) + -- print("Player selected:", selected) + -- end) function playerMeta:requestDropdown(title, subTitle, options, callback) net.Start("DropdownRequest") net.WriteString(title) @@ -525,8 +724,13 @@ if SERVER then -- @string title The title of the request. -- @string subTitle The subtitle of the request. -- @tab options The table of options to choose from. - -- @number limit The maximum number of selectable options. + -- @int limit The maximum number of selectable options. -- @func callback The function to call upon receiving the selected options. + -- @treturn void + -- @usage + -- player:requestOptions("Select Items", "Choose up to 3 items:", {"Item1", "Item2", "Item3"}, 3, function(selected) + -- print("Player selected:", table.concat(selected, ", ")) + -- end) function playerMeta:requestOptions(title, subTitle, options, limit, callback) net.Start("OptionsRequest") net.WriteString(title) @@ -542,8 +746,20 @@ if SERVER then -- @string title The title of the string input dialog. -- @string subTitle The subtitle or description of the string input dialog. -- @func callback The function to call with the entered string. - -- @param[opt] default The default value for the string input. - -- @treturn Promise A promise object resolving with the entered string. + -- @string[opt=nil] default The default value for the string input. + -- @treturn Promise|nil A promise object resolving with the entered string, or nil if a callback is provided. + -- @usage + -- player:requestString("Enter Name", "Please enter your name:", function(name) + -- print("Player entered:", name) + -- end) + -- + -- -- Using promise + -- local promise = player:requestString("Enter Name", "Please enter your name:", "DefaultName") + -- if promise then + -- promise:next(function(name) + -- print("Player entered:", name) + -- end) + -- end function playerMeta:requestString(title, subTitle, callback, default) local d if not isfunction(callback) and default == nil then @@ -570,6 +786,15 @@ if SERVER then -- @string option2 The text for the second option. -- @bool manualDismiss Whether the notice should be manually dismissed. -- @func callback The function to call with the choice (0 or 1) when the player selects an option. + -- @treturn void + -- @usage + -- player:binaryQuestion("Confirm Action", "Are you sure you want to proceed?", "Yes", "No", false, function(choice) + -- if choice == 1 then + -- print("Player chose Yes.") + -- else + -- print("Player chose No.") + -- end + -- end) function playerMeta:binaryQuestion(question, option1, option2, manualDismiss, callback) net.Start("BinaryQuestionRequest") net.WriteString(question) @@ -582,7 +807,10 @@ if SERVER then --- Retrieves the player's total playtime. -- @realm server - -- @treturn number The total playtime of the player. + -- @treturn Float The total playtime of the player. + -- @usage + -- local playTime = player:getPlayTime() + -- print("Playtime:", playTime, "seconds") function playerMeta:getPlayTime() local diff = os.time(lia.date.toNumber(self.lastJoin)) - os.time(lia.date.toNumber(self.firstJoin)) return diff + (RealTime() - (self.liaJoinTime or RealTime())) @@ -591,8 +819,10 @@ if SERVER then playerMeta.GetPlayTime = playerMeta.getPlayTime --- Creates a ragdoll entity for the player on the server. -- @realm server - -- @bool[opt] dontSetPlayer Determines whether to associate the player with the ragdoll. + -- @bool dontSetPlayer Determines whether to associate the player with the ragdoll. -- @treturn Entity The created ragdoll entity. + -- @usage + -- local ragdoll = player:createServerRagdoll() function playerMeta:createServerRagdoll(dontSetPlayer) local entity = ents.Create("prop_ragdoll") entity:SetPos(self:GetPos()) @@ -628,9 +858,16 @@ if SERVER then -- @realm server -- @entity entity The entity towards which the player performs the stared action. -- @func callback The function to call when the stared action is completed. - -- @int[opt] time The duration of the stared action in seconds. - -- @func[opt] onCancel The function to call if the stared action is canceled. - -- @int[opt] distance The maximum distance for the stared action. + -- @int[opt=5] time The duration of the stared action in seconds. + -- @func onCancel The function to call if the stared action is canceled. + -- @int[opt=96] distance The maximum distance for the stared action. + -- @treturn void + -- @usage + -- player:doStaredAction(targetEntity, function() + -- print("Stared action completed.") + -- end, 10, function() + -- print("Stared action canceled.") + -- end, 150) function playerMeta:doStaredAction(entity, callback, time, onCancel, distance) local uniqueID = "liaStare" .. self:SteamID64() local data = {} @@ -654,25 +891,64 @@ if SERVER then end) end - --- Notifies the player with a message. + --- Notifies the player with a message and prints the message to their chat. -- @realm server - -- @string message The message to notify the player. - function playerMeta:notify(message) - lia.notices.notify(message, self) + -- @string message The message to notify and print. + -- @treturn void + -- @usage + -- player:notifyP("You have received a new item!") + function playerMeta:notifyP(message) + self:notify(message) + self:chatNotify(message) end - --- Notifies the player with a localized message. + --- Sets a waypoint for the player. -- @realm server - -- @string message The key of the localized message to notify the player. - -- @tab ... Additional arguments to format the localized message. - function playerMeta:notifyLocalized(message, ...) - lia.notices.notifyLocalized(message, self, ...) + -- @string name The name of the waypoint. + -- @tparam Vector vector The position vector of the waypoint. + -- @func onReach Function to call when the player reaches the waypoint. + -- @treturn void + -- @usage + -- player:setWeighPoint("Spawn Point", Vector(100, 200, 300), function(p) + -- print("Player reached the waypoint.") + -- end) + function playerMeta:setWeighPoint(name, vector, onReach) + hook.Add("HUDPaint", "WeighPoint", function() + local dist = self:GetPos():Distance(vector) + local spos = vector:ToScreen() + local howclose = math.Round(math.floor(dist) / 40) + if not spos then return end + render.SuppressEngineLighting(true) + surface.SetFont("WB_Large") + draw.DrawText(name .. "\n" .. howclose .. " Meters\n", "CenterPrintText", spos.x, spos.y, Color(123, 57, 209), TEXT_ALIGN_CENTER) + render.SuppressEngineLighting(false) + if howclose <= 3 then RunConsoleCommand("weighpoint_stop") end + end) + + concommand.Add("weighpoint_stop", function() + hook.Remove("HUDPaint", "WeighPoint") + if IsValid(onReach) then onReach() end + end) + end + + --- Retrieves the player's total playtime. + -- @realm client + -- @treturn Float The total playtime of the player. + -- @usage + -- local playTime = player:getPlayTime() + -- print("Playtime:", playTime, "seconds") + function playerMeta:getPlayTime() + local diff = os.time(lia.date.toNumber(lia.lastJoin)) - os.time(lia.date.toNumber(lia.firstJoin)) + return diff + (RealTime() - (lia.joinTime or 0)) end + playerMeta.GetPlayTime = playerMeta.getPlayTime --- Creates a ragdoll entity for the player. -- @realm server -- @bool freeze Whether to freeze the ragdoll initially. -- @treturn Entity The created ragdoll entity. + -- @usage + -- local ragdoll = player:createRagdoll(true) function playerMeta:createRagdoll(freeze) local entity = ents.Create("prop_ragdoll") entity:SetPos(self:GetPos()) @@ -706,9 +982,12 @@ if SERVER then --- Sets the player to a ragdolled state or removes the ragdoll. -- @realm server -- @bool state Whether to set the player to a ragdolled state (`true`) or remove the ragdoll (`false`). - -- @int[opt] time The duration for which the player remains ragdolled. - -- @int[opt] getUpGrace The grace period for the player to get up before the ragdoll is removed. - -- @string[opt] getUpMessage The message displayed when the player is getting up. + -- @int[opt=0] time The duration for which the player remains ragdolled. + -- @int[opt=0] getUpGrace The grace period for the player to get up before the ragdoll is removed. + -- @string[opt="@wakingUp"] getUpMessage The message displayed when the player is getting up. + -- @treturn void + -- @usage + -- player:setRagdolled(true, 10, 5, "@gettingUp") function playerMeta:setRagdolled(state, time, getUpGrace, getUpMessage) getUpMessage = getUpMessage or "@wakingUp" local hasRagdoll = self:hasRagdoll() @@ -819,8 +1098,10 @@ if SERVER then end --- Synchronizes networked variables with the player. - -- @internal -- @realm server + -- @treturn void + -- @usage + -- player:syncVars() function playerMeta:syncVars() for entity, data in pairs(lia.net) do if entity == "globals" then @@ -838,7 +1119,10 @@ if SERVER then --- Sets a local variable for the player. -- @realm server -- @string key The key of the variable. - -- @param value The value of the variable. + -- @tparam any value The value of the variable. + -- @treturn void + -- @usage + -- player:setLocalVar("health", 100) function playerMeta:setLocalVar(key, value) if checkBadType(key, value) then return end lia.net[self] = lia.net[self] or {} @@ -850,6 +1134,9 @@ if SERVER then --- Notifies the player with a message and prints the message to their chat. -- @realm server -- @string text The message to notify and print. + -- @treturn void + -- @usage + -- player:notifyP("You have received a new item!") function playerMeta:notifyP(text) self:notify(text) self:chatNotify(text) @@ -857,16 +1144,22 @@ if SERVER then else --- Displays a notification for this player in the chatbox. -- @realm client - -- @string message Text to display in the notification + -- @string message Text to display in the notification. + -- @treturn void + -- @usage + -- player:chatNotify("Welcome to the server!") function playerMeta:chatNotify(message) local client = LocalPlayer() if self == client then chat.AddText(Color(255, 215, 0), message) end end - --- Displays a notification for this player in the chatbox with the given language phrase. + --- Displays a notification for the player in the chatbox with the given language phrase. -- @realm client - -- @string message ID of the phrase to display to the player - -- @param ... Arguments to pass to the phrase + -- @string message ID of the phrase to display to the player. + -- @tparam ... any Arguments to pass to the phrase. + -- @treturn void + -- @usage + -- player:chatNotifyLocalized("welcome_message", player:Nick()) function playerMeta:chatNotifyLocalized(message, ...) local client = LocalPlayer() if self == client then @@ -877,27 +1170,37 @@ else --- Retrieves the player's total playtime. -- @realm client - -- @treturn number The total playtime of the player. + -- @treturn Float The total playtime of the player. + -- @usage + -- local playTime = player:getPlayTime() + -- print("Playtime:", playTime, "seconds") function playerMeta:getPlayTime() local diff = os.time(lia.date.toNumber(lia.lastJoin)) - os.time(lia.date.toNumber(lia.firstJoin)) - return diff + (RealTime() - lia.joinTime or 0) + return diff + (RealTime() - (lia.joinTime or 0)) end playerMeta.GetPlayTime = playerMeta.getPlayTime --- Opens a UI panel for the player. - -- @param panel The panel type to create. -- @realm client + -- @string panel The panel type to create. -- @treturn Panel The created UI panel. + -- @usage + -- local inventoryPanel = player:openUI("InventoryPanel") function playerMeta:openUI(panel) return vgui.Create(panel) end playerMeta.OpenUI = playerMeta.openUI --- Sets a waypoint for the player. + -- @realm client -- @string name The name of the waypoint. -- @vector vector The position vector of the waypoint. - -- @func onReach[opt=nil] Function to call when the player reaches the waypoint. - -- @realm client + -- @func onReach Function to call when the player reaches the waypoint. + -- @treturn void + -- @usage + -- player:setWeighPoint("Spawn Point", Vector(100, 200, 300), function(p) + -- print("Player reached the waypoint.") + -- end) function playerMeta:setWeighPoint(name, vector, onReach) hook.Add("HUDPaint", "WeighPoint", function() local dist = self:GetPos():Distance(vector) @@ -912,16 +1215,19 @@ else end) concommand.Add("weighpoint_stop", function() - hook.Add("HUDPaint", "WeighPoint", function() end) + hook.Remove("HUDPaint", "WeighPoint") if IsValid(onReach) then onReach() end end) end --- Retrieves a value from the local Lilia data. - -- @string key The key for the data. - -- @param[opt] default The default value to return if the key does not exist. -- @realm client + -- @string key The key for the data. + -- @tparam any[opt=nil] default The default value to return if the key does not exist. -- @treturn any The value corresponding to the key, or the default value if the key does not exist. + -- @usage + -- local rank = player:getLiliaData("rank", "Novice") + -- print("Player Rank:", rank) function playerMeta:getLiliaData(key, default) local data = lia.localData and lia.localData[key] if data == nil then @@ -952,7 +1258,7 @@ playerMeta.GetTrace = playerMeta.getTrace playerMeta.GetEyeEnt = playerMeta.getEyeEnt playerMeta.SetAction = playerMeta.setAction playerMeta.StopAction = playerMeta.stopAction -playerMeta.PlaySound = playerMeta.playSound +playerMeta.PlaySound = playerMeta.PlaySound playerMeta.OpenPage = playerMeta.openPage playerMeta.CreateServerRagdoll = playerMeta.createServerRagdoll playerMeta.DoStaredAction = playerMeta.doStaredAction diff --git a/lilia/gamemode/core/meta/tool.lua b/lilia/gamemode/core/meta/tool.lua index f7382522b..11f82f0d7 100644 --- a/lilia/gamemode/core/meta/tool.lua +++ b/lilia/gamemode/core/meta/tool.lua @@ -12,11 +12,13 @@ By integrating with Lilia's files, the `ToolGun` class enables developers to bui ]] -- @toolmeta Framework local ToolGunMeta = lia.meta.tool or {} - --- Creates a new tool object. -- This method initializes a new tool object with default properties. It sets up the metatable and various default values such as `Mode`, `SWEP`, `Owner`, `ClientConVar`, `ServerConVar`, `Objects`, `Stage`, `Message`, `LastMessage`, and `AllowedCVar`. -- @realm shared --- @return table A new tool object with default properties. +-- @treturn Table A new tool object with default properties. +-- @usage +-- local tool = ToolGunMeta:Create() +-- tool.Mode = "builder" function ToolGunMeta:Create() local object = {} setmetatable(object, self) @@ -37,6 +39,9 @@ end --- Creates client and server convars for the tool. -- This method generates convars (console variables) based on the tool's mode. Client convars are created on the client-side, while server convars are created on the server-side. -- @realm shared +-- @treturn void +-- @usage +-- tool:CreateConVars() function ToolGunMeta:CreateConVars() local mode = self:GetMode() if CLIENT then @@ -53,7 +58,9 @@ end -- This method returns the value of a server-side convar associated with the tool's mode. -- @realm shared -- @string property The name of the property to retrieve. --- @return string The value of the server convar. +-- @treturn ConVar The server convar object. +-- @usage +-- local allowUse = tool:GetServerInfo("allow_use"):GetBool() function ToolGunMeta:GetServerInfo(property) local mode = self:GetMode() return ConVar(mode .. "_" .. property) @@ -62,7 +69,12 @@ end --- Builds a list of client-side convars. -- This method constructs a table of convars by appending the mode prefix to each convar name. -- @realm shared --- @return table A table containing the mode-prefixed convars. +-- @treturn Table A table containing the mode-prefixed convars. +-- @usage +-- local convars = tool:BuildConVarList() +-- for k, v in pairs(convars) do +-- print(k, v) +-- end function ToolGunMeta:BuildConVarList() local mode = self:GetMode() local convars = {} @@ -76,7 +88,10 @@ end -- This method returns the value of a client-side convar associated with the tool's mode. -- @realm shared -- @string property The name of the property to retrieve. --- @return string The value of the client convar. +-- @treturn String The value of the client convar. +-- @usage +-- local toolSetting = tool:GetClientInfo("setting") +-- print("Tool Setting:", toolSetting) function ToolGunMeta:GetClientInfo(property) return self:GetOwner():GetInfo(self:GetMode() .. "_" .. property) end @@ -85,8 +100,11 @@ end -- This method returns the value of a client-side convar as a number, or a default value if the convar does not exist. -- @realm shared -- @string property The name of the property to retrieve. --- @number default The default value to return if the convar is not found. --- @return number The numerical value of the client convar. +-- @float default The default value to return if the convar does not exist. +-- @treturn Float The numerical value of the client convar. +-- @usage +-- local toolPower = tool:GetClientNumber("power", 10) +-- print("Tool Power:", toolPower) function ToolGunMeta:GetClientNumber(property, default) return self:GetOwner():GetInfoNum(self:GetMode() .. "_" .. property, tonumber(default) or 0) end @@ -94,7 +112,13 @@ end --- Checks if the tool is allowed on the server. -- This method returns whether the tool is allowed based on the server convar `AllowedCVar`. It always returns true on the client-side. -- @realm shared --- @return boolean True if the tool is allowed, false otherwise. +-- @treturn Boolean True if the tool is allowed, false otherwise. +-- @usage +-- if tool:Allowed() then +-- print("Tool is allowed.") +-- else +-- print("Tool is not allowed.") +-- end function ToolGunMeta:Allowed() if CLIENT then return true end return self.AllowedCVar:GetBool() @@ -103,13 +127,21 @@ end --- Placeholder for initializing the tool. -- This method is intended to be overridden if initialization logic is needed when the tool is created. -- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:Init() +-- -- Custom initialization logic here +-- end function ToolGunMeta:Init() end --- Retrieves the mode of the tool. -- This method returns the current mode of the tool, which is a string representing the specific operation the tool is set to perform. -- @realm shared --- @return string The current mode of the tool. +-- @treturn String The current mode of the tool. +-- @usage +-- local mode = tool:GetMode() +-- print("Tool Mode:", mode) function ToolGunMeta:GetMode() return self.Mode end @@ -117,7 +149,10 @@ end --- Retrieves the SWEP (Scripted Weapon) associated with the tool. -- This method returns the SWEP object, which is typically the weapon the player is holding while using the tool. -- @realm shared --- @return SWEP The SWEP object associated with the tool. +-- @treturn SWEP The SWEP object associated with the tool. +-- @usage +-- local swep = tool:GetSWEP() +-- print("Tool SWEP:", swep:GetClass()) function ToolGunMeta:GetSWEP() return self.SWEP end @@ -125,7 +160,10 @@ end --- Retrieves the owner of the tool. -- This method returns the player who owns the tool by accessing the SWEP's `Owner` property. -- @realm shared --- @return Player The player who owns the tool. +-- @treturn Player The player who owns the tool. +-- @usage +-- local owner = tool:GetOwner() +-- print("Tool Owner:", owner:Nick()) function ToolGunMeta:GetOwner() return self:GetSWEP().Owner or self:GetOwner() end @@ -133,7 +171,10 @@ end --- Retrieves the weapon associated with the tool. -- This method returns the weapon associated with the tool by accessing the SWEP's `Weapon` property or the tool's own `Weapon` property. -- @realm shared --- @return Weapon The weapon object associated with the tool. +-- @treturn Weapon The weapon object associated with the tool. +-- @usage +-- local weapon = tool:GetWeapon() +-- print("Associated Weapon:", weapon:GetClass()) function ToolGunMeta:GetWeapon() return self:GetSWEP().Weapon or self.Weapon end @@ -141,7 +182,12 @@ end --- Handles the left-click action with the tool. -- This method is intended to be overridden to define what happens when the player left-clicks with the tool. By default, it does nothing and returns false. -- @realm shared --- @return boolean False by default, indicating no action was taken. +-- @treturn Boolean False by default, indicating no action was taken. +-- @usage +-- function ToolGunMeta:LeftClick(trace) +-- -- Custom left-click logic here +-- return true +-- end function ToolGunMeta:LeftClick() return false end @@ -149,7 +195,12 @@ end --- Handles the right-click action with the tool. -- This method is intended to be overridden to define what happens when the player right-clicks with the tool. By default, it does nothing and returns false. -- @realm shared --- @return boolean False by default, indicating no action was taken. +-- @treturn Boolean False by default, indicating no action was taken. +-- @usage +-- function ToolGunMeta:RightClick(trace) +-- -- Custom right-click logic here +-- return true +-- end function ToolGunMeta:RightClick() return false end @@ -157,6 +208,11 @@ end --- Handles the reload action with the tool. -- This method clears the objects that the tool is currently manipulating when the player reloads with the tool. -- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:Reload() +-- self:ClearObjects() +-- end function ToolGunMeta:Reload() self:ClearObjects() end @@ -164,6 +220,11 @@ end --- Deploys the tool. -- This method is called when the player equips the tool. It releases any ghost entities associated with the tool. -- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:Deploy() +-- self:ReleaseGhostEntity() +-- end function ToolGunMeta:Deploy() self:ReleaseGhostEntity() return @@ -172,6 +233,11 @@ end --- Holsters the tool. -- This method is called when the player unequips the tool. It releases any ghost entities associated with the tool. -- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:Holster() +-- self:ReleaseGhostEntity() +-- end function ToolGunMeta:Holster() self:ReleaseGhostEntity() return @@ -180,6 +246,11 @@ end --- Handles the tool's "think" logic. -- This method is called periodically to perform updates. By default, it releases any ghost entities associated with the tool. -- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:Think() +-- self:ReleaseGhostEntity() +-- end function ToolGunMeta:Think() self:ReleaseGhostEntity() end @@ -187,10 +258,47 @@ end --- Checks the validity of objects the tool is manipulating. -- This method iterates over the tool's objects and clears them if they are no longer valid, such as if the entity is no longer part of the world or is invalid. -- @realm shared +-- @treturn void +-- @usage +-- tool:CheckObjects() function ToolGunMeta:CheckObjects() for _, v in pairs(self.Objects) do if not v.Ent:IsWorld() and not v.Ent:IsValid() then self:ClearObjects() end end end -lia.meta.tool = ToolGunMeta +--- Clears all objects the tool is manipulating. +-- This method removes all objects from the tool's `Objects` table, effectively resetting the tool's state. +-- @realm shared +-- @treturn void +-- @usage +-- tool:ClearObjects() +function ToolGunMeta:ClearObjects() + self.Objects = {} +end + +--- Releases any ghost entities associated with the tool. +-- This method removes any ghost entities the tool may be holding, ensuring that no visual artifacts remain when the tool is not actively manipulating objects. +-- @realm shared +-- @treturn void +-- @usage +-- tool:ReleaseGhostEntity() +function ToolGunMeta:ReleaseGhostEntity() + if IsValid(self.GhostEntity) then + self.GhostEntity:Remove() + self.GhostEntity = nil + end +end + +--- Placeholder for handling tool-specific logic. +-- This method is intended to be overridden to implement custom logic that should be executed periodically or under specific conditions. +-- @realm shared +-- @treturn void +-- @usage +-- function ToolGunMeta:CustomLogic() +-- -- Custom periodic logic here +-- end +function ToolGunMeta:CustomLogic() +end + +lia.meta.tool = ToolGunMeta \ No newline at end of file diff --git a/lilia/modules/core/spawns/docs/hooks.lua b/lilia/modules/core/spawns/docs/hooks.lua index 6bbc94c6d..65e5408b7 100644 --- a/lilia/modules/core/spawns/docs/hooks.lua +++ b/lilia/modules/core/spawns/docs/hooks.lua @@ -80,7 +80,7 @@ end -- return false, "notNow" -- only allow staff to create a character -- end -- end --- -- non-admins will see the message "You are not allowed to do this ght now!" +-- non-admins will see the message "You are not allowed to do this ght now!" function CanPlayerCreateChar(client) end