14.10.2014, 17:22
(
Последний раз редактировалось Juvanii; 14.10.2014 в 18:28.
)
I tried to make a command returns 3 things but it didn't success as well!
The command is /ddealer to request a drug dealer!
1. No Drug Dealers are online (If the playerid typed the command but no ddealers found)
2. Drug Dealers Far Away (If the playerid typed the command while he is far away from drug dealers)
3. Drug Dealers Near playerid (It explains itself)
Here is a sample of the command, please somebody tell me how to fix all of these mess:
Edit: Everything fixed now but if i remove the loop from the code below.
When adding it: it always return the message even if there are drug dealers online.
Without it: Command works fine for the "Near" and "Far Away"!
The command is /ddealer to request a drug dealer!
1. No Drug Dealers are online (If the playerid typed the command but no ddealers found)
2. Drug Dealers Far Away (If the playerid typed the command while he is far away from drug dealers)
3. Drug Dealers Near playerid (It explains itself)
Here is a sample of the command, please somebody tell me how to fix all of these mess:
pawn Код:
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;
}
When adding it: it always return the message even if there are drug dealers online.
Without it: Command works fine for the "Near" and "Far Away"!
pawn Код:
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;
}