mirror of
https://github.com/darksaid98/overextended.github.io.git
synced 2026-12-02 06:28:54 +00:00
update lib.addCommand
This commit is contained in:
1 parent
8ce5644b8c
commit
b4c985a59f
1 file changed
+43
-11
@@ -1,18 +1,50 @@
|
|||||||
|
Registers commands and simplifies argument validation, permissions, and chat suggestions.
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.addCommand(principal, command, callback, parameters, help)
|
lib.addCommand(commandName, properties, cb)
|
||||||
```
|
```
|
||||||
|
|
||||||
* principal: `string` or `string[]` or `false`
|
- commandName: `string` or `string[]`
|
||||||
* command: `string`
|
- properties: `table` or `false`
|
||||||
* callback: `function`
|
- help?: `string`
|
||||||
* parameters?: `table` (`array`)
|
- restricted?: `boolean` or `string` or `string[]`
|
||||||
* help?: `string`
|
- params?: `table[]`
|
||||||
|
- name: `string`
|
||||||
|
- help?: `string`
|
||||||
|
- type?: `'number'` or `'playerId'` or `'string'`
|
||||||
|
- optional?: `boolean`
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
lib.addCommand('group.admin', {'additem', 'giveitem'}, function(source, args)
|
lib.addCommand('giveitem', {
|
||||||
args.item = Items(args.item)
|
help = 'Gives an item to a player',
|
||||||
if args.item and args.count > 0 then
|
params = {
|
||||||
Inventory.AddItem(args.target, args.item.name, args.count, args.metatype)
|
{
|
||||||
|
name = 'target',
|
||||||
|
type = 'playerId',
|
||||||
|
help = 'Target player\'s server id', },
|
||||||
|
{
|
||||||
|
name = 'item',
|
||||||
|
type = 'string',
|
||||||
|
help = 'Name of the item to give',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = 'count',
|
||||||
|
type = 'number',
|
||||||
|
help = 'Amount of the item to give, or blank to give 1',
|
||||||
|
optional = true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = 'metatype',
|
||||||
|
help = 'Sets the item\'s "metadata.type"',
|
||||||
|
optional = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
restricted = 'group.admin'
|
||||||
|
}, function(source, args, raw)
|
||||||
|
local item = Items(args.item)
|
||||||
|
|
||||||
|
if item then
|
||||||
|
Inventory.AddItem(args.target, item.name, args.count or 1, args.metatype)
|
||||||
end
|
end
|
||||||
end, {'target:number', 'item:string', 'count:number', 'metatype:?string'})
|
end)
|
||||||
```
|
```
|
||||||
Reference in new issue
Block a user