Lua Car Ring

Статус
В этой теме нельзя размещать новые ответы.

MelomanCool

Новичок
Автор темы
Проверенный
65
41
Car Ring

Скрипт делает кольцо из машин в прорисовке. В качестве синхронизации используется unoccupied sync, так что на популярных RP-серверах, скорее всего, работать не будет.

Для работы необходим MoonLoader.

Активация: /ring в чат

Lua:
script_name("Car Ring")
script_version("1.0")
script_version_number(1)
script_author("MelomanCool")
script_description("Creates car ring")

require "lib.moonloader"

--[[ config ]]--
CAR_INTERVAL = 4.0


function main()
  sampRegisterChatCommand("ring", carRing)
  wait(-1)
end

function carRing()
  local cars = getCars()
  if not cars then return end
  local centerX, centerY, centerZ = getCharCoordinates(playerPed)
  local radius = getRadius(#cars)

  for j = 1, #cars do
    local circleX, circleY, angle = getCirclePointXY(j, #cars, radius)
    local posX = centerX + circleX
    local posY = centerY + circleY
    local posZ = centerZ
    setCarCoordinatesNoOffset(cars[j], posX, posY, posZ)
    setCarHeading(cars[j], math.deg(angle) + 90.0)
    exists, carId = sampGetVehicleIdByCarHandle(cars[j])
    if exists then
      sampForceUnoccupiedSyncSeatId(carId, 0)
    end
  end
end

function getCars()
  local exists
  local cars = {}

  local centerX, centerY, centerZ = getCharCoordinates(playerPed)
  exists, cars[1] = findAllRandomVehiclesInSphere(centerX, centerY, centerZ,
    --[[radius]] 500.0, --[[findNext]] false, --[[passWrecked]] true)
  if not exists then return end

  local j = 2
  while true do
    exists, currentCar = findAllRandomVehiclesInSphere(centerX, centerY, centerZ,
      --[[radius]] 500.0, --[[findNext]] true, --[[passWrecked]] true)
    if not exists then break end
    cars[j] = currentCar
    j = j+1
  end

  return cars
end

function getRadius(numOfCars)
  local radius
  if numOfCars >= 20 then
    radius = numOfCars * CAR_INTERVAL/(2*math.pi)
  else
    if numOfCars < 4 then return end
    radius = 20 * CAR_INTERVAL/(2*math.pi)
  end
  return radius
end

function getCirclePointXY(pointNumber, numberOfPoints, radius)
  local X, Y, angle
  angle = pointNumber/numberOfPoints * 2*math.pi
  X = radius * math.cos(angle)
  Y = radius * math.sin(angle)
  return X, Y, angle
end
P.S. Скрипт отчасти повторяет функции скрипта Circle от @Opcode.eXe. Писал, в общем-то, тестируя возможности языка и MoonLoader'а.
 

Вложения

  • Car Ring.lua
    2 KB · Просмотры: 137
Последнее редактирование:

WhyExtern

Участник
73
12
Car Ring

Скрипт делает кольцо из машин в прорисовке. В качестве синхронизации используется unoccupied sync, так что на популярных RP-серверах, скорее всего, работать не будет.

Для работы необходим MoonLoader.

Активация: /ring в чат

Lua:
script_name("Car Ring")
script_version("1.0")
script_version_number(1)
script_author("MelomanCool")
script_description("Creates car ring")

require "lib.moonloader"

--[[ config ]]--
CAR_INTERVAL = 4.0


function main()
  sampRegisterChatCommand("ring", carRing)
  wait(-1)
end

function carRing()
  local cars = getCars()
  if not cars then return end
  local centerX, centerY, centerZ = getCharCoordinates(playerPed)
  local radius = getRadius(#cars)

  for j = 1, #cars do
    local circleX, circleY, angle = getCirclePointXY(j, #cars, radius)
    local posX = centerX + circleX
    local posY = centerY + circleY
    local posZ = centerZ
    setCarCoordinatesNoOffset(cars[j], posX, posY, posZ)
    setCarHeading(cars[j], math.deg(angle) + 90.0)
    exists, carId = sampGetVehicleIdByCarHandle(cars[j])
    if exists then
      sampForceUnoccupiedSyncSeatId(carId, 0)
    end
  end
end

function getCars()
  local exists
  local cars = {}

  local centerX, centerY, centerZ = getCharCoordinates(playerPed)
  exists, cars[1] = findAllRandomVehiclesInSphere(centerX, centerY, centerZ,
    --[[radius]] 500.0, --[[findNext]] false, --[[passWrecked]] true)
  if not exists then return end

  local j = 2
  while true do
    exists, currentCar = findAllRandomVehiclesInSphere(centerX, centerY, centerZ,
      --[[radius]] 500.0, --[[findNext]] true, --[[passWrecked]] true)
    if not exists then break end
    cars[j] = currentCar
    j = j+1
  end

  return cars
end

function getRadius(numOfCars)
  local radius
  if numOfCars >= 20 then
    radius = numOfCars * CAR_INTERVAL/(2*math.pi)
  else
    if numOfCars < 4 then return end
    radius = 20 * CAR_INTERVAL/(2*math.pi)
  end
  return radius
end

function getCirclePointXY(pointNumber, numberOfPoints, radius)
  local X, Y, angle
  angle = pointNumber/numberOfPoints * 2*math.pi
  X = radius * math.cos(angle)
  Y = radius * math.sin(angle)
  return X, Y, angle
end
P.S. Скрипт отчасти повторяет функции скрипта Circle от @Opcode.eXe. Писал, в общем-то, тестируя возможности языка и MoonLoader'а.
Эм а для чего он пригодиться?
 
Статус
В этой теме нельзя размещать новые ответы.