Jump to content

[HELP] Error in Object Preview!


Vazern

Recommended Posts

Hello guys!
I'm having a little problem, I'm a beginner in scripting and I was using the Object_Preview resource in a script, and I saw an example of it in GUI, but I do not know how to do it in Dx.

 

GUI EXAMPLE: 

https://wiki.multitheftauto.com/wiki/Resource:Object_preview

 

Code:

local dxfont0_fonte = dxCreateFont("font/fonte.ttf", 10)

local myObject,myElement = nil, nil

local screenW, screenH = guiGetScreenSize()
local resW, resH = 1360,768
local x, y = (screenW/resW), (screenH/resH)

function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
	if 
		type( sEventName ) == 'string' and 
		isElement( pElementAttachedTo ) and 
		type( func ) == 'function' 
	then
		local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
		if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
			for i, v in ipairs( aAttachedFunctions ) do
				if v == func then
					return true
				end
			end
		end
	end

	return false
end




function menu()



    color = tocolor(0, 0, 0, 185)
    if isCursorOnElement(screenW * 0.3294, screenH * 0.3307, screenW * 0.3360, screenH * 0.0495) then --  M4
    	--exports.preview:setPositionOffsets(m4view,0,1.5,0.1)
    	--exports.preview:setRotation(m4view, getTickCount()/10, 0, 0)
        color = tocolor(16, 102, 231, 100)
    end

    color2 = tocolor(0, 0, 0, 185)
    if isCursorOnElement(screenW * 0.3294, screenH * 0.3802, screenW * 0.3360, screenH * 0.0495) then --  Desert
        color2 = tocolor(16, 102, 231, 100)
    end

    color3 = tocolor(0, 0, 0, 185)
    if isCursorOnElement(screenW * 0.3294, screenH * 0.4297, screenW * 0.3360, screenH * 0.0495) then --  Cacetete 
        color3 = tocolor(16, 102, 231, 100)
    end

    color4 = tocolor(0, 0, 0, 185)
    if isCursorOnElement(screenW * 0.3294, screenH * 0.4792, screenW * 0.3360, screenH * 0.0495) then --  Vida e colete
        color4 = tocolor(16, 102, 231, 100)
    end

    colorF = tocolor(0, 0, 0, 0)
    if isCursorOnElement(screenW * 0.6544, screenH * 0.2656, screenW * 0.0228, screenH * 0.0469) then 
        colorF = tocolor(255, 0, 0, 150)
    end

    myElement = createObject(356,0,0,0)
    myObject = exports.preview:createObjectPreview(myElement,0,0,1,1,1,1, true, true, true)   

        dxDrawRectangle(screenW * 0.3221, screenH * 0.2656, screenW * 0.3551, screenH * 0.4844, tocolor(0, 0, 0, 185), false)
        dxDrawRectangle(screenW * 0.3221, screenH * 0.2656, screenW * 0.3551, screenH * 0.0469, tocolor(0, 0, 0, 185), false)
        dxDrawText("Menu de itens - #1066E7PMESP", screenW * 0.3294, screenH * 0.2786, screenW * 0.4971, screenH * 0.3242, tocolor(255, 255, 255, 200), x*1.00, dxfont0_fonte, "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.6544, screenH * 0.2656, screenW * 0.0228, screenH * 0.0469, colorF, false)
        dxDrawText("X", screenW * 0.6618, screenH * 0.2786, screenW * 0.8294, screenH * 0.3242, tocolor(255, 255, 255, 200), x*1.30, "default-bold", "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.3294, screenH * 0.3307, screenW * 0.3360, screenH * 0.0495, color, false)
        dxDrawText("(#1066E7Armamento#FFFFFF) M4", screenW * 0.3368, screenH * 0.3438, screenW * 0.5044, screenH * 0.3893, tocolor(255, 255, 255, 200), x*1.00, dxfont0_fonte, "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.3294, screenH * 0.3802, screenW * 0.3360, screenH * 0.0495, color2, false)
        dxDrawText("(#1066E7Armamento#FFFFFF) Desert Eagle", screenW * 0.3368, screenH * 0.3932, screenW * 0.5044, screenH * 0.4388, tocolor(255, 255, 255, 200), x*1.00, dxfont0_fonte, "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.3294, screenH * 0.4297, screenW * 0.3360, screenH * 0.0495, color3, false)
        dxDrawText("(#1066E7Armamento#FFFFFF) Cacetete", screenW * 0.3368, screenH * 0.4427, screenW * 0.5044, screenH * 0.4883, tocolor(255, 255, 255, 200), x*1.00, dxfont0_fonte, "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.3294, screenH * 0.4792, screenW * 0.3360, screenH * 0.0495, color4, false)
        dxDrawText("Vida e Colete", screenW * 0.3368, screenH * 0.4922, screenW * 0.5044, screenH * 0.5378, tocolor(255, 255, 255, 200), x*1.00, dxfont0_fonte, "left", "top", false, false, false, true, false)
        dxDrawRectangle(screenW * 0.3294, screenH * 0.5612, screenW * 0.3360, screenH * 0.1615, tocolor(0, 0, 0, 185), false)
        


end

function render()
	if not isEventHandlerAdded("onClientRender", root, menu) then
	    addEventHandler("onClientRender", root, menu)
	    showCursor(true)
	    showChat(false)
	   -- l_0_1 = true
	end
end
addEvent("openMenuPM", true)
addEventHandler("openMenuPM", root, render)


function close(_,state)
    if isEventHandlerAdded("onClientRender", root, menu) then  
        if state == "down" then
            if isCursorOnElement(screenW * 0.6544, screenH * 0.2656, screenW * 0.0228, screenH * 0.0469) then 
		        showCursor(false)
                showChat(true)
                playSound("sfx/hit.mp3", false)
                removeEventHandler("onClientRender", root, menu)
                if l_0_1 then
                    l_0_1 = false
                end
            end
        end
    end
end
addEventHandler("onClientClick", root, close)


function m4(_,state)
    if isEventHandlerAdded("onClientRender", root, menu) then  
        if state == "down" then
            if isCursorOnElement(screenW * 0.3294, screenH * 0.3307, screenW * 0.3360, screenH * 0.0495) then
                triggerServerEvent("m4", localPlayer)
                removeEventHandler("onClientRender", root, menu)
                showChat(true)
                showCursor(false)
                playSound("sfx/hit.mp3", false) 
                if l_0_1 then
                    l_0_1 = false
                end
            end
        end
    end
end
addEventHandler("onClientClick", root, m4)



function isCursorOnElement( posX, posY, width, height )
  if isCursorShowing( ) then
    local mouseX, mouseY = getCursorPosition( )
    local clientW, clientH = guiGetScreenSize( )
    local mouseX, mouseY = mouseX * clientW, mouseY * clientH
    if ( mouseX > posX and mouseX < ( posX + width ) and mouseY > posY and mouseY < ( posY + height ) ) then
      return true
    end
  end
  return false
end

 

 

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...