Skream Posted January 29, 2018 Share Posted January 29, 2018 (edited) Is there any better version of object preview? I want to print all skins (I have custom ones) but some of then doesn't render well. I'm using this resource https://wiki.multitheftauto.com/wiki/Resource:Object_preview this is my lua code based on wiki -- -- c_main.lua -- local scx, scy = guiGetScreenSize () local myObject,myElement, guiWindow = nil, nil, nil local myRotation = {0,0,180} local mySkin = 0 addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()), function() outputChatBox('Use num keys to rotate the object') local x1, y1, z1 = getCameraMatrix() myElement = createPed(mySkin, 1760.5491, -1950.9703, 14.1096) myObject = exports.object_preview:createObjectPreview(myElement,0,0,180,1,1,1,1,true,false,true) guiWindow = guiCreateWindow(0, 0,400,400,"Test area",false,false) guiSetAlpha(guiWindow, 0.05 + 0.2) local projPosX, projPosY = guiGetPosition(guiWindow,true) local projSizeX, projSizeY = guiGetSize(guiWindow, true) bindKey ( "p", "down", function() for i = mySkin + 1, 312 do if isValidSkin(i) == 1 then mySkin = i setElementModel(myElement, mySkin) break end end end ) bindKey ( "i", "down", function() setElementModel(myElement, mySkin) end ) bindKey ( "o", "down", function() exports.object_preview:saveRTToFile(myObject, "skins/"..mySkin..".png") end) end) addEventHandler("onClientRender", root, function() if myObject then local projPosX, projPosY = guiGetPosition(guiWindow,true) local projSizeX, projSizeY = guiGetSize(guiWindow, true) exports.object_preview:setRotation(myObject,myRotation[1], myRotation[2], myRotation[3]) exports.object_preview:setProjection(myObject,projPosX, projPosY, projSizeX, projSizeY, true, true) end end) addEventHandler("onClientResourceStop", getResourceRootElement( getThisResource()), function() exports.object_preview:destroyObjectPreview(myObject) end ) function isValidSkin( specifiedSkin ) -- Define the function local result = false -- Define result, it is currently false if ( specifiedSkin ) then -- If skin specified local allSkins = getValidPedModels ( ) -- Get valid skin IDs for key, skin in ipairs( allSkins ) do -- Check all skins if skin == tonumber( specifiedSkin ) then -- If skin equals specified one, it is valid result = 1 -- So set it as result break --stop looping through a table after we found the skin end end end return result end Edited January 29, 2018 by Skream Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now