//cuff
public :confused:(playerid, newkeys, oldkeys)
{
new string[128];
if(newkeys == KEY_WALK)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(CommandsBlocked[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
return 1;
}
if(InDuel[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
return 1;
}
if(pInfo[playerid][Spawned] != 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
return 1;
}
if(IsKidnapped[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
return 1;
}
if(IsFrozen[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
return 1;
}
if(AccInfo[i][OnDuty] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
return 1;
}
if(gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI)
{
return 1;
}
if(i == playerid)
{
return 1;
}
if(GetDistanceBetweenPlayers(playerid,i) > 4)
{
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(GetPlayerWantedLevel(i) == 0)
{
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
return 1;
}
if(GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
return 1;
}
if(pInfo[i][Spawned] != 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsFrozen[i] == 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsCuffed[i] == 1 && cuff_arrest_time[i] != 0) return 1;
if(IsCuffed[i] == 1 && cuff_arrest_time[i] == 0)
{
ARREST(playerid,i);
}
CUFF(playerid,i);
}
}
return 1;
}
Try this:
https://sampforum.blast.hk/showthread.php?tid=570868 Instead of the normal loop. And for a more effecient way, you should run the loop the find out the nearest ID(the one you want to cuff/arrest), and after that do all the rest(close the loop before) because your loop is running shitloads of code and it's being returned 1; which is why it stops. |
public :confused:(newkeys, oldkeys)
{
new string[128];
if(newkeys == KEY_WALK)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
for(new playerid;playerid<MAX_PLAYERS;playerid++)
{
if(CommandsBlocked[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
return 1;
}
if(InDuel[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
return 1;
}
if(pInfo[playerid][Spawned] != 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
return 1;
}
if(IsKidnapped[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
return 1;
}
if(IsFrozen[playerid] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
return 1;
}
if(AccInfo[i][OnDuty] == 1)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
return 1;
}
if(gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI)
{
return 1;
}
if(i == playerid)
{
return 1;
}
if(GetDistanceBetweenPlayers(playerid,i) > 4)
{
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(GetPlayerWantedLevel(i) == 0)
{
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
return 1;
}
if(GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
return 1;
}
if(pInfo[i][Spawned] != 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsFrozen[i] == 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsCuffed[i] == 1 && cuff_arrest_time[i] != 0) return 1;
if(IsCuffed[i] == 1 && cuff_arrest_time[i] == 0)
{
ARREST(playerid,i);
}
CUFF(playerid,i);
}
}
return 1;
}
for(new playerid;playerid<MAX_PLAYERS;playerid++)
{
I had a good laugh reading the stupidity of the replies you got. You have a lot of code here that does not even belong in a loop and there other issues as well with the logic structure.
|
new string[128];
if(newkeys & KEY_WALK)
{
if(CommandsBlocked[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] Your commands are blocked, You cannot use commands.");
if(InDuel[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use commands while on duel, Use /leave to exit the duel.");
if(pInfo[playerid][Spawned] != 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You must be alive and spawned in order to be able to use this command.");
if(IsKidnapped[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You are kidnapped. You cannot use this command.");
if(IsFrozen[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You have been frozen by a Server Administrator. You cannot use this command.");
if(AccInfo[i][OnDuty] == 1) return SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot use this command on this player because they are in Administrator mode.");
if(gTeam[playerid] != COP && gTeam[playerid] != ARMY && gTeam[playerid] != CIA && gTeam[playerid] != FBI) return 1;
new i = GetClosestPlayer(playerid);
if(i == -1) return 1;
if(GetDistanceBetweenPlayers(playerid,i) > 4)
{
format(string,sizeof(string),"[ERROR] %s[%d] is too far away. You cannot reach him to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(GetPlayerWantedLevel(i) == 0)
{
format(string,sizeof(string),"[ERROR] %s[%d] is innocent. use /cuff to place cuffs on him.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(gTeam[i] == COP || gTeam[i] == ARMY || gTeam[i] == CIA || gTeam[i] == FBI)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot cuff other Law Enforcement officers. You might lose your job for that ...");
return 1;
}
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER || GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while in a vehicle. Exit the vehicle first.");
return 1;
}
if(GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
{
SendClientMessage(playerid,COLOR_ERROR,"[ERROR] You cannot place a suspect in cuffs while they are in a vehicle. Get them to exit the vehicle first.");
return 1;
}
if(pInfo[i][Spawned] != 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is not spawned. You cannot place cuffs on dead people ..",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsFrozen[i] == 1)
{
format(string,sizeof(string),"[ERROR] %s(%d) is frozen by a Server Administrator. You cannot place cuffs them.",GetName(i),i);
SendClientMessage(playerid,COLOR_ERROR,string);
return 1;
}
if(IsCuffed[i] == 1 && cuff_arrest_time[i] != 0) return 1;
if(IsCuffed[i] == 1 && cuff_arrest_time[i] == 0)
{
ARREST(playerid,i);
}
CUFF(playerid,i);
}
return 1;
}
stock GetClosestPlayer(playerid) {
new idx=-1,Float:x,Float:y,Float:z;
GetPlayerPos(playerid,x,y,z);
for(new i=GetPlayerPoolSize()+1,Float:tmp,Float:max=3000.0; --i!=-1; ) {
if(!IsPlayerConnected(i) || IsPlayerNPC(i) || i==playerid) continue;
tmp = GetPlayerDistanceFromPoint(i,x,y,z);
if(tmp < max) max=tmp,idx=i;
}
return idx;
}
You say it
I am so friendly and solve this "problem" for you Here you go: PHP код:
|
Originally Posted by Mowgli;
That for loop looks strange to me.
|