Jump to content

Vehicle shot


arciCZ

Recommended Posts

addEventHandler('onClientPlayerWeaponFire',root,function(weapon,ammo,aic,x,y,z,hitElement)
    if hitElement then
        if getElementType(hitElement) == 'vehicle' then
            local components = getVehicleComponents(hitElement)
            for i=1,#components do
                local 2x,2y,2z = getComponentWorldPosition(components[i])
                if x == 2x and y == 2y and z == 2z then
                    return components[i]
                end
            end
        end
    end
end)

function getComponentWorldPosition(vehicle,component)
    local m = getElementMatrix(vehicle)
    local x,y,z = getVehicleComponentPosition(vehicle,component)
    local wX = x*m[1][1]+y*m[2][1]+z*m[3][1]+m[4][1]
    local wY = x*m[1][2]+y*m[2][2]+z*m[3][2]+m[4][2]
    local wY = x*m[1][3]+y*m[2][3]+z*m[3][3]+m[4][3]
    return wX,wY,wZ
end

This only works if you shoot dead center of the component. So you may have to modify it to do what you want. This is as far as I can help. Sorry.

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