Jump to content

Laser


DarkByte

Recommended Posts

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

  • Moderators

Try this:

local imageLocation = "image.png" 
local imageSizeX,imageSizeY = 100,100 
  
local extendLine = function ( x,y,z,x2,y2,z2,length ) 
    local vx = x2 - x 
    local vy = y2 - y 
    local vz = z2 - z 
    local ratio = length/(getDistanceBetweenPoints3D ( x,y,z,x2,y2,z2 )) 
    vx = vx*ratio 
    vy = vy*ratio 
    vz = vz*ratio 
    return (x + vx),(y + vy),(z + vz) 
end 
local texture = dxCreateTexture(imageLocation,"dxt5") or imageLocation -- createTexture + fallback 
local renderTankLine = function () 
    local theVeh = getPedOccupiedVehicle(localPlayer) 
    if theVeh and getElementModel(theVeh) == 432 then 
        local x,y,z = getVehicleComponentPosition( theVeh, "misc_c","world" ) 
        local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a","world" ) 
        if x and x1 then 
            local endX,endY,endZ = extendLine(x1,y1,z1,x,y,z,10000) 
            local hit,endX2,endY2,endZ2,hitElement = processLineOfSight ( x,y,z,endX,endY,endZ, 
                true, -- checkBuildings 
                true, -- checkVehicles 
                true, -- checkPlayers 
                true, -- checkObjects 
                true, -- checkDummies 
                false, -- seeThroughStuff 
                false, -- ignoreSomeObjectsForCamera 
                false, -- shootThroughStuff 
                theVeh -- ignoredElement 
            ) 
            local laserColor = tocolor(0,255,0,255) 
            if hit then 
                endX,endY,endZ = endX2,endY2,endZ2 
                if hitElement then 
                    local elementType = getElementType(hitElement) 
                    if elementType == "vehicle" or elementType == "ped" then 
                        laserColor = tocolor(255,0,0,255) 
                    end 
                end 
            end 
            local imageCenterX,imageCenterY = getScreenFromWorldPosition (endX,endY,endZ) 
            if imageCenterX and imageCenterY then 
                dxDrawImage(imageCenterX-imageSizeX/2,imageCenterY-imageSizeY/2,imageSizeX,imageSizeY,texture) 
            end 
            dxDrawLine3D (x,y,z,endX,endY,endZ,laserColor,10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 

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