добавление скорости

hanzohasani

Известный
Автор темы
124
38
Версия MoonLoader
.026-beta
1:
local sampev = require('lib.samp.events')
local speedV = 1 -- скорость в машине(похуй)

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 2)
            return data
        end
    end
end
есть такой код, и я не пойму как мне с каждой секундой добавлять к скорости допустим 0.1
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,981
2,196
Где нибудь в main
Lua:
local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
local speed = getCarSpeed(vehicle)
speed = speed + 0.1
setCarForwardSpeed(vehicle, speed)
wait(1000)

Пример:
Lua:
function main()
    while true do
         if isKeyDown(0xA4) then -- если зажат альт, то
            local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
            local speed = getCarSpeed(vehicle)
            speed = speed + 5
            setCarForwardSpeed(vehicle, speed)
        end
        wait(0)
    end
end
 

hanzohasani

Известный
Автор темы
124
38
Где нибудь в main
Код:
local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
local speed = getCarSpeed(vehicle)
speed = speed + 0.1
setCarForwardSpeed(vehicle, speed)
wait(1000)

Пример:
Код:
function main()
    while true do
         if isKeyDown(0xA4) then -- если зажат альт, то
            local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
            local speed = getCarSpeed(vehicle)
            speed = speed + 5
            setCarForwardSpeed(vehicle, speed)
        end
        wait(0)
    end
end
[ML] (error) Ãàñòàðáàéòåð.lua: opcode '02E3' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarSpeed'
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:9: in function <F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:4
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,981
2,196
[ML] (error) Ãàñòàðáàéòåð.lua: opcode '02E3' call caused an unhandled exception
stack traceback:
[C]: in function 'getCarSpeed'
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:9: in function <F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:4
скинь весь код куда ты его запихал
 

hanzohasani

Известный
Автор темы
124
38
скинь весь код куда ты его запихал
1:
local sampev = require('lib.samp.events')
local speedV = 1 -- скорость в машине

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
    local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
local speed = getCarSpeed(vehicle)
speed = speed + 0.1
setCarForwardSpeed(vehicle, speed)
wait(1000)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 1)
            return data
        end
    end
end
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,981
2,196
1:
local sampev = require('lib.samp.events')
local speedV = 1 -- скорость в машине

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
    local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
local speed = getCarSpeed(vehicle)
speed = speed + 0.1
setCarForwardSpeed(vehicle, speed)
wait(1000)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 1)
            return data
        end
    end
end
Попробуй так, по умолчанию не работает, после ввода команды активируется
Lua:
require 'lib.moonloader'
local on = false

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
    while true do -- когда истина, то повторяется
        if on then -- если команда активирована, то
            local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
            local speed = getCarSpeed(vehicle)
            speed = speed + 0.1
            setCarForwardSpeed(vehicle, speed)
            wait(1000)
        end
    wait(0)
    end
end
 

hanzohasani

Известный
Автор темы
124
38
Попробуй так, по умолчанию не работает, после ввода команды активируется
Lua:
require 'lib.moonloader'
local on = false

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage( on and "Активирован" or 'Деактивирован', -1) end)
    while true do -- когда истина, то повторяется
        if on then -- если команда активирована, то
            local vehicle = storeCarCharIsInNoSave(PLAYER_PED)
            local speed = getCarSpeed(vehicle)
            speed = speed + 0.1
            setCarForwardSpeed(vehicle, speed)
            wait(1000)
        end
    wait(0)
    end
end
бляяя, я оговорился, нужно чтоб не скорость добавлялась, а синхра скорости отправлялась на серв с добавлением
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,981
2,196
бляяя, я оговорился, нужно чтоб не скорость добавлялась, а синхра скорости отправлялась на серв с добавлением
это я не умею Т-Т, но вот похожий вопрос, мб тебе полезно будет
 

whyega52

Eblang головного мозга
Модератор
2,873
2,853
1:
local sampev = require('lib.samp.events')
local speedV = 1 -- скорость в машине(похуй)

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 2)
            return data
        end
    end
end
есть такой код, и я не пойму как мне с каждой секундой добавлять к скорости допустим 0.1
Через for делай перечисление от 1 допустим до 10
Lua:
for speed = 1, 10 do
    data.moveSpeed = {0, 0, speed}
    wait(1000)
end
 

hanzohasani

Известный
Автор темы
124
38
Через for делай перечисление от 1 допустим до 10
Lua:
for speed = 1, 10 do
    data.moveSpeed = {0, 0, speed}
    wait(1000)
end
[ML] (error) Ãàñòàðáàéòåð.lua: F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:22: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:22: in function 'callback'
 

whyega52

Eblang головного мозга
Модератор
2,873
2,853
В хук поток добавь
[ML] (error) Ãàñòàðáàéòåð.lua: F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:22: attempt to yield across C-call boundary
stack traceback:
[C]: in function 'wait'
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:22: in function 'callback'
 

hanzohasani

Известный
Автор темы
124
38
Код:
local sampev = require('lib.samp.events')
local speedV = 0.5 -- скорость в машине

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(50) end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    lua_thread.create(function()
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 1)
            return data
        end
    end
end)
end
мне нужно просто чтоб фейк скорость с каждой секундой увеличивалась на 0.1
 

whyega52

Eblang головного мозга
Модератор
2,873
2,853
я так понимаю, ты делаешь что-то типа рванки, так что
Код:
local sampev = require('lib.samp.events')
local speedV = 0.5 -- скорость в машине

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(50) end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
  end

function sampev.onSendVehicleSync(data)
    lua_thread.create(function()
    if on then
        local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
        if _ then
            local heading = getCarHeading(veh)
            data.moveSpeed = getMoveSpeed(heading, 1)
            return data
        end
    end
end)
end
мне нужно просто чтоб фейк скорость с каждой секундой увеличивалась на 0.1

тут мне кажется лучше не хукать, а отправлять синхру

Lua:
function main()
    while not isSampAvailable() do wait(50) end

    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
    while true do wait(0)
        if on then
            if isCharInAnyCar(PLAYER_PED) then
                local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
                if _ then
                    for speed = 1, 10, 0.1 do
                        local heading = getCarHeading(veh)
                        local data = samp_create_sync_data("vehicle")
                        data.moveSpeed = getMoveSpeed(heading, speed)
                        data.send()
                        wait(1000)
                    end
                end
            end
        end
    end
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
end

function samp_create_sync_data(sync_type, copy_from_player)
    local ffi = require 'ffi'
    local sampfuncs = require 'sampfuncs'
    local raknet = require 'samp.raknet'
    require 'samp.synchronization'
    copy_from_player = copy_from_player or true
    local sync_traits = {
        player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
        vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
        passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
        aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
        trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
        unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
        bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
        spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
    }
    local sync_info = sync_traits[sync_type]
    local data_type = 'struct ' .. sync_info[1]
    local data = ffi.new(data_type, {})
    local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
    if copy_from_player then
        local copy_func = sync_info[3]
        if copy_func then
            local _, player_id
            if copy_from_player == true then
                _, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
            else
                player_id = tonumber(copy_from_player)
            end
            copy_func(player_id, raw_data_ptr)
        end
    end
    local func_send = function()
        local bs = raknetNewBitStream()
        raknetBitStreamWriteInt8(bs, sync_info[2])
        raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
        raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
        raknetDeleteBitStream(bs)
    end
    local mt = {
        __index = function(t, index)
            return data[index]
        end,
        __newindex = function(t, index, value)
            data[index] = value
        end
    }
    return setmetatable({send = func_send}, mt)
end
 

hanzohasani

Известный
Автор темы
124
38
я так понимаю, ты делаешь что-то типа рванки, так что


тут мне кажется лучше не хукать, а отправлять синхру

Lua:
function main()
    while not isSampAvailable() do wait(50) end

    sampRegisterChatCommand('son', function() on = not on sampAddChatMessage(on and "Активирован" or 'Деактивирован', -1) end)
    while true do wait(0)
        if on then
            if isCharInAnyCar(PLAYER_PED) then
                local _, veh = sampGetCarHandleBySampVehicleId(data.vehicleId)
                if _ then
                    for speed = 1, 10, 0.1 do
                        local heading = getCarHeading(veh)
                        local data = samp_create_sync_data("vehicle")
                        data.moveSpeed = getMoveSpeed(heading, speed)
                        data.send()
                        wait(1000)
                    end
                end
            end
        end
    end
end

function getMoveSpeed(heading, speed)
    moveSpeed = {x = math.sin(-math.rad(heading)) * (speed), y = math.cos(-math.rad(heading)) * (speed), z = 0.25}
    return moveSpeed
end

function samp_create_sync_data(sync_type, copy_from_player)
    local ffi = require 'ffi'
    local sampfuncs = require 'sampfuncs'
    local raknet = require 'samp.raknet'
    require 'samp.synchronization'
    copy_from_player = copy_from_player or true
    local sync_traits = {
        player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
        vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
        passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
        aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
        trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
        unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
        bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
        spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
    }
    local sync_info = sync_traits[sync_type]
    local data_type = 'struct ' .. sync_info[1]
    local data = ffi.new(data_type, {})
    local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
    if copy_from_player then
        local copy_func = sync_info[3]
        if copy_func then
            local _, player_id
            if copy_from_player == true then
                _, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
            else
                player_id = tonumber(copy_from_player)
            end
            copy_func(player_id, raw_data_ptr)
        end
    end
    local func_send = function()
        local bs = raknetNewBitStream()
        raknetBitStreamWriteInt8(bs, sync_info[2])
        raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
        raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
        raknetDeleteBitStream(bs)
    end
    local mt = {
        __index = function(t, index)
            return data[index]
        end,
        __newindex = function(t, index, value)
            data[index] = value
        end
    }
    return setmetatable({send = func_send}, mt)
end
[ML] (error) Ãàñòàðáàéòåð.lua: F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:10: attempt to index global 'data' (a nil value)
stack traceback:
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua: in function <F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:3>
[ML] (error) Ãàñòàðáàéòåð.lua: Script died due to an error. (0F6BC864)
 

whyega52

Eblang головного мозга
Модератор
2,873
2,853
[ML] (error) Ãàñòàðáàéòåð.lua: F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:10: attempt to index global 'data' (a nil value)
stack traceback:
F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua: in function <F:\Games\GTA 140K BY DAPO SHOW\moonloader\Ãàñòàðáàéòåð.lua:3>
[ML] (error) Ãàñòàðáàéòåð.lua: Script died due to an error. (0F6BC864)
скинь свой код весь