Player aim at a ped
#1

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
Reply
#2

PHP код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    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
Reply
#3

Quote:
Originally Posted by FailerZ
Посмотреть сообщение
PHP код:
#define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    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?
Reply
#4

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
Reply
#5

Use GetPlayerTargetActor in a timer that is triggered by OnPlayerKeyStateChange while holding right click and that is stopped when rich click is released.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)