gpt-4o-2024-05-13· openai
from WildChat-4.8M
почисть и сократи код - function attachCharacterToCar(carID) if not…
- User
почисть и сократи код - function attachCharacterToCar(carID) if not isCharInAnyCar(playerPed) then local result, vehicle = sampGetCarHandleBySampVehicleId(carID) if result then local px, py, pz = getCharCoordinates(playerPed) local vx, vy, vz = getCarCoordinates(vehicle)
codelocal rx, ry, rz, rw = getVehicleQuaternion(vehicle) local vec_player = maf.vector(vx, vy, vz) local vec_vehicle = maf.vector(px, py, pz) local vec_offset = vec_player - vec_vehicle local quat_vehicle = maf.quat(rx, ry, rz, rw) local x, y, z = vec_offset:unpack() print(x, y, z) local quat_negative = -quat_vehicle local a, b, c, d = quat_negative:unpack() print(a, b, c, d) local ax, ay, az = rotate_vector_on_quaternion(x, y, z, a, b, c, d) local slot = getCurrentCharWeapon(playerPed) -- 31 --getPlayerWeaponSlot(player) sampAddChatMessage("gluing player to " .. getNameOfVehicleModel(getCarModel(vehicle)) .. "(offset: "..tostring(ax)..","..tostring(ay)..","..tostring(az), -1) -- attachCharToCar(Ped ped, Vehicle car, float offsetX, float offsetY, float offsetZ, int position, float shootingAngleLimit, int weapon) attachCharToCar(playerPed, vehicle, ax*-1, ay*-1, az*-1, 1 --[[position]], 360 --[[shootingAngleLimit]], slot --[[weapon]]) --triggerServerEvent("gluePlayer", player, slot, vehicle, x, y, z, rotX, rotY, rotZ) -- unbindKey("x","down",glue) -- bindKey("x","down",unglue) -- bindKey("jump","down",unglue) end endend
- Assistant
Чтобы почистить и сократить ваш код, я оставлю только необходимое, уберу лишние комментарии и оптимизирую выражения, где это возможно.
luafunction attachCharacterToCar(carID) if not isCharInAnyCar(playerPed) then local result, vehicle = sampGetCarHandleBySampVehicleId(carID) if result then local px, py, pz = getCharCoordinates(playerPed) local vx, vy, vz = getCarCoordinates(vehicle) local rx, ry, rz, rw = getVehicleQuaternion(vehicle) local vec_offset = maf.vector(vx, vy, vz) - maf.vector(px, py, pz) local quat_vehicle = maf.quat(rx, ry, rz, rw) local quat_negative = -quat_vehicle local ax, ay, az = rotate_vector_on_quaternion(vec_offset:unpack(), quat_negative:unpack()) local slot = getCurrentCharWeapon(playerPed) sampAddChatMessage("Gluing player to " .. getNameOfVehicleModel(getCarModel(vehicle)) .. "(offset: " .. ax .. "," .. ay .. "," .. az .. ")", -1) attachCharToCar(playerPed, vehicle, -ax, -ay, -az, 1, 360, slot) end end end