Jump to content

dxDrawImage bad argument


adithegman

Recommended Posts

Hey guys, need some help with my code, the script works, but it spams me this warning:

Quote

Bad Argument @ 'dxDrawImage' [Expected vector 2 at argument 1, got boolean]

Code:

function onRender( )
    if isCursorShowing( ) then
        vehicles = getElementsByType( "vehicle" )
        local px, py, pz = getElementPosition( localPlayer )

        for key, vehicle in ipairs(vehicles) do
            local vx, vy, vz = getElementPosition( vehicle )

            local distance = getDistanceBetweenPoints3D ( vx,vy,vz,px,py,pz )
            if distance < 30 then
                local w, h = guiGetScreenSize ()
                local scalex, scaley = w/1920/distance, h/1080/distance
                local x, y = getScreenFromWorldPosition ( vx, vy, vz + 1 ) 
                dxDrawImage ( x, y, 200 * scalex, 200 * scaley, "steering_wheel.png" )
            end
        end
    end
end

addEventHandler( "onClientRender", getRootElement(), onRender )

 

Update!

After a while I got bored and decided to take a ride around LS for some time, and I noticed that when I'm around just one car, it doesn't show me the warning. So i went to the wiki and found out that  getScreenFromWorldPosition returns false if the camera does not see the object. Modified the code and now it works perfectly!

 

local x, y = getScreenFromWorldPosition ( vx, vy, vz + 1 ) 
if x ~= false then
	dxDrawImage ( x, y, 200 * scalex * 4, 200 * scaley * 4, "steering_wheel.png" )
end

 

Edited by adithegman
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...