Помогите. Проблема с LUA кодом.

Sirccet

Участник
Автор темы
130
19
Версия SA-MP
  1. 0.3.7 (R1)
Код:
script_name("SeatCar")
script_author("Eternal_Despair")

--=[Libs]=--

local encoding = require "encoding"
encoding.default = "UTF-8"
cyr = encoding.CP1251

--=[Config]=--

local SCRIPT_PREFIX = "{FA8072}[SeatCar] {FFFFFF}"
local COOLDOWN = 1000

--=[Script Code]=--

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Скрипт загружен. Использование: {FA8072}/sc [1 - Водитель | 2,3,4 - Пассажир]"))

    sampRegisterChatCommand("sc", function(arg)
        lua_thread.create(function()
            if isCharInAnyCar(PLAYER_PED) then
                carHandle = storeCarCharIsInNoSave(PLAYER_PED)
                _, carId = sampGetVehicleIdByCarHandle(carHandle)
                maxPassengers = getMaximumNumberOfPassengers(carHandle) + 1
                if #arg == 1 then
                    if type(tonumber(arg)) == "number" then
                        seat = tonumber(arg)
                        if seat > 0 and seat <= maxPassengers then
                            sampSendExitVehicle(carId)
                            local x, y, z = getCarCoordinates(carHandle) warpCharFromCarToCoord(PLAYER_PED, x, y, z)
                            if seat == 1 then wait(400)
                                sampSendEnterVehicle(carId, false)
                                wait(COOLDOWN)
                                warpCharIntoCar(PLAYER_PED, carHandle)
                            else
                                sampSendEnterVehicle(carId, true)
                                wait(COOLDOWN)
                                taskWarpCharIntoCarAsPassenger(PLAYER_PED, carHandle, seat)
                            end
                        else
                            sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Использование: {FA8072}/sc [1-"..maxPassengers.."]"))
                        end
                    else
                        sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Использование: {FA8072}/sc [1-"..maxPassengers.."]"))
                    end
                else
                    sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Использование: {FA8072}/sc [1-"..maxPassengers.."]"))
                end
            else
                sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Ты должен находиться в транспорте!"))
            end
        end)
    end)

    while true do wait(1000)
    end
end
Суть скрипта: пересаживает перса, на то место транспорт которое написал командой (/sc 1; /sc 2; /sc 3; /sc 4)
Каждая цифры, то место в тс.
В чём заключается проблема: Когда пишу /sc 3 меня не пересаживает на 3 место в транспорте.
Помогите решить данную проблему.
 
Решение
Исправлено:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Скрипт загружен. Использование: {FA8072}/sc [1 - Водитель | 2,3,4 - Пассажир]"))

    sampRegisterChatCommand("sc", function(arg)
        lua_thread.create(function()
            if isCharInAnyCar(PLAYER_PED) then
                carHandle = storeCarCharIsInNoSave(PLAYER_PED)
                _, carId = sampGetVehicleIdByCarHandle(carHandle)
                maxPassengers = getMaximumNumberOfPassengers(carHandle) + 1
                local seat = tonumber(arg)
                if seat and seat >= 1 and seat <= maxPassengers then...

PaddingtonBaby

Участник
66
13
Исправлено:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Скрипт загружен. Использование: {FA8072}/sc [1 - Водитель | 2,3,4 - Пассажир]"))

    sampRegisterChatCommand("sc", function(arg)
        lua_thread.create(function()
            if isCharInAnyCar(PLAYER_PED) then
                carHandle = storeCarCharIsInNoSave(PLAYER_PED)
                _, carId = sampGetVehicleIdByCarHandle(carHandle)
                maxPassengers = getMaximumNumberOfPassengers(carHandle) + 1
                local seat = tonumber(arg)
                if seat and seat >= 1 and seat <= maxPassengers then
                    sampSendExitVehicle(carId)
                    local x, y, z = getCarCoordinates(carHandle)
                    warpCharFromCarToCoord(PLAYER_PED, x, y, z)
                    if seat == 1 then
                        wait(400)
                        sampSendEnterVehicle(carId, false)
                        wait(COOLDOWN)
                        warpCharIntoCar(PLAYER_PED, carHandle)
                    else
                        sampSendEnterVehicle(carId, true)
                        wait(COOLDOWN)
                        taskWarpCharIntoCarAsPassenger(PLAYER_PED, carHandle, seat - 2) 
                    end
                else
                    sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Использование: {FA8072}/sc [1-"..maxPassengers.."]"))
                end
            else
                sampAddChatMessage(cyr(SCRIPT_PREFIX .. "Ты должен находиться в транспорте!"))
            end
        end)
    end)

    while true do wait(1000) end
end
 
  • Нравится
Реакции: Sirccet