#giveall command

1 messages · Page 1 of 1 (latest)

round sedge
#
lib.addCommand('giveall', {
    help = 'Gives all players a item of your choice',
    params = {},
    restricted = 'group.admin'
}, true, function(args)
    local item = args[1]
    local amount = tonumber(args[2])
    local players = GetPlayers()
    for _, playerId in ipairs(players) do
        exports.ox_inventory:AddItem(tonumber(playerId), item, amount)
    end
end)

ive got this but its not giving anything

twilit pendant
#

probably because tonumber(playerId)

left dawn
#

what in the ipairs

round sedge
twilit pendant
#

oh u are using ipairs

#

use pairs 🙂

#

@round sedge

round sedge
#

ty i will test it

round sedge
# twilit pendant use pairs 🙂

changed it to this after reading the ox docs and still having issues not giving items to everyone

lib.addCommand('giveitemall', {
    help = 'Gives item to all player',
    params = {
        {
            name = 'itemid',
            type = 'string',
            help = 'Item Code',
        },
        {
            name = 'count',
            type = 'number',
            help = 'Item Count',
        },
    },
    restricted = 'group.admin'
}, function(source, args, raw)
    local players = GetPlayers()
    local item = Items(args.item)
    for _, playerId in pairs(players) do
        exports.ox_inventory:AddItem(playerId, item.name, args.count)
    end
end)
twilit pendant
#

print(playerId)

#

add this and see what it says

round sedge
twilit pendant
#

theres ir usse then

#

print(json.encode(players))

round sedge
twilit pendant
#

show me the code

round sedge
# twilit pendant show me the code
lib.addCommand('giveitemall', {
    help = 'Gives an item to a player',
    params = {
        {
            name = 'itemid',
            type = 'string',
            help = 'Item Code',
        },
        {
            name = 'count',
            type = 'number',
            help = 'Item Count',
        },
    },
    restricted = 'group.admin'
}, function(source, args, raw)
    local players = GetPlayers()
    local item = Items(args.item)
    for _, playerId in pairs(players) do
        exports.ox_inventory:AddItem(playerId, item.name, args.count)
        print(json.encode(players))
    end
end)
twilit pendant
#

put the print below local players.

round sedge
twilit pendant
#

okay you are placing it in the wrong place then.

#

if the command doesnt even run.

round sedge
twilit pendant
#

is it on server side?

#

do u have perms?

round sedge
#

yes

twilit pendant
#

how does the new code look

#

the print should be on server side.

round sedge
# twilit pendant the print should be on server side.
lib.addCommand('giveitemall', {
    help = 'Gives an item to a player',
    params = {
        {
            name = 'itemid',
            type = 'string',
            help = 'Item Code',
        },
        {
            name = 'count',
            type = 'number',
            help = 'Item Count',
        },
    },
    restricted = 'group.admin'
}, function(source, args, raw)
    local players = GetPlayers()
    print(json.encode(players))
    local item = Items(args.item)
    for _, playerId in pairs(players) do
        exports.ox_inventory:AddItem(playerId, item.name, args.count)
    end
end)
twilit pendant
#

does it not print players?

round sedge
#

nah