[Include] OnPlayerShootPos
#1

I have officially ended supported for this. 0.3z introduces a more accurate implementation of this in SA-MP, so you should use it instead.

OnPlayerShootPos

Introduction
I can't believe that nobody came up with this idea! Basically, this include detects the position that the player potentially shot at with a weapon. This is useful in a lot of circumstances. For example, if a player shoots an object, that object would get destroyed!

How it works
Firstly, the player's position is recorded and stored. An iteration is performed to get the position that the player potentially shot at. When the nearest Z position is matched with the aimed Z position, this callback is called:

pawn Код:
public OnPlayerShootPos(playerid, Float:x, Float:y, Float:z, Float:distance)
{
    return 1;
}
Note that this include needs SAfull.hmap from MapAndreas (you do NOT need the plugin). Place it inside the scriptfiles folder.

Notes
- This doesn't work in interiors due to MapAndreas limitations.
- The array of weapon distances might be a bit off.
- Won't work when a player aims too high.

Credits
- Credits to RyDeR` for the MapAndreas function.
- Credits to Kalcor for the SAfull.hmap file.
- Credits to Rockstar Games for the weapon distances (weapon.dat).

Downloads
a_sp.inc
SAfull.hmap

Screenshots
Tested with this code:

pawn Код:
#include <a_samp>
#include <a_sp>

public OnPlayerShootPos(playerid, Float:x, Float:y, Float:z, Float:distance)
{
    CreateExplosion(x, y, z, 6, 30.0);
    return 1;
}


Reply
#2

Nice and awesome, i wanted an include like this, But i don't know how to make one...
Reply
#3

Does it work for vehicle objects? (models)
Reply
#4

Quote:
Originally Posted by Sublime
Посмотреть сообщение
Does it work for vehicle objects? (Not models)
Not sure, but I believe there's an include released for that already.

Quote:
Originally Posted by newbie scripter
Посмотреть сообщение
Nice and awesome, i wanted an include like this, But i don't know how to make one...
It's pretty easy, IMO. You just need to know some basic maths and PAWN knowledge.

Anyways, here's some small code (using this include) that destroys objects upon shooting them:

pawn Код:
public OnPlayerShootPos(playerid, Float:x, Float:y, Float:z, Float:distance)
{
    new Float:fObjectPos[3];

    for (new i = 0; i < MAX_OBJECTS; i ++)
    {
        if (!IsValidObject(i))
            continue;
           
        GetObjectPos(i, fObjectPos[0], fObjectPos[1], fObjectPos[2]);
       
        fObjectPos[0] -= x;
        fObjectPos[1] -= y;
        fObjectPos[2] -= z;

        if ((fObjectPos[0] * fObjectPos[0]) + (fObjectPos[1] * fObjectPos[1]) + (fObjectPos[2] * fObjectPos[2]) < 40.0)
        {
            DestroyObject(i);
            break;
        }
    }
    return 1;
}
Reply
#5

Ah, great idea and the include Emmet_.
Reply
#6

There is going to be a problem with this, you didn't take into account you need to adjust for shooting offset so your results won't be accurate.
Reply
#7

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
There is going to be a problem with this, you didn't take into account you need to adjust for shooting offset so your results won't be accurate.
That's true, I need to do some minor tweaking with the script. As far as I know, it was tested with most semi-auto weapons and works well when the player is crouched.
Reply
#8

Could be useful, I've been looking for a good way to compensate for checking line/sphere collisions.
Reply
#9

Interesting,good work :P
Reply
#10

How would i make it so it only destroys a specific object? like only when i shoot a lamp post it destroys just that lamp post and when you shoot other objects it doesnt do anything?

nice include! and I hope someone can tell me this :P!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)