Jump to content

Laser


DarkByte

Recommended Posts

Posted

One last thing. When laser and image is aiming on a vehicle or a enemy to be red. Can you help me?

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

  • Moderators
Posted

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) 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Yea its workin', but when player is aiming in his team mate laser turns in red but i don't need that

When I hear someone saying Mac is better than PC.

o0pjNKG.gif w0t?VeJXjxD.gifw0t? evspcFJ.gifw0t?

Great minds discuss ideas, average minds discuss events and small minds discuss people.

  • Moderators
Posted

That is not so hard, you can do that by yourself.

getPlayerTeam 

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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