View Single Post
Old 04/07/2014, 02:49 PM   #2
Huge Clucker
[MM]18240[FMB]'s Avatar
Join Date: Jul 2011
Location: Space!
Posts: 355
Reputation: 47
Default Re: How to make a car be destroyed even if is not anyone in the car (OnPlayerWeaponShot)

i'll have to test this out. Looks nice.

This code needs heavy modified. When you shoot the car, the first bullet makes it have -900 HP and the second one repairs it to 1000 HP.. Also doesn't work with Knives, Grenades, and Fists.
I found the problem, your math was backwards.
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
    if(hittype == 2) // verify if the player shoot an vehicle
         new bool: isany_incar = false; // we use a boolean (true/false variable) to check if is anyone in car, and set this to false by default
         for(new i = 0; i < MAX_PLAYERS; i++) // we go through a loop for all players
             if(IsPlayerInVehicle(i, hitid)) // we verify if any player is in the shooted vehicle
                  isany_incar = true; // if a player is in vehicle , then we set our variable to false
                  break; // we break the loop , cause thats mean that a player have been found
         if(isany_incar != true) // we check if the verify from below was false, is noone in the car
              new Float: vHealth; // creating a float variable for getting vehicle health
              GetVehicleHealth(hitid, vHealth); // getting the hitid vehicle

              SetVehicleHealth(hitid, vHealth-40);  // removing 100 from the vehicle health, its not necesary to be 100, you can make a system based on weapon cause unfortunately there is no damage paramater in this callback
    return 1;
Looking for a free Teamspeak Server to chill with your friends on? Join Teamshrimp Gaming's Teamspeak. We have free permanent channels, custom servergroups, and we're hiring moderators! Come check us out!

Last edited by [MM]18240[FMB]; 04/07/2014 at 09:39 PM.
[MM]18240[FMB] is offline   Reply With Quote