[Tutorial] Usage(s) of OnPlayerWeaponShot!
#1

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.

Code:
#includes a_samp
#includes foreach
And our defines for the callback...
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
Okay, so next we will be placing an empty OnPlayerWeaponShot in. It should look like this:

Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    return 1;
}
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.
Code:
if(BULLET_HIT_TYPE_NONE) {
SetPlayerPos(playerid, fX, fY, fZ);
}
If we want to restrict this to only RCON Admins we can do it like this:
Code:
if(hittype == BULLET_HIT_TYPE_NONE) {
if(IsPlayerAdmin(playerid)) SetPlayerPos(playerid, fX, fY, fZ);
}
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...

Code:
if(hittype == BULLET_HIT_TYPE_PLAYER) {
SetPlayerArmour(hitid, 0);
}
Now if we want to make a vehicle loose 100 health when shot at we can do...
Code:
if(hittype == BULLET_HIT_TYPE_VEHICLE) {
SetVehicleHealth(hitid, 0);
}
If we want to destroy an object when it's shot at we can do this...
Code:
if(hittype == BULLET_HIT_TYPE_OBJECT) {
DestroyObject(hitid);
}
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
Reply
#2

Updated.
Reply
#3

Lots of mistakes. You're not even comparing the hittype. I'm pretty sure that if you were to compile this you would get warnings about redundant expression non-zero.
Reply
#4

Using switch would be faster.
Reply
#5

You can't use like that, you getting warnings.
You must do with == like this
pawn Code:
if( hittype == BULLET_HIT_TYPE_PLAYER ) {
SetPlayerArmour( hitid, 0 );
}
Reply
#6

Quote:
Originally Posted by shulk
View Post
You can't use like that, you getting warnings.
You must do with == like this
pawn Code:
if( hittype = BULLET_HIT_TYPE_PLAYER ) {
SetPlayerArmour( hitid, 0 );
}
that's 1 =, lol.

use ==.

could be a typing mistake, just pointing it out
Reply
#7

Uh sorry i edited it, but why use BULLET_HIT_TYPE_PLAYER? That is only define... Use numbers
Reply
#8

i m confused after reading it...
Please make tutorials only if u know what you are doing is correct...
Reply
#9

I'm just saying that this dont work...
Reply
#10

I don't know what I was doing when I made this one... I'll fix it when I have time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)