scriptname('Display Vehicle Components Example') local mad = require 'MoonAdditions'…
- User
script_name('Display Vehicle Components Example') local mad = require 'MoonAdditions'
local lt = os.time() local vi = 0
function main() while true do wait(0) if isPlayerPlaying(PLAYER_HANDLE) then if isCharInAnyCar(PLAYER_PED) then local car = storeCarCharIsInNoSave(PLAYER_PED) local components = mad.get_all_vehicle_components(car) for i, comp in ipairs(components) do draw_component(comp, i) end end end end end
function draw_component(component, id) local x, y, z = component.matrix.pos:get() local sx, sy = convert3DCoordsToScreen(x, y, z) draw_text(string.format('Component #%d:
y%s', id, component.name), sx, sy, 255, 255, 255) sx = sx + 4 -- draw objects local objs = component:get_objects() for i, obj in ipairs(objs) do local mats = obj:get_materials() sy = sy + 12 draw_text('Object #' .. i .. ' total materials:y' .. #mats, sx, sy, 255, 255, 255) -- draw materials sx = sx + 4 for i, mat in ipairs(mats) do local tex = mat:get_texture() local tex_name = tex and ('b' .. tex.name) or 'hhrno texture' sy = sy + 12 draw_text('Material #' .. i .. ' texture: ' .. tex_name, sx, sy, 255, 255, 255) end sx = sx - 4 end endfunction draw_text(str, x, y, r, g, b) mad.draw_text(str, x, y, mad.font_style.SUBTITLES, 0.3, 0.6, mad.font_align.LEFT, 2000, true, false, r, g, b, 255, 1, 0, 30, 30, 30, 120) end
этот код рендерит текст прямо на компонентнах. перепиши его так, чтобы вместо рендера он сохранял текст с информацией о всех компонентнах в файл.
- Assistant
Конечно, давайте перепишем ваш скрипт так, чтобы он сохранял информацию о компонентах автомобиля в текстовый файл вместо рендера на экран. Также добавим необходимые импорты для работы с файлами.
lua