Jump to content

function that trigger when colshape hit other colshape


maffius97

Recommended Posts

I have spike stripe script below. All vehicles have sphere (vehCol) attached to vehicle. I want to break all tires in the vehicle when vehCol hit blow or blow2 or blow3 or blow4. How can I do it?

addCommandHandler("sting", 
    function(player) 
        if (player) then 
        local x,y,z = getElementPosition(player) 
        local xr,yr,zr = getElementRotation(player) 
        px, py, pz = getElementPosition(player) 
        prot = getPedRotation(player) 
        local offsetRot = math.rad(prot+90) 
        local vx = px + 5 * math.cos(offsetRot) 
        local vy = py + 5 * math.sin(offsetRot) 
        local vx2 = px + 2 * math.cos(offsetRot) 
        local vy2 = py + 2 * math.sin(offsetRot) 
        local vx3 = px + 3 * math.cos(offsetRot) 
        local vy3 = py + 3 * math.sin(offsetRot) 
        local vx4 = px + 4 * math.cos(offsetRot) 
        local vy4 = py + 4 * math.sin(offsetRot) 
        local vz = pz + 2 
        local vrot = prot+180 
        spike = createObject(2892,vx,vy,z-0.95,0,0,vrot) 
        setObjectScale(spike,0.7) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blow = createColTube (x2, y2, z2-0.25, 0.75,1) 
        local blow2 = createColTube (vx2, vy2, z2-0.25, 0.75,1) 
        local blow3 = createColTube (vx3, vy3, z2-0.25, 0.75,1) 
        local blow4 = createColTube (vx4, vy4, z2-0.25, 0.75,1) 
        addEventHandler("onColShapeHit",blow, wylaczKola) 
        addEventHandler("onColShapeHit",blow2,wylaczKola) 
        addEventHandler("onColShapeHit",blow3,wylaczKola) 
        addEventHandler("onColShapeHit",blow4,wylaczKola) 
    end 
end) 
  
  
function wylaczKola (player) 
    if player and getElementType(player) == "player" then 
        if isPedInVehicle(player) then 
            local pveh = getPedOccupiedVehicle(player)      
            setVehicleWheelStates(pveh,1,1,1,1) 
        end 
    end 
end 

Link to comment

¿Why are you making two posts? Try this:

local spike = { } 
local blows = { } 
  
addCommandHandler("sting", 
    function(player) 
        if (player) then 
        local x,y,z = getElementPosition(player) 
        local xr,yr,zr = getElementRotation(player) 
        px, py, pz = getElementPosition(player) 
        prot = getPedRotation(player) 
        local offsetRot = math.rad(prot+90) 
        local vx = px + 5 * math.cos(offsetRot) 
        local vy = py + 5 * math.sin(offsetRot) 
        local vx2 = px + 2 * math.cos(offsetRot) 
        local vy2 = py + 2 * math.sin(offsetRot) 
        local vx3 = px + 3 * math.cos(offsetRot) 
        local vy3 = py + 3 * math.sin(offsetRot) 
        local vx4 = px + 4 * math.cos(offsetRot) 
        local vy4 = py + 4 * math.sin(offsetRot) 
        local vz = pz + 2 
        local vrot = prot+180 
        spike[player] = createObject(2892,vx,vy,z-0.95,0,0,vrot) 
        setObjectScale(spike,0.7) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blows[player] = {createColTube (x2, y2, z2-0.25, 0.9,2), createColTube (vx2, vy2, z2-0.25, 0.9,2), createColTube (vx3, vy3, z2-0.25, 0.9,2), createColTube (vx4, vy4, z2-0.25, 0.9,2) } 
        addEventHandler("onColShapeHit",blows[player], wylaczKola) 
    end 
end) 
  
  
function wylaczKola (player) 
    if player and getElementType(player) == "player" then 
        if isPedInVehicle(player) then 
            local pveh = getPedOccupiedVehicle(player)     
            setVehicleWheelStates(pveh,1,1,1,1) 
        end 
    end 
end 

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