🇪🇬
SAM
  • 📔Info (READ)
    • States 🟪🟦🟨
    • Static Methods vs Instance Methods
    • (optional)
    • Console
  • 💘API
    • 👨‍🦽Player
      • Functions
        • 🟦sam.Player.set_nwvar
        • 🟪sam.Player.get_nwvar
        • 🟦sam.Player.kick_id
        • 🟦sam.Player.cloak
        • 🟦sam.Player.set_pdata
        • 🟦sam.Player.get_pdata
        • 🟦sam.Player.play_sound
        • 🟪sam.Player.has_permission
        • 🟪sam.Player.can_target
        • 🟪sam.Player.get_ban_limit
        • 🟪sam.Player.get_session_time
        • 🟪sam.Player.get_play_time
        • 🟦sam.Player.set_rank
        • 🟦sam.Player.set_rank_id
        • 🟦sam.Player.get_rank
        • 🟦sam.Player.ban
        • 🟦sam.Player.ban_id
        • 🟦sam.Player.unban
        • ✨exclusive
          • 🟦sam.Player.set_exclusive
          • 🟦sam.Player.get_exclusive
      • Hooks
        • 🟪SAM.Player.Authed
        • 🟪SAM.Player.UpdatedPlayTimes
        • 🟪SAM.Player.Rank.Changed
        • 🟪SAM.Player.Rank.Changed_STEAMID64
        • 🟪SAM.Player.Rank.Banned
        • 🟪SAM.Player.Rank.Banned_STEAMID64
        • 🟪SAM.Player.Rank.UnBanned
    • 🤖Command
      • Static
        • 🟪sam.Command.new
        • 🟪sam.Command.set_category
        • 🟪sam.Command.get
        • 🟪sam.Command.get_all
        • 🟪sam.Command.remove
        • 🟪sam.Command.new_argument
      • Command
        • 🟪Command:aliases
        • 🟪Command:add_arg
        • Page 1
      • Argument
    • 🔫Rank
      • Structure
      • Functions
        • 🟦sam.Rank.add
        • 🟦sam.Rank.remove
        • 🟦sam.Rank.rename
        • 🟦sam.Rank.change_inherit
        • 🟦sam.Rank.change_immunity
        • 🟦sam.Rank.change_ban_limit
        • 🟦sam.Rank.set_limit
        • 🟦sam.Rank.give_permission
        • 🟦sam.Rank.take_permission
        • 🟪sam.Rank.get_all
        • 🟪sam.Rank.get
        • 🟪sam.Rank.exists
        • 🟪sam.Rank.is_default
        • 🟪sam.Rank.inherits_from
        • 🟪sam.Rank.has_permission
        • 🟪sam.Rank.get_limit
        • 🟪sam.Rank.get_immunity
        • 🟪sam.Rank.can_target
        • 🟪sam.Rank.get_ban_limit
      • Hooks
        • 🟪SAM.Rank.Added
        • 🟪SAM.Rank.OnRemove
        • 🟪SAM.Rank.Removed
        • 🟪SAM.Rank.ChangedName
        • 🟪SAM.Rank.ChangedInherit
        • 🟪SAM.Rank.ChangedImmunity
        • 🟪SAM.Rank.ChangedBanLimit
        • 🟪SAM.Rank.ChangedLimit
        • 🟪SAM.Rank.PermissionGiven
        • 🟪SAM.Rank.PermissionTaken
    • ⚙️Config
      • 🟪sam.Config.set
      • 🟪sam.Config.get
    • ⚒️Util
      • 🟪sam.Util.parse_args
      • 🟪sam.Util.is_steamid
      • 🟪sam.Util.is_steamid64
      • 🟪sam.Util.is_valid_map
      • 🟪sam.Util.is_valid_gamemode
      • 🟪sam.Util.to_hex
    • 🕸️Net
      • 🟪sam.Net.start
        • 🟦sam.Net.start
        • 🟨sam.Net.start
      • 🟪sam.Net.hook
        • 🟦sam.Net.hook
        • 🟨sam.Net.hook
    • 📦Sql
      • 🟦sam.Sql.escape
      • 🟦sam.Sql.query
      • 🟦sam.Sql.fquery
      • 🟦sam.Sql.table_exists
      • 🟦sam.Sql.is_connected
      • 🟦sam.Sql.is_mysql
Powered by GitBook
On this page

Was this helpful?

  1. Info (READ)

Static Methods vs Instance Methods

A static method is a method that belongs to the class itself not to an Instance from that class.

--

An instance method is a method that belongs to an instance from a class, they require an object that gets created to be invoked.

Example:

local Player = {}
local PlayerMethods = {}

local all_players = {}

-- Player.new is a static method
-- It creates an object from Player class
function Player.new(name)
    local player = setmetatable({
        name = name
    }, {
        __index = PlayerMethods
    })
    
    table.insert(all_players, player)
    
    return player
end

-- Player.get_all is a static method
function Player.get_all()
    return all_players
end

-- PlayerMethods:kill is not a static method
-- It requires a player object to be called
function PlayerMethods:kill()
    print("Killed " .. self.name)
end

-- here is an object that we created from Player class
local player = Player.new("Srlion")
player:kill()

-- no object was created to call get_all function
print(#Player.get_all())
PreviousStates 🟪🟦🟨Next(optional)

Last updated 3 years ago

Was this helpful?

📔