Вопрос про sampRegisterChatCommand

Brooklyn123

Новичок
Автор темы
9
0
Версия MoonLoader
Другое
Приветствую, вопрос такой появился: как мне сделать так, чтобы из выбранного мною списка выдавалась машина для другого человека т.е. как это выглядит в игре /plveh *ID человека* *айди из моего списка* но чтобы авто из моего списка вставлялось само... Вот код, возможно поймете отсюда суть моего вопроса
Ещё желательно, чтобы в строке про "ты выдал" так же выписывалось название авто и его айди (тоже не знаю как сделать)


lua:
require "lib.moonloader"



local cars = {

    '451',

    '480',

    '485',

    '494',

    '506',

    '535',

    '541',

    '543',

    '562',

    '1915',

    '1932',

    '1958',

    '1963',

    '1981',

    '1993',

    '1994',

    '1995',

    '1998',

    '1999',

    '2001',

    '2002',

    '3821',

    '3822',

    '3825',

    '3831',

    '3832',

    '3835',

    '3836',

    '6024',

    '6543',

    '6544',

    '6546',

    '6552',

    '6553',

    '7762',

    '7763',

    '7774',

    '9218',

    '10560',

    '10561',

    '10562',

    '10563',

    '10568',

    '10569',

    '10570',

    '10573',

    '10814',

    '10819',

    '12839',

    '12893',

    '12922',

    '12923',

    '12926',

    '12928',

    '12949',

    '12952',

    '12953',

    '1155',

    '13646',

    '13647',

    '13648',

    '13662'

}



function main()

    if not isSampfuncsLoaded() or not isSampLoaded() then return end

    while not isSampAvailable() do wait(100) end



    sampRegisterChatCommand("randomcar", randomcar)



    sampAddChatMessage('{FF10B4}[RandomCar]: Скрипт на выдачу рандомных авто загружен', -1)



    sampRegisterChatCommand('plv', function(arg)

        local id, arg1 = string.match(arg,'(%d+) (.+)')

        id = tonumber( id )

        arg1 = tonumber (randomcar)

        if not id then

            return sampAddChatMessage('/plv [id]', 0xFF0000) end

        sampAddChatMessage(('{FF10B4}Ты выдал %s %s'):format(sampGetPlayerNickname( id ), arg1), -1)

    end)



    while true do

        wait(0)

    end

end



function randomcar()

    math.randomseed(os.time())

    rand = math.random(1, #cars)

    sampAddChatMessage(cars[rand], -1)

end
 
Последнее редактирование:
Решение
Не совсем понял, но наверное так.
Ещё желательно, чтобы в строке про "ты выдал" так же выписывалось название авто и его айди (тоже не знаю как сделать)
Для этого нужно где-то брать название авто по его айди, к примеру изменить текущую таблицу cars - вписать туда названия авто

Lua:
local cars = {
    '451',
    '480',
    '485',
    '494',
    '506',
    '535',
    '541',
    '543',
    '562',
    '1915',
    '1932',
    '1958',
    '1963',
    '1981',
    '1993',
    '1994',
    '1995',
    '1998',
    '1999',
    '2001',
    '2002',
    '3821',
    '3822',
    '3825',
    '3831',
    '3832',
    '3835',
    '3836',
    '6024',
    '6543',
    '6544',
    '6546',
    '6552',
    '6553',
    '7762',
    '7763',
    '7774'...

mooh

Известный
166
47
Не совсем понял, но наверное так.
Ещё желательно, чтобы в строке про "ты выдал" так же выписывалось название авто и его айди (тоже не знаю как сделать)
Для этого нужно где-то брать название авто по его айди, к примеру изменить текущую таблицу cars - вписать туда названия авто

Lua:
local cars = {
    '451',
    '480',
    '485',
    '494',
    '506',
    '535',
    '541',
    '543',
    '562',
    '1915',
    '1932',
    '1958',
    '1963',
    '1981',
    '1993',
    '1994',
    '1995',
    '1998',
    '1999',
    '2001',
    '2002',
    '3821',
    '3822',
    '3825',
    '3831',
    '3832',
    '3835',
    '3836',
    '6024',
    '6543',
    '6544',
    '6546',
    '6552',
    '6553',
    '7762',
    '7763',
    '7774',
    '9218',
    '10560',
    '10561',
    '10562',
    '10563',
    '10568',
    '10569',
    '10570',
    '10573',
    '10814',
    '10819',
    '12839',
    '12893',
    '12922',
    '12923',
    '12926',
    '12928',
    '12949',
    '12952',
    '12953',
    '1155',
    '13646',
    '13647',
    '13648',
    '13662'
}

function main()
    repeat wait(0) until isSampAvailable()
    sampAddChatMessage('{FF10B4}[RandomCar]: Скрипт на выдачу рандомных авто загружен', -1)

    sampRegisterChatCommand('plv', function(arg)
        if arg:find('(%d+)') then
            local playerId = tonumber(arg:match('(%d+)'))
            local randomCar = getRandomCar()
            sampSendChat(('/plveh %d %d'):format(playerId, randomCar))
            sampAddChatMessage(('{FF10B4}Ты выдал %s %s'):format(sampGetPlayerNickname(playerId), randomCar), -1)
        else
            sampAddChatMessage('/plv [id]', 0xFF0000)
        end
    end)
    wait(-1)
end

function getRandomCar()
    math.randomseed(os.time())
    rand = math.random(1, #cars)
    return cars[rand]
end
 
  • Нравится
Реакции: Brooklyn123

Anti...

Активный
276
36
Lua:
function main()

    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage('{FF10B4}[RandomCar]: Скрипт на выдачу рандомных авто загружен', -1)

    sampRegisterChatCommand("randomcar", randomcar)
    sampRegisterChatCommand("plveh", plveh)
     wait(-1)
end


function plveh(arg)
    local id, idVEH = arg:match("(%d+)%s+(%d+)")
    if not id or not idVEH then
        return sampAddChatMessage('/plveh [id] [id veh]', 0xFF0000)
    else
        local player_nickname = sampGetPlayerNickname(tonumber(id))
        for v in pairs(cars) do
            if tonumber(idVEH) == v then
                sampAddChatMessage(string.format("{FF10B4}Ты выдал: %s; автомобиль: %s", player_nickname, tonumber(idVEH)), -1)
            end
        end
    end
end
 
Последнее редактирование:
  • Клоун
Реакции: Gorskin

kyrtion

Известный
684
251
Lua:
local sf = string.format

local cars = {
    451,   480,   485,   494,   506,   535,   541,   543,   562,
    1155,  1915,  1932,  1958,  1963,  1981,  1993,  1994,  1995,
    1998,  1999,  2001,  2002,  3821,  3822,  3825,  3831,  3832,
    3835,  3836,  6024,  6543,  6544,  6546,  6552,  6553,  7762,
    7763,  7774,  9218,  10560, 10561, 10562, 10563, 10568, 10569,
    10570, 10573, 10814, 10819, 12839, 12893, 12922, 12923, 12926,
    12928, 12949, 12952, 12953, 13646, 13647, 13648, 13662
}

local function getRandomCar()
    math.randomseed(os.time())
    local rand = math.random(1, #cars)
    return cars[rand]
end

local function alert(text, ...)
    local context = sf('{FF10B4}[RandomCar]: ' .. text, ...)
    return sampAddChatMessage(context, 0xFF0000)
end

function main()
    repeat wait(0) until isSampAvailable()
    alert('Скрипт на выдачу рандомных авто загружен')

    sampRegisterChatCommand('plv', function(arg)
        if not arg or not arg:find('^%s*%d+%s*$') then
            alert('Введите: /plv [id]')
            return
        end

        local playerId = tonumber(arg:match('^%s*(%d+)%s*$'))

        if not sampIsPlayerConnected(playerId) or not sampGetPlayerNickname(playerId) then
            alert('Игрок с ID %d не в сети!', playerId)
            return
        end

        local randomModelIdCar = getRandomCar()
        local contextCommand = string.format('/plveh %d %d', playerId, randomModelIdCar)

        sampSendChat(contextCommand)
        alert('Ты выдал игроку %s[%d] на авто #%s', sampGetPlayerNickname(playerId), randomModelIdCar)
    end)
    wait(-1)
end