Create Explosion's if player shoot's a rhino!(0.3z) -
Abagail - 22.01.2014
Okay, so if you want Rhino's to explode when shot at just follow this tutorial. It's tailored for beginners-intermediate pawno scripters.
Okay, so we'll be using the new 0.3z RC3 PAWN package. We'll need to download this if not already, by clicking here. After downloaded follow the tutorial.
Okay, so we'll be needing the #a_samp include of-course.
Then, we'll be needing to define the following things:
#define BULLET_HIT_TYPE_NONE 0
#define BULLET_HIT_TYPE_PLAYER 1
#define BULLET_HIT_TYPE_VEHICLE 2
#define BULLET_HIT_TYPE_OBJECT 3
#define BULLET_HIT_TYPE_PLAYER_OBJECT 4
Then, after we've defined that we can start with the actual code. We'll be using OnPlayerWeaponShot for this.
pawn Code:
forward OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
Then, we'll of-course need to check if they've shot a vehicle. BULLET_HIT_TYPE_VEHICLE is defined as hittype 2, so we'll check just that.(Don't forget to put your brackets!)
pawn Code:
if(hittype == 2 && hitid != INVALID_VEHICLE_ID)
This will also check if the VEHICLEID(hitid) is a valid vehicle. If not it will just return 0 basically. Now, we need to check if the vehicle they shot is a Rhino or not. Rhino's are VehID 432.
We'll use GetVehicleModel for this.
pawn Code:
if(GetVehicleModel(hitid) == 432) ExplodeRhino(hitid);
We'll be using a custom stock to actually create the explosions. We will use CreateExplosion for this tutorial, although it is possible to use custom functions for fire/explosions.
pawn Code:
stock ExplodeRhino(vehicleid)
We'll need to make sure to define the x y and z floats, so we'll do:
new Float: x, Float: y, Float: z;
Now we will use the Float's to get the vehicle's position with GetVehiclePos.
GetVehiclePos(vehicleid, x, y, z);
Then, we can actually create the explosions. This is where you need to be creative. You can do different explosion types, different ranges, etc. The one's I've used are shown below:
pawn Code:
CreateExplosion(x, y, z, 7, 10.0);
CreateExplosion(x, y, z, 1, 7.0);
CreateExplosion(x, y, z, 9, 8.5);
You can find the ExplosionID's by clicking
here, and the CreateExplosion wiki page by clicking
here.
Code:
pawn Code:
// Rhino Explosions
#include <a_samp>
#define BULLET_HIT_TYPE_NONE 0
#define BULLET_HIT_TYPE_PLAYER 1
#define BULLET_HIT_TYPE_VEHICLE 2
#define BULLET_HIT_TYPE_OBJECT 3
#define BULLET_HIT_TYPE_PLAYER_OBJECT 4
forward OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ);
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(hittype == 2 && hitid != INVALID_VEHICLE_ID)
{
if(GetVehicleModel(hitid) == 432) ExplodeRhino(hitid); // They Shot a Rhino, - Let there be an explosion from the Rhino. We'll use a custom stock for this. //
}
}
stock ExplodeRhino(vehicleid)
{
new Float: x, Float: y, Float: z;
GetVehiclePos(vehicleid, x, y, z);
CreateExplosion(x, y, z, 7, 10.0);
CreateExplosion(x, y, z, 1, 7.0);
CreateExplosion(x, y, z, 9, 8.5);
}
If you have any questions feel free to reply or PM me.
Thanks,
Abagail
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Vince - 22.01.2014
You define BULLET_HIT_TYPE_VEHICLE, yet you don't use it. Pro.
Also use [pawn][/pawn] tags, please.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Abagail - 22.01.2014
That doesn't help me... or anyone else for a matter of fact. I put them there so you could easily reference the ID's if needed.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Vince - 22.01.2014
What would be the point?
pawn Code:
if(hittype == BULLET_HIT_TYPE_VEHICLE && hitid != INVALID_VEHICLE_ID)
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Kyance - 23.01.2014
I don't understand why is everyone giving out so much hate to everyone in the tutorials board/w.e.
So what if he did something wrong? No need to act like a fucking dick-head.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Mauzen - 23.01.2014
I cant see any hate here, just constructive criticism. He just mentioned some things that you could improve.
Tutorials are meant to teach other people, so wheres the problem with giving some tips how to teach them better?
Quote:
Originally Posted by Abagail
That doesn't help me... or anyone else for a matter of fact. I put them there so you could easily reference the ID's if needed.
|
Defines like these indeed are mostly meant to be used instead of the numbers. The code gets a lot easier to read if you see that it checks for vehicles, instead of just seeing it checks for "2", then searching the defines and trying to figure out what "2" could mean. Imagine this is part of a big script and there are dozens of definitions with the value "2", how could you know which one is correct?
The rest is written pretty well, considering that most other guys here just post a bunch of code without any explanation.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Abagail - 23.01.2014
Thanks for the constructive criticism and comments!
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
xZdadyZx - 01.02.2014
This is creating explosion, it is useless.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Gill - 01.02.2014
He can use
pawn Code:
SetVehicleHealth(vehicleid, Float:health)
....together with the explosives.. to ensure that it'll blowup.. not sure if Rhino blows up with explosives only. lol.
Anyways could help some newbies around. GJ.
Re: Create Explosion's if player shoot's a rhino!(0.3z) -
Raza2013 - 18.02.2014
brah you're using CreateExplosion it's useless i think so.