CMD:ddealer(playerid, params[])
{
new string[128], targetid;
// no drug dealers online
if(PlayerInfo[playerid][pSkill] == SKILL_DRUGDEALER) return SendClientMessage(playerid, COLOR_RED, "You are already a drug dealer, you cannot use this command.");
targetid = GetClosestDDealer(playerid, 7.0);
if(targetid == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED, "Sorry! There are no drug dealers online at the moment.");
if(targetid == ??) // when there are drug dealers online found but they are away from the playerid
{
SendClientMessage(playerid, COLOR_WHITE, "You have {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}to your current location!");
format(string, sizeof(string), "%s(%d) {FFFFFF}has {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}at {B3B3B3}%s", GetName(playerid), playerid, GetPlayerLocation(playerid));
SendClientMessage(targetid, COLOR_COPS, string);
return 1;
}
//else if there a drug dealer near the playerid
ShowDDealerTextDraws(targetid, playerid);
format(string, sizeof(string), "%s(%d) {FFFFFF}is now taking a look on your list.", GetName(playerid), playerid);
SendClientMessage(targetid, COLOR_YELLOW, string);
format(string, sizeof(string), "You are now viewing {0040FF}%s(%i)'s {FFFFFF}list.", GetName(targetid), targetid);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
stock GetClosestDDealer(playerid, Float:dis)
{
new Float:dis2, player = INVALID_PLAYER_ID;
for(new x = 0; x < MAX_PLAYERS; x++)
{
if(!IsPlayerConnected(x)) continue;
if(GetPlayerState(x) == PLAYER_STATE_SPECTATING) continue;
if(x == playerid) continue;
if(PlayerTeam[x] != TEAM_CIV) continue;
if(PlayerInfo[x][pSkill] != SKILL_DRUGDEALER) continue;
dis2 = GetDistanceBetweenPlayers(x,playerid);
if(dis2 < dis && dis2 != -1.00)
{
dis = dis2;
player = x;
}
}
return player;
}
CMD:ddealer(playerid, params[])
{
new string[128], Float:x,Float:y,Float:z;
new targetid = GetClosestDDealer(playerid, 7.0);
GetPlayerPos(targetid,x,y,z);
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(PlayerInfo[i][pSkill] != SKILL_DRUGDEALER) return SendClientMessage(playerid,COLOR_RED, "Sorry! There are no drug dealers online at the moment.");
}
if(IsPlayerInRangeOfPoint(playerid,7,x,y,z))
{
ShowDDealerTextDraws(targetid, playerid);
format(string, sizeof(string), "%s(%d) {FFFFFF}is now taking a look on your list.", GetName(playerid), playerid);
SendClientMessage(targetid, COLOR_YELLOW, string);
format(string, sizeof(string), "You are now viewing {0040FF}%s(%i)'s {FFFFFF}list.", GetName(targetid), targetid);
SendClientMessage(playerid, COLOR_WHITE, string);
return 1;
}
SendClientMessage(playerid, COLOR_WHITE, "You have {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}to your current location!");
format(string, sizeof(string), "%s(%d) {FFFFFF}has {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}at {B3B3B3}%s", GetName(playerid), playerid, GetPlayerLocation(playerid));
SendClientMessage(targetid, COLOR_COPS, string);
return 1;
}
new dealerCount = 0;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(PlayerInfo[i][pSkill] == SKILL_DRUGDEALER)
dealerCount++;
}
if(dealerCount == 0) return SendClientMessage(playerid,COLOR_RED, "Sorry! There are no drug dealers online at the moment.");
You shouldn't be using return inside a loop because it will end the loop at the first player that isn't a drug dealer so if there is players after him that are drug dealers it will never get to them.
Try something like this: pawn Код:
|
CMD:ddealer(playerid, params[])
{
if(PlayerInfo[playerid][pSkill] == SKILL_DRUGDEALER) return SendClientMessage(playerid, COLOR_RED, "You are already a drug dealer, you cannot use this command.");
new targetid = INVALID_PLAYER_ID, Float:range = -1.0, count = 0, Float:x, Float:y, Float:z;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i)) continue;
if(i == playerid) continue;
if(GetPlayerState(i) == PLAYER_STATE_SPECTATING) continue;
if(PlayerTeam[i] != TEAM_CIV) continue;
if(PlayerInfo[i][pSkill] != SKILL_DRUGDEALER) continue;
count++;
GetPlayerPos(i, x, y, z);
new Float:newrange = GetPlayerDistanceFromPoint(playerid, x, y, z);
if((newrange > range) && (range != -1.0)) continue;
targetid = i;
range = newrange;
}
if(!count) return SendClientMessage(playerid,COLOR_RED, "Sorry! There are no drug dealers online at the moment.");
new string[145];
if(GetPlayerDistanceFromPoint(playerid, x, y, z) > 7.0)
{
SendClientMessage(playerid, COLOR_WHITE, "You have {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}to your current location!");
format(string, sizeof(string), "%s(%d) {FFFFFF}has {33CCFF}Requested {FFFFFF}a {C73041}Drug Dealer {FFFFFF}at {B3B3B3}%s", GetName(playerid), playerid, GetPlayerLocation(playerid));
SendClientMessage(targetid, COLOR_COPS, string);
}
else
{
ShowDDealerTextDraws(targetid, playerid);
format(string, sizeof(string), "%s(%d) {FFFFFF}is now taking a look on your list.", GetName(playerid), playerid);
SendClientMessage(targetid, COLOR_YELLOW, string);
format(string, sizeof(string), "You are now viewing {0040FF}%s(%i)'s {FFFFFF}list.", GetName(targetid), targetid);
SendClientMessage(playerid, COLOR_WHITE, string);
}
return 1;
}