Jump to content

Crosshair bug


-Doc-

Recommended Posts

OMG Do u saw handler? when i enter hydra to show the crosshair

Ah sorry i didnt take attention

try this

function crosshair () 
if getPedOccupiedVehicle(localPlayer) then  
        if getElementModel(getPedOccupiedVehicle(localPlayer)) == 520 then  
            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 
end 
    addEventHandler("onClientRender", root, crosshair) 

Link to comment

Rechange the script

function crosshair () 
if getPedOccupiedVehicle(localPlayer) then 
        if getElementModel(getPedOccupiedVehicle(localPlayer)) == 520 then 
    --there local veh = getPedOccupiedVehicle(gMe) 
      --there     local col2 = getElementData(veh, "r.col2") 
    --there        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 
end 
    addEventHandler("onClientRender", root, crosshair) 

Link to comment

Your error is about getPedOccupiedVehicle ,if this didnt works inform me to edit my post

function crosshair () 
if getPedOccupiedVehicle(localPlayer) then 
        if getElementModel(getPedOccupiedVehicle(localPlayer)) == 520 true then 
    --there local veh = getPedOccupiedVehicle(gMe) 
      --there     local col2 = getElementData(veh, "r.col2") 
    --there        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 
end 
    addEventHandler("onClientRender", root, crosshair) 

Edited by Guest
Link to comment
  
addEventHandler("onClientRender", getRootElement(),  
    function ( ) 
        if isPedInVehicle(localPlayer) then 
            if getElementModel( getPedOccupiedVehicle(localPlayer) ) == 520 then 
                local veh = getPedOccupiedVehicle(localPlayer) 
                    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 
    end 
) 
  

Link to comment
  • Moderators

Why don't you take a look of what really happens?

If you don't know how your code behaves, you will have a hard time fixing it...

addEventHandler("onClientRender", getRootElement(), 
    function ( ) 
        if isPedInVehicle(localPlayer) then 
            if getElementModel( getPedOccupiedVehicle(localPlayer) ) == 520 then 
                local veh = getPedOccupiedVehicle(localPlayer) 
                local col2 = getElementData(veh, "r.col2") 
                local col1 = getElementData(veh, "r.col1") 
                if not isElement(col2) or not isElement(col1) then return end 
                local x, y, z = getElementPosition(col2) 
                local x1, y1, z1 = getElementPosition(col1) 
                -- 
                dxDrawLine3D(x, y, z,x1, y1, z1,tocolor(255, 0, 0)) -- debug line 1 
                -- 
                z1 = z1+getElementDistanceFromCentreOfMassToBaseOfModel(veh)*2 
                -- 
                dxDrawLine3D(x, y, z,x1, y1, z1,tocolor(0, 0, 255)) -- debug line 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 
                -- 
                dxDrawLine3D( x1, y1, z1,x2, y2, z2,tocolor(0, 255, 0)) -- debug line 3 
                -- 
                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 
    end 
) 

Link to comment
  • Moderators
Whats stupid there i said no errorrs, or...

It is stupid, because the code I posted doesn't show any debug text, but 3D lines.

It seems you didn't even looked at it, you are wasting my time.

Link to comment
  • 5 months later...

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