HELP WITH /ROB COMMAND
#1

Hi , with this command you need to put the player id that you want to rob , i want that the player dont need to put any id , when put /rob rob the nearest player
Код:
 if(strcmp(cmd, "/rob", true) == 0)
   {
       tmp = strtok(cmdtext, idx);
       if(strlen(tmp) == 0) return SendClientMessage(playerid, ERROR, "Use: /rob [ID]");
       else
       {
          if(IsPlayerSpawned(playerid))
          {
            if(gTeam[playerid] == CIVILIAN)
            {
                if(strval(tmp) != playerid)
                {
                  if(!IsPlayerInAnyVehicle(playerid))
                  {
                      if(!IsPlayerInAnyVehicle(strval(tmp)))
                      {
                          if(IsPlayerConnected(strval(tmp)))
                          {
                                  if(GetPlayerMoney(strval(tmp) > 0))
                                  {
                                      if(GetDistanceBetweenPlayers(playerid, strval(tmp)) <= 8)
                                      {
                                     if(RecentlyRobbed[strval(tmp)] == 0)
                                     {
                                    if(GetPlayerMoney(strval(tmp)) > 4999)
                                    {
                                        new string[250], string2[250], string3[250], robbedcash, robbedname[MAX_PLAYER_NAME], robbername[MAX_PLAYER_NAME];
                                        robbedcash = random(5000);
                                        GetPlayerName(playerid, robbername, sizeof(robbername));
                                        GetPlayerName(strval(tmp), robbedname, sizeof(robbedname));
                                        format(string, sizeof(string), "You have robbed $%d from %s[ID:%d]", robbedcash, robbedname, strval(tmp));
                                        SendClientMessage(playerid, SERVER_COLOR, string);
                                        format(string2, sizeof(string2), "%s[ID:%d] has robbed $%d from you!", robbername, playerid, robbedcash);
                                        SendClientMessage(strval(tmp), RED, string2);
                                        format(string3, sizeof(string3), "[HQ] %s has robbed $%d from %s.", robbername, robbedname, robbedcash);
                                              SendRadioMessageToCops(string3);
                                       GivePlayerMoney(playerid, robbedcash);
                                       GivePlayerMoney(strval(tmp), -robbedcash);
                                       RecentlyRobbed[strval(tmp)] = 60;
                                       GivePlayerScore(playerid, 1);
                                       if(gTeam[strval(tmp)] == CIVILIAN)
                                       {
                                       SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 2);
                                       }
                                       if(gTeam[strval(tmp)] == COP || gTeam[strval(tmp)] == SWAT || gTeam[strval(tmp)] == FBI || gTeam[strval(tmp)] == ARMY || gTeam[strval(tmp)] == Medic)
                                       {
                                       SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5);
                                       }
                                       SetPlayerRobbingSkill(playerid, GetPlayerRobbingSkill(playerid)+1);
                                        return true;
                                    }
                                    else if(GetPlayerMoney(strval(tmp)) < 4999)
                                    {
                                       new string[250], recentlyrobber[MAX_PLAYER_NAME];
                                       GetPlayerName(strval(tmp), recentlyrobber, sizeof(recentlyrobber));
                                       format(string, sizeof(string), "%s[ID:%d] don't have enought money.", recentlyrobber, strval(tmp));
                                       return SendClientMessage(playerid, ERROR, string);
                                    }
                                    }
                                    else if(RecentlyRobbed[strval(tmp)] > 0)
                                    {
                                       new string[250], recentlyrobber[MAX_PLAYER_NAME];
                                       GetPlayerName(strval(tmp), recentlyrobber, sizeof(recentlyrobber));
                                       format(string, sizeof(string), "%s[ID:%d] has been robbed recently. Try again later.", recentlyrobber, strval(tmp));
                                       return SendClientMessage(playerid, ERROR, string);
                                    }
                                 else
                                 {
                                    new string[250], faraway[MAX_PLAYER_NAME];
                                     GetPlayerName(strval(tmp), faraway, sizeof(faraway));
                                     format(string, sizeof(string), "%s[ID:%d] is too far away.", faraway, strval(tmp));
                                    return SendClientMessage(playerid, ERROR, string);
                                 }
                              }
                              else if(GetPlayerMoney(strval(tmp)) == 0)
                              {
                                  new string[250], poor[MAX_PLAYER_NAME];
                                  GetPlayerName(strval(tmp), poor, sizeof(poor));
                                  format(string, sizeof(string), "%s[ID:%d] does not have any money.", poor, strval(tmp));
                                 return SendClientMessage(playerid, ERROR, string);
                              }
                           }
                        }
                        else if(!IsPlayerConnected(strval(tmp)))
                        {
                           new string[250];
                           format(string, sizeof(string), "ID %d is not connected.", strval(tmp));
                           return SendClientMessage(playerid, ERROR, string);
                        }
                     }
                     else if(IsPlayerInAnyVehicle(strval(tmp)))
                     {
                         new string[250], invehicle[MAX_PLAYER_NAME];
                         GetPlayerName(strval(tmp), invehicle, sizeof(invehicle));
                        format(string, sizeof(string), "%s[ID:%d] is in a vehicle. You cannot rob him.", invehicle, strval(tmp));
                        return SendClientMessage(playerid, ERROR, string);
                     }
                  }
                  else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "You cannot rob anyone from inside a vehicle.");
               }
               else return SendClientMessage(playerid, ERROR, "You cannot rob yourself.");
            }
            else return SendClientMessage(playerid, ERROR, "Only CIVILIANS can use this command!");
          }
       }
       return 1;
   }
Reply
#2

Код:
stock GetClosestPlayer(playerid)
{
    new Float:cdist, targetid = -1;
    ////foreach(Player, i)
    for(new i; i<MAX_PLAYERS; i++)
    {
        if (IsPlayerConnected(i) && playerid != i && (targetid < 0 || cdist > GetDistanceBetweenPlayers(playerid, i)))
        {
            targetid = i;
            cdist = GetDistanceBetweenPlayers(playerid, i);
        }
    }
    return targetid;
}


if(strcmp(cmd, "/rob", true) == 0)
   {
       new victim = GetClosestPlayer(playerid);
       else
       {
          if(IsPlayerSpawned(playerid))
          {
            if(gTeam[playerid] == CIVILIAN)
            {
                if(strval(victim) != playerid)
                {
                  if(!IsPlayerInAnyVehicle(playerid))
                  {
                      if(!IsPlayerInAnyVehicle(strval(victim)))
                      {
                          if(IsPlayerConnected(strval(victim)))
                          {
                                  if(GetPlayerMoney(strval(victim) > 0))
                                  {
                                      if(GetDistanceBetweenPlayers(playerid, strval(victim)) <= 8)
                                      {
                                     if(RecentlyRobbed[strval(victim)] == 0)
                                     {
                                    if(GetPlayerMoney(strval(victim)) > 4999)
                                    {
                                        new string[250], string2[250], string3[250], robbedcash, robbedname[MAX_PLAYER_NAME], robbername[MAX_PLAYER_NAME];
                                        robbedcash = random(5000);
                                        GetPlayerName(playerid, robbername, sizeof(robbername));
                                        GetPlayerName(strval(victim), robbedname, sizeof(robbedname));
                                        format(string, sizeof(string), "You have robbed $%d from %s[ID:%d]", robbedcash, robbedname, strval(victim));
                                        SendClientMessage(playerid, SERVER_COLOR, string);
                                        format(string2, sizeof(string2), "%s[ID:%d] has robbed $%d from you!", robbername, playerid, robbedcash);
                                        SendClientMessage(strval(tmp), RED, string2);
                                        format(string3, sizeof(string3), "[HQ] %s has robbed $%d from %s.", robbername, robbedname, robbedcash);
                                              SendRadioMessageToCops(string3);
                                       GivePlayerMoney(playerid, robbedcash);
                                       GivePlayerMoney(strval(victim), -robbedcash);
                                       RecentlyRobbed[strval(victim)] = 60;
                                       GivePlayerScore(playerid, 1);
                                       if(gTeam[strval(victim)] == CIVILIAN)
                                       {
                                       SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 2);
                                       }
                                       if(gTeam[strval(victim)] == COP || gTeam[strval(victim)] == SWAT || gTeam[strval(victim)] == FBI || gTeam[strval(victim)] == ARMY || gTeam[strval(victim)] == Medic)
                                       {
                                       SetPlayerWantedLevel(playerid,GetPlayerWantedLevel(playerid)+ 5);
                                       }
                                       SetPlayerRobbingSkill(playerid, GetPlayerRobbingSkill(playerid)+1);
                                        return true;
                                    }
                                    else if(GetPlayerMoney(strval(victim)) < 4999)
                                    {
                                       new string[250], recentlyrobber[MAX_PLAYER_NAME];
                                       GetPlayerName(strval(victim), recentlyrobber, sizeof(recentlyrobber));
                                       format(string, sizeof(string), "%s[ID:%d] don't have enought money.", recentlyrobber, strval(victim));
                                       return SendClientMessage(playerid, ERROR, string);
                                    }
                                    }
                                    else if(RecentlyRobbed[strval(victim)] > 0)
                                    {
                                       new string[250], recentlyrobber[MAX_PLAYER_NAME];
                                       GetPlayerName(strval(victim), recentlyrobber, sizeof(recentlyrobber));
                                       format(string, sizeof(string), "%s[ID:%d] has been robbed recently. Try again later.", recentlyrobber, strval(victim));
                                       return SendClientMessage(playerid, ERROR, string);
                                    }
                                 else
                                 {
                                    new string[250], faraway[MAX_PLAYER_NAME];
                                     GetPlayerName(strval(tmp), faraway, sizeof(faraway));
                                     format(string, sizeof(string), "%s[ID:%d] is too far away.", faraway, strval(victim));
                                    return SendClientMessage(playerid, ERROR, string);
                                 }
                              }
                              else if(GetPlayerMoney(strval(victim)) == 0)
                              {
                                  new string[250], poor[MAX_PLAYER_NAME];
                                  GetPlayerName(strval(tmp), poor, sizeof(poor));
                                  format(string, sizeof(string), "%s[ID:%d] does not have any money.", poor, strval(victim));
                                 return SendClientMessage(playerid, ERROR, string);
                              }
                           }
                        }
                        else if(!IsPlayerConnected(strval(victim)))
                        {
                           new string[250];
                           format(string, sizeof(string), "ID %d is not connected.", strval(victim));
                           return SendClientMessage(playerid, ERROR, string);
                        }
                     }
                     else if(IsPlayerInAnyVehicle(strval(victim)))
                     {
                         new string[250], invehicle[MAX_PLAYER_NAME];
                         GetPlayerName(strval(victim), invehicle, sizeof(invehicle));
                        format(string, sizeof(string), "%s[ID:%d] is in a vehicle. You cannot rob him.", invehicle, strval(victim));
                        return SendClientMessage(playerid, ERROR, string);
                     }
                  }
                  else if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, ERROR, "You cannot rob anyone from inside a vehicle.");
               }
               else return SendClientMessage(playerid, ERROR, "You cannot rob yourself.");
            }
            else return SendClientMessage(playerid, ERROR, "Only CIVILIANS can use this command!");
          }
       }
       return 1;
   }
This should work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)