Advertisement
Srlion1

Untitled

Sep 13th, 2019 (edited)
5,943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. sam.command.set_category("any_nameee") -- any new command will be in that category unless the command uses :SetCategory function
  2.  
  3. sam.command.new("command_name")
  4.     :SetPermission("hp", "admin") -- OR "superadmin" OR "user" OR remove the second argument for no default access OR just remove that line to make it for everyone!
  5.  
  6.     :DisallowConsole() -- disallow the console from running this command!
  7.  
  8.     :SetCategory("Fun") -- set the category for the command, or you can use sam.command.set_category function to set the category for any upcoming commands
  9.  
  10.     :Help("This is helpful!")
  11.  
  12.     :GetRestArgs(true) -- allows to get the rest of text, something like !ban he is a really bad boi, by default you have to do !ban "he is a really bad boi"
  13.  
  14.     :MenuHide(true) -- hide this command from the menu
  15.     :DisableNotify(true) -- hide <PLAYER(PLAYER_STEAMID)> ran command stuff in server console, useful for something like !menu command
  16.  
  17.     :AddArg("player", {
  18.         optional = true, -- makes it target the player who is calling if there is no input, like !god (MAKE SURE TO MAKE IT THE ONLY ARGUMENT)
  19.         single_target = true, -- only targets one player
  20.         cant_target_self = true, -- disallow the player who is calling to target himself
  21.         allow_higher_target = true, -- allow the player who is calling to target anyone, admin -> superadmin, useful for commands like !goto
  22.     })
  23.  
  24.     :AddArg("text", {
  25.         optional = true, -- makes it optional!
  26.         default = 50, -- add a default amount if there was no input!
  27.         hint = "name", -- ummmm?
  28.         check = function(input, ply)
  29.             if not is_good_input(input) then
  30.                 return false
  31.             end
  32.         end, -- this gets called to see if the input of this argument is valid
  33.     })
  34.  
  35.     :AddArg("number", {
  36.         optional = true, -- makes it optional!
  37.         default = 50, -- add a default amount if there was no input!
  38.         hint = "amount", -- ummmm?
  39.         min = 100, -- input < 100 then the input gonna be 100
  40.         max = 200, -- input > 200 then the input gonna be 200
  41.         round = true, -- numbers like 1.5, 1.4, 1.2 gets rounded
  42.     })
  43.  
  44.     :AddArg("length")
  45.    
  46.     -- arrays https://www.lua.org/pil/11.1.html
  47.     :OnExecute(function(calling_ply --[[the player who called this command]], targets --[[this will always be an array (https://www.lua.org/pil/11.1.html) ]], name, amount, length)
  48.         for i = 1, #targets do
  49.             local target = targets[i]
  50.             -- do something with him --
  51.         end
  52.  
  53.         sam.player.send_message(nil --[[this is like player.GetAll(), you can use an array of players or a player]], "Admin {A} targeted {T} with amount {V}, name {V_2} and length {V_3}", {
  54.             A = calling_ply, T = targets, V = amount, V_2 = name, V_3 = length
  55.         })
  56.     end)
  57. :End()
  58.  
  59. sam.command.new("do_something_with_steamid")
  60.     :AddArg("steamid") -- passes a promise
  61.     :AddArg("steamid", {allow_higher_target = true}) -- passes steamid
  62.     :OnExecute(calling_ply, function(promise, steamid_2)
  63.         -- if you set "allow_higher_target" to true then the argument will be a promise otherwise it will be a steamid
  64.         -- it needs to be done this way because I need to check if the player can target the steamid, so admins can't ban superadmins (eg. !banid "<steamid_with_higher_immunity>"
  65.         promise:done(function(data)
  66.             local steamid, target = data[1], data[2] -- target will be "nil" if player is not online
  67.         end)
  68.     end)
  69. :End()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement