Jump to content

Crosshair bug


-Doc-

Recommended Posts

Posted

You want these direct x lines show in the screen when you press a "button"?

You didnt explain well what you wanted to do,so it will be easy to help after understanding your point.

Posted
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) 

Posted

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) 

My scripting skills

 


76561198189590622.pngAddFriend.png

Posted (edited)

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
Posted
  
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 
) 
  

Currently developing for International Gaming Community - Join us!

  • Moderators
Posted

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 
) 

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

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Or at least say what debug outputs

If you're looking for a cheap paid scripter, don't hesitate to contact me.

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

Posted

You're asking help on a public forum made for its members, And if you want a specific person to do it for you, Contact him/them in private and not post here your topic and then ask us to leave.

I'm reporting this

If you're looking for a cheap paid scripter, don't hesitate to contact me.

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

  • Moderators
Posted

Blue, I just gave you code to debug your code. What is the result?

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

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
No errors nothing

Stupid answer, bye.

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

 

  Useful functions  3x 

  Tutorials  4x 

 

  • Moderators
Posted
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.

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

 

  Useful functions  3x 

  Tutorials  4x 

 

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