16.02.2014, 14:28
(
Last edited by Abagail; 30/09/2014 at 09:26 PM.
Reason: Updated.
)
Usage(s) of OnPlayerWeaponShot!
This tutorial will be showing you how you can use OnPlayerWeaponShot. OnPlayerWeaponShot was just recently added in 0.3z.
You can detect the coordinates, what was hit(object, vehicle, player, none), the playerid that shot it, and what weaponid was used. I'll be showing you some cool things you can do with this new feature.
Requirements for Tutorial:
Basic Pawno Knowledge
The 0.3z Pawno Package(0.3z official release is recommended, how-ever RC versions will work.)
Alright, so we'll start by opening up our pawno! Once opened click on "New". Then, you'll need to just delete everything in the script so it's just a blank script with nothing in it. Once that's done you'll need to put your includes in.
And our defines for the callback...
Okay, so next we will be placing an empty OnPlayerWeaponShot in. It should look like this:
Okay, so let's take it slow and explain everything before we dive in. The "playerid" is obviously the id of the player shooting the weapon. The "weaponid" is the WeaponID that shot the bullet. The "hittype" is the type of hit that was shot at. The defines you added go with the "hittype".
BULLET_HIT_TYPE_NONE is as the name suggests when the bullet doesn't hit anything(object/pobject, vehicle, etc.).
BULLET_HIT_TYPE_PLAYER is when the bullet hit's another player.
BULLET_HIT_TYPE_VEHICLE is when the bullet hit's a vehicle.
BULLET_HIT_TYPE_OBJECT is when the bullet hit's an object.
BULLET_HIT_TYPE_PLAYER_OBJECT is when the bullet hit's an object attached to a player(player object). This will only be called if the object is attached either through AttachObjectToPlayer, - or SetPlayerAttachedObject. This returns the object offsets.
The HitID goes along with "hittype". For instance, if the hittype is BULLET_HIT_TYPE_PLAYER it will be the player(ID) that was shot at. Or if it was a vehicle it will be the vehicles ID and so on.
Now the coordinates can be a bit confusing in a way. If the bullet hit nothing then they will simply be the coordinates the bullet hit. Of-Course "fX" is the X coordinate, "fY" is the Y coordinate, and "fZ" is the Z Coordinate.
How-ever if it was a player/vehicle/object/playerobject it will be the offset coordinates from the center of what ever it is.
Now that we've explained everything we can start testing things out. The first thing we'll be doing is making a simple teleport gun. So, we'll use SetPlayerPos and the fX, fY, fZ coordinates. We'll only teleport them if they shot at the ground.
If we want to restrict this to only RCON Admins we can do it like this:
Next moving onto the player type example. We'll just make it so they loose all their armour... Just for an example of what you can do...
Now if we want to make a vehicle loose 100 health when shot at we can do...
If we want to destroy an object when it's shot at we can do this...
It should be noted that returning 0, - or another integer/number besides "1" will stop the bullet from being sent, - and no damage will be taken. Returning 1 sends the bullet as normal.
I hope I explained everything accurately and in-depth enough for you guys. If I did something wrong, or you have a question or comment just simply reply or Private Message me!
NOTE: This tutorial is some-what updated as I haven't really updated it, and it's not very clear. Apologies for the awful tutorial, if I have any time I'll fix it up.
Thanks,
- Abagail
This tutorial will be showing you how you can use OnPlayerWeaponShot. OnPlayerWeaponShot was just recently added in 0.3z.
You can detect the coordinates, what was hit(object, vehicle, player, none), the playerid that shot it, and what weaponid was used. I'll be showing you some cool things you can do with this new feature.
Requirements for Tutorial:
Basic Pawno Knowledge
The 0.3z Pawno Package(0.3z official release is recommended, how-ever RC versions will work.)
Alright, so we'll start by opening up our pawno! Once opened click on "New". Then, you'll need to just delete everything in the script so it's just a blank script with nothing in it. Once that's done you'll need to put your includes in.
Code:
#includes a_samp #includes foreach
Code:
#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
Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) { return 1; }
BULLET_HIT_TYPE_NONE is as the name suggests when the bullet doesn't hit anything(object/pobject, vehicle, etc.).
BULLET_HIT_TYPE_PLAYER is when the bullet hit's another player.
BULLET_HIT_TYPE_VEHICLE is when the bullet hit's a vehicle.
BULLET_HIT_TYPE_OBJECT is when the bullet hit's an object.
BULLET_HIT_TYPE_PLAYER_OBJECT is when the bullet hit's an object attached to a player(player object). This will only be called if the object is attached either through AttachObjectToPlayer, - or SetPlayerAttachedObject. This returns the object offsets.
The HitID goes along with "hittype". For instance, if the hittype is BULLET_HIT_TYPE_PLAYER it will be the player(ID) that was shot at. Or if it was a vehicle it will be the vehicles ID and so on.
Now the coordinates can be a bit confusing in a way. If the bullet hit nothing then they will simply be the coordinates the bullet hit. Of-Course "fX" is the X coordinate, "fY" is the Y coordinate, and "fZ" is the Z Coordinate.
How-ever if it was a player/vehicle/object/playerobject it will be the offset coordinates from the center of what ever it is.
Now that we've explained everything we can start testing things out. The first thing we'll be doing is making a simple teleport gun. So, we'll use SetPlayerPos and the fX, fY, fZ coordinates. We'll only teleport them if they shot at the ground.
Code:
if(BULLET_HIT_TYPE_NONE) { SetPlayerPos(playerid, fX, fY, fZ); }
Code:
if(hittype == BULLET_HIT_TYPE_NONE) { if(IsPlayerAdmin(playerid)) SetPlayerPos(playerid, fX, fY, fZ); }
Code:
if(hittype == BULLET_HIT_TYPE_PLAYER) { SetPlayerArmour(hitid, 0); }
Code:
if(hittype == BULLET_HIT_TYPE_VEHICLE) { SetVehicleHealth(hitid, 0); }
Code:
if(hittype == BULLET_HIT_TYPE_OBJECT) { DestroyObject(hitid); }
I hope I explained everything accurately and in-depth enough for you guys. If I did something wrong, or you have a question or comment just simply reply or Private Message me!
NOTE: This tutorial is some-what updated as I haven't really updated it, and it's not very clear. Apologies for the awful tutorial, if I have any time I'll fix it up.
Thanks,
- Abagail