Jump to content

[HELP]Shooting Car Gas Tank


Shagwrath

Recommended Posts

I'd like to make a script which detects if a player has shot a car's gas tank with a sniper rifle, and then blows it up if so.

I've been searching for a way to detect if a specific component of the car was shot, but I haven't been able to find anything useful, any thoughts on how to do this? I could finish the script from there, but this part has baffled me for awhile.

Thanks, any help will be greatly appreciated

Link to comment

  
  
local allowedWeapons = { 
    [33] = true, 
    [34] = true, 
}; 
  
  
  
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()), 
    function() 
        for i,v in ipairs(getElementsByType("vehicle")) do 
            setVehicleFuelTankExplodable(v,false); 
        end 
    end 
); 
  
addEventHandler("onClientPlayerWeaponFire",getLocalPlayer(), 
    function(weapon,ammo,ammoInClip,hX,hY,hZ,hitElement) 
        if hX and hY and hZ then 
            if hitElement then 
                if getElementType(hitElement) == "vehicle" then 
                    if allowedWeapons[weapon] == true then 
                        setVehicleFuelTankExplodable(hitElement,true); 
                    else 
                        setVehicleFuelTankExplodable(hitElement,false); 
                    end 
                end 
            end 
        end 
    end 
); 
  
  

I tried some things and finally got it to work, so yah, now I feel dumb. I wouldn't have thought that setting the fuel tank explodable after it was shot would work, but now I know. So if anyone else has wondered this, or wants the code, here's the solution.

Edited by Guest
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...