Jump to content

Object Preview - Showing Player Skin and vehicle


Recommended Posts

Hi people,

I was trying to understand Object Preview resource, but I don't get how to listen to skin changes so it updates the preview

Also, given the same, I need to know when a player is in a car, and render that car. For the moment I have this, it renders the player skin:
 

local scx, scy = guiGetScreenSize ()
local myObject,myElement, guiWindow = nil, nil, nil
local myRotation = {180,180,0}

function showPlayerSkin()
	local x1, y1, z1 = getCameraMatrix()
	--myElement = createVehicle(429, x1, y1, z1)
	myElement = createPed(getElementModel(getLocalPlayer()),x1,y1,z1)
	--myElement = createObject(356,0,0,0)
	myObject = 	exports.object_preview:createObjectPreview(myElement,0,0,0,1,1,1,1,true,true,false)
	guiWindow = guiCreateWindow((scx/2)-100,(scy/2) - 100,200,200,"Test area",false,false)
	guiSetAlpha(guiWindow, 0.05)
	local projPosX, projPosY = guiGetPosition(guiWindow,true)
	local projSizeX, projSizeY = guiGetSize(guiWindow, true)
end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), showPlayerSkin())

addEventHandler("onClientPreRender", root, function()
	if not myElement or not myObject then return end
	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, true, "high" )

addEventHandler("onClientResourceStop", getResourceRootElement( getThisResource()), function()
	exports.object_preview:destroyObjectPreview(myObject)
end
)

Also it would be nice to know how to remove these render shadows, and to have them not affected by world light

Link to comment
local scx, scy = guiGetScreenSize()
local myObject, myElement, guiWindow = nil, nil, nil
local myRotation = {180, 180, 0}

function showPlayerSkin()
    local x1, y1, z1 = getCameraMatrix()
    myElement = createPed(getElementModel(getLocalPlayer()), x1, y1, z1)
    myObject = exports.object_preview:createObjectPreview(myElement, 0, 0, 0, 1, 1, 1, 1, true, true, false)
    guiWindow = guiCreateWindow((scx / 2) - 100, (scy / 2) - 100, 200, 200, "Test area", false, false)
    guiSetAlpha(guiWindow, 0.05)
end

function updatePlayerSkin()
    if isElement(myElement) then
        destroyElement(myElement)
    end
    local x1, y1, z1 = getCameraMatrix()
    myElement = createPed(getElementModel(getLocalPlayer()), x1, y1, z1)
    exports.object_preview:setObjectElement(myObject, myElement)
end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), showPlayerSkin)

addEventHandler("onClientElementModelChange", root, function(changedElement)
    if changedElement == getLocalPlayer() then
        updatePlayerSkin()
    end
end)

addEventHandler("onClientVehicleEnter", root, function(vehicle, seat)
    if source == getLocalPlayer() and seat == 0 then
        if isElement(myElement) then
            destroyElement(myElement)
        end
        local x1, y1, z1 = getCameraMatrix()
        myElement = createVehicle(getElementModel(vehicle), x1, y1, z1)
        exports.object_preview:setObjectElement(myObject, myElement)
    end
end)

addEventHandler("onClientVehicleExit", root, function(vehicle, seat)
    if source == getLocalPlayer() and seat == 0 then
        updatePlayerSkin()
    end
end)

addEventHandler("onClientPreRender", root, function()
    if not myElement or not myObject then return end
    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, true, "high")

addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), function()
    exports.object_preview:destroyObjectPreview(myObject)
end)

 

  • Like 1
Link to comment
On 21/05/2024 at 01:25, P[ow]er said:
local scx, scy = guiGetScreenSize()
local myObject, myElement, guiWindow = nil, nil, nil
local myRotation = {180, 180, 0}

function showPlayerSkin()
    local x1, y1, z1 = getCameraMatrix()
    myElement = createPed(getElementModel(getLocalPlayer()), x1, y1, z1)
    myObject = exports.object_preview:createObjectPreview(myElement, 0, 0, 0, 1, 1, 1, 1, true, true, false)
    guiWindow = guiCreateWindow((scx / 2) - 100, (scy / 2) - 100, 200, 200, "Test area", false, false)
    guiSetAlpha(guiWindow, 0.05)
end

function updatePlayerSkin()
    if isElement(myElement) then
        destroyElement(myElement)
    end
    local x1, y1, z1 = getCameraMatrix()
    myElement = createPed(getElementModel(getLocalPlayer()), x1, y1, z1)
    exports.object_preview:setObjectElement(myObject, myElement)
end

addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), showPlayerSkin)

addEventHandler("onClientElementModelChange", root, function(changedElement)
    if changedElement == getLocalPlayer() then
        updatePlayerSkin()
    end
end)

addEventHandler("onClientVehicleEnter", root, function(vehicle, seat)
    if source == getLocalPlayer() and seat == 0 then
        if isElement(myElement) then
            destroyElement(myElement)
        end
        local x1, y1, z1 = getCameraMatrix()
        myElement = createVehicle(getElementModel(vehicle), x1, y1, z1)
        exports.object_preview:setObjectElement(myObject, myElement)
    end
end)

addEventHandler("onClientVehicleExit", root, function(vehicle, seat)
    if source == getLocalPlayer() and seat == 0 then
        updatePlayerSkin()
    end
end)

addEventHandler("onClientPreRender", root, function()
    if not myElement or not myObject then return end
    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, true, "high")

addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), function()
    exports.object_preview:destroyObjectPreview(myObject)
end)

 

The GUI functions are client sided, so I cannot manage to start this

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...