PlayerPos help
#1

Hi all,i want to make a cuff system with hotkey,but i dont know how to check if the suspect is near to cop.For example,when a cop press hotkey 'LALT' and a suspect is near to him,then the suspect will stop moving (with controlable,.Who can help me?

Thanks
Reply
#2

Use IsPlayerInRangeOfPoint and TogglePlayerControllable,look up SAMP wikipedia.
Reply
#3

ok,but i want use hot key not and a command like /cuff id ,so how i can check if any suspect is near to cop?
Reply
#4

https://sampwiki.blast.hk/wiki/GetPlayerPos
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/Function:...erControllable

pawn Код:
forward IsCopNearSuspect(playerid);

public IsCopNearSuspect(playerid)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 5, X, Y, Z))
            {
                //Your code here
            }
        }
    }
    return 1;
}
for u
Reply
#5

Quote:
Originally Posted by Devilxz97
Посмотреть сообщение
https://sampwiki.blast.hk/wiki/GetPlayerPos
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/Function:...erControllable

pawn Код:
forward IsCopNearSuspect(playerid);

public IsCopNearSuspect(playerid)
{
    new Float:X, Float:Y, Float:Z;
    GetPlayerPos(playerid, X, Y, Z);
    for(new i; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInRangeOfPoint(i, 5, X, Y, Z))
            {
                //Your code here
            }
        }
    }
    return 1;
}
for u
That will just check if playerid is near anyone, and it's terrible inflexible :/

Try:

pawn Код:
stock IsPlayerNearSuspect(playerid, suspectid, Float:range)
{
    new bool:isNear = false;
    if(IsPlayerConnected(playerid) && IsPlayerConnected(suspectid)) {
        new Float:pX, Float:pY, Float:pZ;
        GetPlayerPos(playerid, pX, pY, pZ);
        if(IsPlayerInRangeOfPoint(suspectid, range, pX, pY, pZ)) {
            isNear = true;
        }
    }
    return isNear;
}
Reply
#6

ok, look an example on human language and not at p.c language. Sorry,but i am not so good on scripting ,but thanks for trying to help.
When cop press 'LALT' then the code will check if a suspect is near to cop, if yes then the suspect will be cuffed and stop moving ,if not the cop will receive a message [noone is near to you]
Reply
#7

Quote:
Originally Posted by jimis
Посмотреть сообщение
ok, look an example on human language and not at p.c language. Sorry,but i am not so good on scripting ,but thanks for trying to help.
When cop press 'LALT' then the code will check if a suspect is near to cop, if yes then the suspect will be cuffed and stop moving ,if not the cop will receive a message [noone is near to you]
If you can't script why do you need to know this? The examples are perfectly simple. You just check if the position of the player is near the position of the suspect.
Reply
#8

Quote:
Originally Posted by Sinner
Посмотреть сообщение
That will just check if playerid is near anyone, and it's terrible inflexible :/

Try:

pawn Код:
stock IsPlayerNearSuspect(playerid, suspectid, Float:range)
{
    new bool:isNear = false;
    if(IsPlayerConnected(playerid) && IsPlayerConnected(suspectid)) {
        new Float:pX, Float:pY, Float:pZ;
        GetPlayerPos(playerid, pX, pY, pZ);
        if(IsPlayerInRangeOfPoint(suspectid, range, pX, pY, pZ)) {
            isNear = true;
        }
    }
    return isNear;
}
mine should works . .
Reply
#9

To check what key has player pressed use OnPlayerKeyStateChange

To check if there is a suspect next to him
you can use this code(in my opinion the fastest way of doing this):
pawn Код:
//global variable
new Suspects[MAX_PLAYERS+1];
//_________________________________
// under OnPlayerKeyStateChange when pressed key
new Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new i=0;Suspects[i]!=-1;i++)
if(IsPlayerInRangeOfPoint(Suspects[i],5,x,y,z))//chage 5 if too big or small range
{
    //your code
}
//_______________________________________
// once player becomes wanted/suspect
new i;
for(i=0;Suspects[i]!=-1;i++){}
Suspects[i]=playerid;//suspectid
Suspects[i+1]=-1;
//----------------------------------
//once player is no loger wanted/suspect - of is jailed, prisoned, DON'T FORGET DISCONNECTED, or something else
new i;
for(i=0;Suspects[i]!=playerid;i++){}//playerid=suspectid
while(Suspects[i]!=-1)Suspects[i]=Suspects[i+1];
Reply
#10

Quote:
Originally Posted by Devilxz97
Посмотреть сообщение
mine should works . .
No. Your code checks if playerid is near ANYONE, how do you know who's the suspect then??
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)