Player aim at a ped - 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: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player aim at a ped (
/showthread.php?tid=637575)
Player aim at a ped -
Arbico - 17.07.2017
Hi guys, So i wanted to make a roleplay server
And i wanted to make people rob a store by aiming at the cashier
Any ideas how can i make that, The cashier will be just a ped
Try to give me a code or an include to do that, i really need it
Re: Player aim at a ped -
FailerZ - 17.07.2017
PHP код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_HANDBRAKE)) //The key handbrake = Right mouse button by default (AIM)
{
new actorid = GetPlayerTargetActor(playerid);
if(actorid == SomeActorVar) //SomeActorVar is your actorid that you are passing. Like the 24/7 actor or clothes store actor etc..
{
//Player aimed at the actor do something like animation and robbing stuff
}
}
return 1;
}
Please note that you should create your actor and assign it to a variable first
https://sampwiki.blast.hk/wiki/CreateActor
Re: Player aim at a ped -
Arbico - 17.07.2017
Quote:
Originally Posted by FailerZ
PHP код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if(PRESSED(KEY_HANDBRAKE)) //The key handbrake = Right mouse button by default (AIM)
{
new actorid = GetPlayerTargetActor(playerid);
if(actorid == SomeActorVar) //SomeActorVar is your actorid that you are passing. Like the 24/7 actor or clothes store actor etc..
{
//Player aimed at the actor do something like animation and robbing stuff
}
}
return 1;
}
Please note that you should create your actor and assign it to a variable first https://sampwiki.blast.hk/wiki/CreateActor
|
Can I make it with OnPlayerUpdate, and use GetPlayerTargetActor or not?
Re: Player aim at a ped -
FailerZ - 17.07.2017
Quote:
Originally Posted by Arbico
Can I make it with OnPlayerUpdate, and use GetPlayerTargetActor or not?
|
Yes but it is
might (not sure) cause performance problems as OnPlayerUpdate is called so frequently.
It is recommended under OnPlayerKeyStateChange if that is your use case.
EDIT: Wiki seems to be using OnPlayerUpdate so I now doubt if it is actually better. I don't know honestly.
https://sampwiki.blast.hk/wiki/GetPlayerTargetActor
Re: Player aim at a ped -
Paulice - 17.07.2017
Use GetPlayerTargetActor in a timer that is triggered by OnPlayerKeyStateChange while holding right click and that is stopped when rich click is released.