• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Checking aiming data real-time
#1
I am working on a right-clickable NPC system. Currently I am checking if the player is aiming on the npc under onplayerupdate.

This solution is not the best, because you should move in order to open the npc's menu. Any way to instantly detect aiming? Is there a callback for aim detection?
  Reply
#2
Code:
new actorid = GetPlayerTargetActor(playerid);
  Reply
#3
(2020-12-20, 08:05 PM)Eloctro Wrote:
Code:
new actorid = GetPlayerTargetActor(playerid);


More or less. NPC's are considered players by the server.

In order to get the ID of the NPC a player is aiming to, use GetPlayerTargetPlayer(playerid);


Furthermore, in order for either of these two functions to work, you'll have to enable the following inside OnPlayerConnect:

Code:
EnablePlayerCameraTarget(playerid, 1);

This is disabled by default to save bandwidth, but isn't really a problem in the last decade.
  Reply
#4
You guys misunderstood me. I am looking for a callback which is called when a player aims. The function is done, but using it under onplayerupdate may not be instant when the player is not moving.

So i am looking for something like this:



public OnPlayerAim(playerid)

{

return 1;

}



OnPlayerUpdate dependent callbacks are not an option.(emmet's new samp callbacks, etc)
  Reply
#5
ID_AIM_SYNC - ID: 203

EDIT: Packet ID, try with raknet.
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#6
(2020-12-24, 10:23 PM)Pinch Wrote: ID_AIM_SYNC - ID: 203

EDIT: Packet ID, try with raknet.
Sorry for my stupid question, but what callback or function is that related to? I am a little bit confused.


For anyone else who might wanna help:
I am looking for a callback which gets called when a player is aiming, so i can instantly check if he is aiming on the npc and if he is, i can run the wanted function.
The problem with OnPlayerUpdate is if the player is moving and right clicking the npc, it instantly runs the function, but when the player is not moving, onplayerupdate doesn't get called so the aiming isn't checked and the function doesn't get called.
So I am looking for a callback where i can instantly check if the player is aiming on the npc, without the player having to move.

I prefer not to use small timers because they might not be "instant"(you have to keep right click pressed for some time) or cause lag(it's not a really good idea to run 20-50ms timers on a lot of players)

I hope this is possible in pawn, never managed to do anything like this before, but MTA is getting advantage over samp and i have to implement functions which replaces commands and gives the players more options.
  Reply
#7
Pawn.RakNet plugin, incoming packet, ID 203
Using Pawn.CMD?

If you're doing so, this is the very first sign that you absolutely shouldn't utilize your all powerful P-Code knowledge in any of the scripting discussion topics.
  Reply
#8
(2020-12-25, 04:27 PM)Pinch Wrote: Pawn.RakNet plugin, incoming packet, ID 203
Thanks, i'm gonna give it a look today or tomorrow and find out if it works well.

EDIT: Tried it, it works. Sometimes it has a small delay(around max. 750ms) but if you move the mouse or move the character it works instantly. Thanks for the help, if i find out any ways to make it faster, i'm gonna post it here.

ps. the delay might appear just because of localhost's lag.
  Reply


Forum Jump: