Отрефактори код - --- Main function main() if not isSampLoaded() or not isCleoLoaded()…
- User
Отрефактори код -
--- Main function main() if not isSampLoaded() or not isCleoLoaded() or not isSampfuncsLoaded() then return end while not isSampAvailable() do wait(100) end sampRegisterChatCommand("c2c", attach) while true do wait(0)
codeendend
function attach(id) -- local h1 = select(2, sampGetCarHandleBySampVehicleId(7)) -- local h2 = select(2, sampGetCarHandleBySampVehicleId(81)) -- local toCar1 = getCarPointer(h1) -- local toCar2 = getCarPointer(h2) -- attachCharToCar(playerPed, h1, 3, 2, 0, 1, 360, 31) -- detachCharFromCar(playerPed) -- --attachCarToCar(h1, h2, 0.0, -5.0, 1.65, 1.0, 1.0, 1.0) -- -- print(attachCarToCar(toCar1, toCar2, 0.0, -1.6, 0.65, 1.0, 1.0, 1.0)) -- -- print(h1) -- -- print(toCar1) -- --print(isVehicleAttached(toCar2)) -- isActive = not isActive local h1 = select(2, sampGetCarHandleBySampVehicleId(id)) local cX, cY, cZ = getCharCoordinates(playerPed) local vX, vY, vZ = getCarCoordinates(h1) local oX = cX-vX local oY = cY-vY local oZ = vZ-vZ attachCharToCar(playerPed, h1, rotatedVector.x, rotatedVector.y, rotatedVector.z, 1, 360, 31) -- float offsetX, float offsetY, float offsetZ, int position, float shootingAngleLimit, int weapon end
function rotateVectorByQuaternion(vector, quaternion) local qx = quaternion[1] local qy = quaternion[2] local qz = quaternion[3] local qw = quaternion[4]
codelocal uv = { x = qy * vector.z - qz * vector.y, y = qz * vector.x - qx * vector.z, z = qx * vector.y - qy * vector.x } local uuv = { x = qy * uv.z - qz * uv.y, y = qz * uv.x - qx * uv.z, z = qx * uv.y - qy * uv.x } local rotatedVector = { x = vector.x + 2 * (qw * uv.x + uuv.x), y = vector.y + 2 * (qw * uv.y + uuv.y), z = vector.z + 2 * (qw * uv.z + uuv.z) } return rotatedVectorend
- Assistant
Вот отрефакторенный код с улучшенной читаемостью и оптимизацией:
lua