SA-MP Forums Archive
[Include] OnPlayerShootPos - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] OnPlayerShootPos (/showthread.php?tid=478751)



OnPlayerShootPos - Emmet_ - 01.12.2013

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;
}





Re: OnPlayerShootPos - newbie scripter - 01.12.2013

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


Re: OnPlayerShootPos - Sublime - 01.12.2013

Does it work for vehicle objects? (models)


Re: OnPlayerShootPos - Emmet_ - 01.12.2013

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;
}



Re: OnPlayerShootPos - iZN - 01.12.2013

Ah, great idea and the include Emmet_.


Re: OnPlayerShootPos - Pottus - 01.12.2013

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.


Re: OnPlayerShootPos - Emmet_ - 01.12.2013

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.


Re: OnPlayerShootPos - Pottus - 01.12.2013

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


Re: OnPlayerShootPos - Gen3i - 01.12.2013

Interesting,good work :P


Re: OnPlayerShootPos - Voxel - 01.12.2013

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!