Untitled conversation
- User
-- Линейная интерполяция function lerp(a, b, t) return a + (b - a) * t end -- Гладкое движение камеры function smoothCameraMovement(targetX, targetY, targetZ, duration) local startTime, camX, camY, camZ = localClock(), getActiveCameraPointAt() repeat local progress = math.min((localClock() - startTime) / duration, 1.0) pointCameraAtPoint(lerp(camX, targetX, progress), lerp(camY, targetY, progress), lerp(camZ, targetZ, progress), 2) wait(0) until progress >= 1.0 end -- Перемещение камеры к цели moveCameraToTarget = function(target, duration) smoothCameraMovement(target.x, target.y, target.z, duration) end -- Проверка на коллизию по линии (Line of sight) function testCollision(fromX, fromY, fromZ, distance) local heading, toX, toY = math.rad(getCharHeading(PLAYER_PED)), fromX + math.sin(heading) * distance, fromY + math.cos(heading) * distance return processLineOfSight(fromX, fromY, fromZ, toX, toY, fromZ, true, true, true, true, false, false, false, false) end -- Передвижение игрока вперед function movePlayerForward(customX, customY, customZ) while true do wait(10) if isCharOnFoot(PLAYER_PED) then local x, y, z = customX or getCharCoordinates(PLAYER_PED) local heading = math.rad(getCharHeading(PLAYER_PED)) local forwardX, forwardY, cameraTarget = x + math.sin(heading) * 3, y + math.cos(heading) * 3, {x = x + math.sin(heading) * 3, y = y + math.cos(heading) * 3, z = z + 2} moveCameraToTarget(cameraTarget, 0.5) testCollision(x, y, z, 3) and setCharHeading(PLAYER_PED, getCharHeading(PLAYER_PED) + 45) or taskGoStraightToCoord(PLAYER_PED, forwardX, forwardY, z, 1, 1) end end end -- Получение ближайшего игрока local function getNearestPlayer() local px, py, pz = getCharCoordinates(PLAYER_PED) local closestPlayer, minDistance = nil, math.huge for i = 0, 1000 do if sampIsPlayerConnected(i) and i ~= sampGetPlayerIdByCharHandle(PLAYER_PED) then local result, x, y, z = sampGetStreamedOutPlayerPos(i) if result then local distance = getDistanceBetweenCoords3d(px, py, pz, x, y, z) closestPlayer, minDistance = (distance < minDistance) and i or closestPlayer, math.min(distance, minDistance) end end end return closestPlayer, minDistance end -- Главная функция function main() while not isSampAvailable() do wait(0) end sampRegisterChatCommand("follow", function() local following = true sampAddChatMessage("Следуем за ближайшим игроком. Чтобы отключиться, используйте /stopfollow.", 0x00FF00) lua_thread.create(function() while following do local nearestPlayerId, distance = getNearestPlayer() if nearestPlayerId and distance < 100 then local result, x, y, z = sampGetStreamedOutPlayerPos(nearestPlayerId) if result then movePlayerForward(x, y, z) end else sampAddChatMessage(nearestPlayerId and "Игрока нет поблизости." or "Слишком далеко.", 0xFF0000) following = false end wait(500) end end) end) sampRegisterChatCommand("stopfollow", function() sampAddChatMessage("Прекращаем следовать.", 0xFF0000) following = false end) while true do wait(0) end end - Assistant
Ваш код имеет синтаксическую ошибку в строке 38, которая связана с логическими операторами
andиor. В Lua логические выражения должны быть частью единого выражения, например, условий ветвления или присваивания переменной значения. Логические операторы не могут использоваться как самостоятельные выражения. - User
Напиши полный код
- Assistant
- User
- Assistant
- User
напиши полный код
- Assistant
- User
- Assistant
- User
Напиши полный код
- Assistant
- User
Warning(s007): Exception 0xE06D7363 at 0x75470F62
- Assistant