[Include] OnPlayerTargetPlayer (0.3d RC7+)
#1

Hey,

SA-MP team just released the new update of 0.3d which contains GetPlayerTargetPlayer function.
This function allows us to detect aiming of players on other players.
With this, I created a new callback called OnPlayerTargetPlayer that called everytime that the target of player is changed.

Script:
http://pastebin.com/EeHumBCP

To install it, just put the script on pawno/include and add the next lines:
pawn Код:
OPTP_OnPlayerUpdate(playerid);
- OnPlayerUpdate
pawn Код:
OPTP_OnPlayerConnect(playerid);
- OnPlayerConnect
pawn Код:
OnPlayerTargetPlayer(playerid,newtarget,oldtarget)
{
    return 1;
}
- Somewhere on your script

Note: The callback is called everytime that GetPlayerTargetPlayer value changed, what means that it will called if the player is aiming someone or if he stopped aiming.

Enjoy
Reply
#2

This is pretty awesome! Though, I didn't like the parts where you have to add bits into code, and so therefore:
http://pastebin.com/SpuF2dfg

I've added the ALS hooking mechanisms so all the user has to do is include the file!

In my copy, I fixed the issue described in the post below. If the player hasn't targeted anyone in the past, it passes INVALID_PLAYER_ID to the callback.
Reply
#3

This will call the callback when the player previously targeted a player, and now is not targetting anybody.
Reply
#4

pawn Код:
forward OnPlayerTargetPlayer(playerid,newtarget,oldtarget);

new OPTP_target[MAX_PLAYERS] = {INVALID_PLAYER_ID,...};
new OPTP_ALS[1 char];

forward OPTP_OnPlayerUpdate(playerid);
forward OPTP_OnPlayerConnect(playerid);
forward OPTP_OnFilterScriptInit();
forward OPTP_OnGameModeInit();

public OnPlayerUpdate(playerid)
{
        new trg = GetPlayerTargetPlayer(playerid);
        if (OPTP_ALS{0} & 1) CallLocalFunction("OnPlayerTargetPlayer","iii",playerid,trg,OPTP_target[playerid]);
        OPTP_target[playerid] = trg;
        return (OPTP_ALS{0} & 2) ? CallLocalFunction("OPTP_OnPlayerUpdate", "i", playerid) : 1;
}
#if defined _ALS_OnPlayerUpdate
        #undef OnPlayerUpdate
#else
        #define _ALS_OnPlayerUpdate
#endif
#define OnPlayerUpdate OPTP_OnPlayerUpdate
 
public OnPlayerConnect(playerid)
{
        OPTP_target[playerid] = INVALID_PLAYER_ID;
        if (OPTP_ALS{0} & 4) CallLocalFunction("OnPlayerConnect", "i", playerid);

        return 1;
}
#if defined _ALS_OnPlayerConnect
        #undef OnPlayerConnect
#else
        #define _ALS_OnPlayerConnect
#endif
#define OnPlayerConnect OPTP_OnPlayerConnect

public OnFilterScriptInit()
{
        if (funcidx("OPTP_OnPlayerTargetPlayer") != -1) OPTP_ALS{0} |= 1;
        if (funcidx("OPTP_OnPlayerUpdate") != -1) OPTP_ALS{0} |= 2;
        if (funcidx("OPTP_OnPlayerConnect") != -1) OPTP_ALS{0} |= 4;
        if (funcidx("OPTP_OnFilterScriptInit") != -1) CallLocalFunction("OPTP_OnFilterScriptInit", "");

        return 1;
}
#if defined _ALS_OnFilterScriptInit
        #undef OnFilterScriptInit
#else
        #define _ALS_OnFilterScriptInit
#endif
#define OnFilterScriptInit OPTP_OnFilterScriptInit

public OnGameModeInit()
{
        if (funcidx("OPTP_OnPlayerTargetPlayer") != -1) OPTP_ALS{0} |= 1;
        if (funcidx("OPTP_OnPlayerUpdate") != -1) OPTP_ALS{0} |= 2;
        if (funcidx("OPTP_OnPlayerConnect") != -1) OPTP_ALS{0} |= 4;
        if (funcidx("OPTP_OnGameModeInit") != -1) CallLocalFunction("OPTP_OnGameModeInit", "");

        return 1;
}
#if defined _ALS_OnGameModeInit
        #undef OnGameModeInit
#else
        #define _ALS_OnGameModeInit
#endif
#define OnGameModeInit OPTP_OnGameModeInit
It can be used as an include.

p.s.: if you don't want me to post here, tell me and I take down it.
Reply
#5

I didn't added any defines to the script because I don't like how it works - replacing the real OnPlayerConnect with one of your own just to add a line... but I didn't expected that someone will really take this code and use it in a inc file, I guess that anyone who want such callback can just modify it how he want.

@KoczkaHUN: I can't see how playing with the bits and cells helps here, also, I'm recommending you to test it on the server because it looks fine for me.
Reply
#6

Quote:
Originally Posted by Amit_B
Посмотреть сообщение
I didn't added any defines to the script because I don't like how it works - replacing the real OnPlayerConnect with one of your own just to add a line... but I didn't expected that someone will really take this code and use it in a inc file, I guess that anyone who want such callback can just modify it how he want.

@KoczkaHUN: I can't see how playing with the bits and cells helps here, also, I'm recommending you to test it on the server because it looks fine for me.
It's not the point of the bits and cells. It's the hooking method. Including your include takes time, while his takes only
pawn Код:
#include <namehere>
And voila. It does everything for you.
Reply
#7

Read my point again. In my opinion, it's better to use the original callbacks and functions (so it will be more easy to detect problems, for example). But as I said - people free to take the code and change it how they want. Publishing this script just shows the way of how to script this.
Reply
#8

No, You're just ignorant. There's not such a big deal with ALS Hooking. There's not any problems and it's been working since now and will be working forever.
Reply
#9

If so, you can edit it and add whatever you want to the script. It wasn't published for hearing opinions.
Reply
#10

Quote:
Originally Posted by Stewie`
Посмотреть сообщение
No, You're just ignorant. There's not such a big deal with ALS Hooking. There's not any problems and it's been working since now and will be working forever.
You are calling a person ignorant for saying his opinion on something? Do you even know the meaning of the word?

On topic:
Great job, although I couldn't think of anything interesting I would be able do with this yet...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)