View Single Post
Old 18/06/2014, 07:35 PM   #1
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 558
Reputation: 46
Default How to make a car be destroyed even if is not anyone in the car (OnPlayerWeaponShot)

Hello everyone, I'm XStormiest and as you may know since the last update 0.3z, its been added a new simple callback but awesome, it allows you to verify what player shoots.

First lets take a brief explaination of the callback

Callback: OnPlayerWeaponShot
  playerid - the id of the player that shoot
  weaponid - the id of the weapon that player use to shoot
  hittid - the id of the object/player/car that have been hit
  fx - the coordonate of X axis where player shoots
  fy - the coordonate of Y axis where player shoots
  fz - the coordonate of Z axis where player shoots
Return Values:
  0 - prevent any bullet from being shoot
  1 - allows bullets to be shoot
Good, now lets see the type of things we can verify if shooted
What can you do with those TYPES?

Good to use with the X,Y,Z coordonates, you can create an awesome Explosive Bullets for example.

Good for making different things based on your creativity for example, you can make more damage bullets , or one shot bullets or anything you want.

Is what we gonna use in this tutorial, also you can make different things as well here, it depends on your imagination.

As said below, in the part of NONE section where i told you about Explosive Bullets , you can make them to remove an object that is in the radius of where palyer shoot

Cool feature, you can use this for example: making a DM Test for players, and they have to shoot different objects. so in this case, only they will see the objects and actual shoot them.

Why is this Callback awesome?
Because before if you wanted to ever do that, you had to use Camera Vectors to verify if player look at that object, but that would be inacurracy, but now is more precise i guess..

Now that I explained almost every single thing about this feature , lets actually get into the tutorial.
So we have this simple callback
pawn Code:
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;

Ok this was my tutorial.
I want to say sorry if i have some mistakes (Im from Romania so my english is not that perfect yet...)
Also, if you know a easy way to do that , go ahead tell me , correct me if Im wrong cause I dont want to learn others wrong scripts.

Last edited by XStormiest; 25/08/2014 at 10:54 PM.
XStormiest is offline   Reply With Quote