PlayerPos help -
jimis - 29.07.2012
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
Re: PlayerPos help -
Cjgogo - 29.07.2012
Use IsPlayerInRangeOfPoint and TogglePlayerControllable,look up SAMP wikipedia.
Re: PlayerPos help -
jimis - 29.07.2012
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?
Re: PlayerPos help -
Devilxz97 - 29.07.2012
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
Re: PlayerPos help -
Sinner - 29.07.2012
Quote:
Originally Posted by Devilxz97
|
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;
}
Re: PlayerPos help -
jimis - 29.07.2012
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]
Re: PlayerPos help -
Sinner - 29.07.2012
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.
Re: PlayerPos help -
Devilxz97 - 29.07.2012
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 . .
Re: PlayerPos help -
Roko_foko - 29.07.2012
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];
Re: PlayerPos help -
Sinner - 29.07.2012
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??