SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 18/06/2014, 08:35 PM   #1
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 546
Reputation: 45
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
Paramaters:
Code:
  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:
Code:
  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
Code:
BULLET_HIT_TYPE_NONE            0
BULLET_HIT_TYPE_PLAYER          1
BULLET_HIT_TYPE_VEHICLE         2
BULLET_HIT_TYPE_OBJECT          3
BULLET_HIT_TYPE_PLAYER_OBJECT   4
What can you do with those TYPES?

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

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

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

BULLET_HIT_TYPE_OBJECT:
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

BULLET_HIT_TYPE_PLAYEROBJECT:
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 11:54 PM.
XStormiest is offline   Reply With Quote
Old 04/07/2014, 03:49 PM   #2
[MM]18240[FMB]
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.

-EDIT-
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.
-edit-
I found the problem, your math was backwards.
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;
}
__________________
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! ts.teamshrimp.com:9987

Last edited by [MM]18240[FMB]; 04/07/2014 at 10:39 PM.
[MM]18240[FMB] is offline   Reply With Quote
Old 25/08/2014, 11:54 PM   #3
XStormiest
Gangsta
 
Join Date: Jun 2012
Location: Continent: Europe, Country: Romania, City: Buzau
Posts: 546
Reputation: 45
Default Re: How to make a car be destroyed even if is not anyone in the car (OnPlayerWeaponShot)

Okay thanks, I see now, I will edit that
__________________
XStormiest is offline   Reply With Quote
Old 06/11/2014, 01:21 AM   #4
Jakwob
Huge Clucker
 
Jakwob's Avatar
 
Join Date: Jan 2014
Location: United Kingdom
Posts: 247
Reputation: 27
Default Re: How to make a car be destroyed even if is not anyone in the car (OnPlayerWeaponShot)

Nice tut I could use this so I will start and see what else could be done with it. Thanks again
Jakwob is offline   Reply With Quote
Old 04/06/2019, 09:16 AM   #5
RainbowAsher
Little Clucker
 
Join Date: Jul 2015
Posts: 10
Reputation: 0
Default Re: How to make a car be destroyed even if is not anyone in the car (OnPlayerWeaponShot)

NIce
RainbowAsher is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PlayerTextdraw not destroyed falcko Scripting Help 1 08/05/2013 12:22 AM
Last checkpoint was not destroyed newbienoob Scripting Help 8 27/02/2013 01:54 PM
Car will not spawn away (get destroyed) EAsT-OAK_510 Scripting Help 1 28/11/2012 02:59 AM
How to make a moving object get destroyed at a players position? gnoomen2 Scripting Help 1 31/07/2012 02:07 AM
Checkpoint not being destroyed NewTorran Help Archive 2 07/06/2010 09:30 PM


All times are GMT. The time now is 09:57 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.