Jump to content

Laser


DarkByte

Recommended Posts

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

And how to make it thicker?

function renderTankLine() 
    local theVeh = getPedOccupiedVehicle(localPlayer) 
    if theVeh and getElementModel(theVeh) == 432 then 
        local x,y,z = getVehicleComponentPosition( theVeh, "misc_c" ) 
        local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a" ) 
        if x and x1 then 
            local endX,endY,endZ = extendLine(x,y,z,x1,y1,z1,300) 
            dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255)) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 
  
  
 function extendLine ( 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 

Link to comment
  • Moderators
dxDrawLine3D ( float startX, float startY, float startZ, float endX, float endY, float endZ, int color[, int width, bool postGUI ] ) 

dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255)[color=#FF0000],10[/color]) 

dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255),10) 

Link to comment

Not working.

function renderTankLine() 
    local theVeh = getPedOccupiedVehicle(localPlayer) 
    if theVeh and getElementModel(theVeh) == 432 then 
        local x,y,z = getVehicleComponentPosition( theVeh, "misc_c" ) 
        local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a" ) 
        if x and x1 then 
            local endX,endY,endZ = extendLine(x,y,z,x1,y1,z1,300) 
            dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255),10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 
  
  
 function extendLine ( 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 

Link to comment
  • Moderators

Now I tested it my self.

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 renderTankLine = function () 
    local theVeh = getPedOccupiedVehicle(localPlayer) 
    if theVeh and getElementModel(theVeh) == 432 then 
        local x,y,z = getVehicleComponentPosition( theVeh, "misc_c","world" ) -- < problem 
        local x1,y1,z1 = getVehicleComponentPosition( theVeh, "misc_a","world" ) -- < problem 
        if x and x1 then 
            local endX,endY,endZ = extendLine(x1,y1,z1,x,y,z,10000) 
            dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255),10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 

And solved the problem...

Link to comment
  • Moderators

Try this:

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 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  = extendLine(x1,y1,z1,x,y,z,10000) 
            local hit,endX2,endY2,endZ2 = 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 
            ) 
            if hit then 
                endX,endY,endZ = endX2,endY2,endZ2 
            end 
             
            dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255),10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 

Link to comment
  • Moderators

Try this, edit the variables on the top.

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 = createTexture(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 = 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 
            ) 
            if hit then 
                endX,endY,endZ = endX2,endY2,endZ2 
            end 
            local imageCenterX,imageCenterY = getScreenFromWorldPosition (endX,endY,endZ) 
            if imageCenterX and imageCenterY then 
                dxDrawImage(imageCenterX-imageSizeX/2,imageCenterY-imageSizeY/2,imageCenterX,imageCenterY,texture) 
            end 
            dxDrawLine3D (x,y,z,endX,endY,endZ,tocolor(255,0,0,255),10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 

Link to comment
  • Moderators

ah yea, indeed. Here + tested.

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 = 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 
            ) 
            if hit then 
                endX,endY,endZ = endX2,endY2,endZ2 
            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,tocolor(255,0,0,255),10) 
        end 
    end 
end 
addEventHandler("onClientRender",root,renderTankLine) 

Link to comment

One more thing. I got this script on community. Can you help me to draw the lines only when player is in hunter not in every vehicle?

-- Client 
local gMe = getLocalPlayer() 
local cando = true 
local key = "vehicle_fire" 
local waitseconds = 1 
local enabled = true 
  
function renderRocketFX() 
    for index, object in pairs(getElementsByType("object")) do  
        if(getElementData(object, "rocket.state") == true) then 
            local x1, y1, z1 = getElementPosition(object) 
            for i = 1, 5, 1 do 
                fxAddTyreBurst(x1, y1, z1, 0, 0, 0) 
                fxAddPunchImpact(x1, y1, z1, 0, 0, 0) 
            end 
        end 
    end 
end 
addEventHandler("onClientRender", getRootElement(), renderRocketFX) 
addEventHandler("onClientPreRender", getRootElement(), renderRocketFX) 
addEventHandler("onClientRender", getRootElement(), function() 
    if(enabled == true) then 
            local veh = getPedOccupiedVehicle(gMe) 
            if not(veh) then return end 
            local col2 = getElementData(veh, "r.col2") 
            local col1 = getElementData(veh, "r.col1") 
            if not(col2) or not(col1) then return end 
            local x, y, z = getElementPosition(col2) 
            local x1, y1, z1 = getElementPosition(col1) 
            z1 = z1+getElementDistanceFromCentreOfMassToBaseOfModel(veh)*2 
            local hit, x2, y2, z2 = processLineOfSight(x, y, z, x1, y1, z1) 
            if not(x2) or not(y2) or not(z2) then x2, y2, z2 = x, y, z end 
            local sx, sy = getScreenFromWorldPosition(x2, y2, z2) 
            if not(sx) or not(sy) then return end    
            dxDrawLine(sx, sy-12.9, sx, sy+12.9, tocolor(0, 255, 0), 2) 
            dxDrawLine(sx-12.9, sy, sx+12.9, sy, tocolor(0, 255, 0), 2) 
    end 
end) 
addEvent("onClientRocketFire", true) 
addEventHandler("onClientRocketFire", getRootElement(), function(theRocket) 
    local x, y, z = getElementPosition(theRocket) 
    local sound = playSound3D("rocket.mp3", x, y, z, false) 
    setSoundMaxDistance(sound, 100) 
    attachElements(sound, theRocket) 
end) 
  
function fireVehicleRocket() 
    if(cando == false) then return end 
    if(enabled == false) then return end 
    local veh = getPedOccupiedVehicle(gMe) 
    if(veh) then else unbindKey(key, "up", fireVehicleRocket) return end 
    local col1 = getElementData(veh, "r.col1") 
    local col2 = getElementData(veh, "r.col2") 
    local x1, y1, z1 = getElementPosition(col1) 
    local x2, y2, z2 = getElementPosition(col2) 
    z1 = z1+getElementDistanceFromCentreOfMassToBaseOfModel(veh)*2 
    local hit, hx, hy, hz = processLineOfSight(x1, y1, z1, x2, y2, z2) 
    if not(hx) or not(hy) or not(hz) then hx, hy, hz = x2, y2, z2 end 
    local distanz = getDistanceBetweenPoints3D(x1, y1, z1, hx, hy, hz) 
    local time = distanz*10 
    cando = false 
    setTimer(function() cando = true end, waitseconds*1000, 1) 
    triggerServerEvent("onRocketCreation", gMe, x1, y1, z1, hx, hy, hz, time) 
end 
  
addEventHandler("onClientPlayerWasted", gMe, function() 
    unbindKey(key, "up", fireVehicleRocket) 
end) 
  
addEventHandler("onClientVehicleExit", getRootElement(), function(thePlayer) 
    if(thePlayer ~= gMe) then return end 
    unbindKey(key, "up", fireVehicleRocket) 
end) 
  
  
addEventHandler("onClientVehicleEnter", getRootElement(), function(thePlayer) 
    if(thePlayer ~= gMe) then return end 
    bindKey(key, "up", fireVehicleRocket) 
end) 
  
function checkVehicleCol() 
    for index, car in pairs(getElementsByType("vehicle")) do 
        if not(getElementData(car, "r.col1")) then 
            local col1 = createColSphere(0, 0, 0, 2) 
            local col2 = createColSphere(0, 0, 0, 2) 
            setElementData(car, "r.col1", col1, false) 
            setElementData(car, "r.col2", col2, false) 
            attachElements(col1, car) 
            attachElements(col2, car, 0, 250, 0) 
        end 
    end 
end 
setTimer(checkVehicleCol, 1000, 1) 
addEventHandler("onClientResourceStop", getResourceRootElement(getThisResource()), function() 
    for index, car in pairs(getElementsByType("vehicle")) do 
        setElementData(car, "r.col1", nil, false) 
        setElementData(car, "r.col2", nil, false) 
    end 
end) 
addCommandHandler("missiles", function() 
    enabled = not enabled 
    local shit 
    if(enabled == true) then shit = "enabled" else shit = "disabled" end 
    outputChatBox("Missiles have been "..shit..".", 0, 255, 255) 
end) 
    -- PROJECTILE VERSION!  -- 
    --[[ 
    local x1, y1, z1 = getElementPosition(col1) 
    local rx, ry, rz = getElementRotation(veh) 
    local rotX,rotY,rotZ = getElementRotation(veh) 
    local x, y, z = getElementPosition(veh) 
    local matrix = getElementMatrix(veh) 
    local offX = 0 * matrix[1][1] + 1 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] 
    local offY = 0 * matrix[1][2] + 1 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] 
    local offZ = 0 * matrix[1][3] + 1 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] 
    local vx = offX - x 
    local vy = offY - y 
    local vz = offZ - z 
    x = 0 * matrix[1][1] + 3 * matrix[2][1] + 0 * matrix[3][1] + 1 * matrix[4][1] 
    y = 0 * matrix[1][2] + 3 * matrix[2][2] + 0 * matrix[3][2] + 1 * matrix[4][2] 
    z = 0 * matrix[1][3] + 3 * matrix[2][3] + 0 * matrix[3][3] + 1 * matrix[4][3] 
    createProjectile(gMe, 19, x, y, z, 200, nil, 0, 0, 360 - rotZ, vx, vy, vz) 
    --]] 

--Server 
addEvent("onRocketCreation", true) 
addEventHandler("onRocketCreation", getRootElement(), function(x, y, z, hx, hy, hz, time) 
    local car = getPedOccupiedVehicle(source) 
    if not(car) then return end 
    local rx, ry, rz = getElementRotation(car) 
    local object = createObject(3786, x, y, z+0.5, rx*1.01, ry*1.01, rz-90) 
    local marker = createMarker(x, y, z+0.5, "corona", 1.0, 0, 255, 0) 
    triggerClientEvent(getRootElement(), "onClientRocketFire", source, object) 
    setElementData(object, "rocket.state", true) 
    attachElements(marker, object) 
    setElementCollisionsEnabled(object, false) 
    setObjectScale(object, 1) 
    moveObject(object, time, hx, hy, hz, 0, 0, 0, "InQuad") 
    setTimer( function() 
        destroyElement(object) 
        destroyElement(marker) 
        createExplosion(hx, hy, hz, 7) 
        createExplosion(hx, hy, hz+4, 4) 
    end, time, 1) 
end) 

Link to comment
  • Moderators

Syntax

projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, element target = nil, float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) 

projectile createProjectile ( element creator, int weaponType [, float posX, float posY, float posZ, float force = 1.0, [color=#FF0000]element target = nil[/color], float rotX, float rotY, float rotZ, float velX, float velY, float velZ, int model ] ) 

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