What's wrong with cmd?
#1

My /taze command works perfectly fine. Except, When i /taze a suspect, it says "USAGE USAGE: /taze (id) when it already worked.

It's only suppose to say that, if i typed /taze only without an ID.

pawn Код:
if(strcmp(cmd, "/taze", true) == 0)
{
  for(new i=0; i < MAX_PLAYERS; i++) {
    if(IsSpawned[playerid] == 0) {
      SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
      return 1;
    }
    if(gTeam[playerid] != TEAM_COP && gTeam[playerid] != TEAM_ARMY && gTeam[playerid] != TEAM_MARINE && gTeam[playerid] != TEAM_AIRSUPPORT) {
      SendClientMessage(playerid, COLOR_ERROR, "Only Law Enforcement can use this command");
      return 1;
    }
    if(InDerby[playerid] == 1) {
      SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
      return 1;
    }
    if(Jailed[playerid] == 1) {
      SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
      return 1;
    }
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) {
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id)");
    return 1;
    }
    if(!IsNumeric(tmp)) {
    SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id) ID Must be a number");
    return 1;
    }
    giveplayerid = strval(tmp);
    if(!IsPlayerConnected(giveplayerid)) {
      format(szstring, sizeof(szstring), "ID (%d) is not an active player", giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(gTeam[playerid] == TEAM_COP && gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_MARINE && gTeam[playerid] == TEAM_AIRSUPPORT) {
      SendClientMessage(playerid, COLOR_ERROR, "You cannot taze another Law Enforcement agent");
      return 1;
    }
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);
    if(GetPlayerWantedLevel(giveplayerid) <= 3) {
      format(szstring, sizeof(szstring), "%s(%d) Does not have a warrant. You cannot use your tazer on this player",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10) {
      format(szstring, sizeof(szstring), "%s(%d) Is not close enough to taze",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(cuffed[giveplayerid] == 1) {
      format(szstring, sizeof(szstring), "%s(%d) Is in handcuffs and is restrained. You cannot taze a handcuffed player",pname, giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(giveplayerid)) {
      format(szstring, sizeof(szstring), "%s(%d) Is in a vehicle. Get the player out the vehicle then use your tazer",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(playerid)) {
      SendClientMessage(playerid, COLOR_ERROR, "You cannot taze a player from inside a vehicle");
      return 1;
    }
    if(Tazed[giveplayerid] == 1) {
      format(szstring, sizeof(szstring), "%s(%d) Is being tazed right now. You cannot taze a player while the player is being tazed",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
    }
    else {

      Tazed[giveplayerid] =1;
      new tazername[30];
      GetPlayerName(playerid,tazername,30);
      format(szstring, sizeof(szstring), "Law Enforcement agent %s(%d) Has tazed suspect %s(%d)",tazername,playerid,pname,giveplayerid);
      SendClientMessageToAll(0x00C7FFAA, szstring);
      SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Law Enforcement Action_|");
      format(szstring, sizeof(szstring), "Officer %s(%d) Has tazed you", oname,playerid);
      SendClientMessage(giveplayerid,COLOR_DODGERBLUE, szstring);
      ApplyAnimation(giveplayerid,"PED","BIKE_fall_off",4.1,0,1,1,1,1);
      SetTimer("Tazingtime",3000,0);
      tazerank[i] +=1;
    }
  }
  return 1;
}
Reply
#2

Might work :

Код:
if(strcmp(cmdtext, "/taze", true) == 0)
{
 
    if(IsSpawned[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
     
    if(gTeam[playerid] != TEAM_COP && gTeam[playerid] != TEAM_ARMY && gTeam[playerid] != TEAM_MARINE && gTeam[playerid] != TEAM_AIRSUPPORT) return SendClientMessage(playerid, COLOR_ERROR, "Only Law Enforcement can use this command");
      
    if(InDerby[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
    
    if(Jailed[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
    
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id)");
   
    if(!IsNumeric(tmp)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id) ID Must be a number");
  
    giveplayerid = strval(tmp);
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);
    


    if(!IsPlayerConnected(giveplayerid)) 
    {
      format(szstring, sizeof(szstring), "(%d) is not an active player", giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(gTeam[playerid] == TEAM_COP && gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_MARINE && gTeam[playerid] == TEAM_AIRSUPPORT) return SendClientMessage(playerid, COLOR_ERROR, "You cannot taze another Law Enforcement agent");
    
    if(GetPlayerWantedLevel(giveplayerid) <= 3) 
    {
      format(szstring, sizeof(szstring), "%s (%d) Does not have a warrant. You cannot use your tazer on this player",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is not close enough to taze",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(cuffed[giveplayerid] == 1) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is in handcuffs and is restrained. You cannot taze a handcuffed player",pname, giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(giveplayerid)) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is in a vehicle. Get the player out the vehicle then use your tazer",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(playerid)) 
    {
      SendClientMessage(playerid, COLOR_ERROR, "You cannot taze a player from inside a vehicle");
      return 1;
    }
    if(Tazed[giveplayerid] == 1) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is being tazed right now. You cannot taze a player while the player is being tazed",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
    }
    
      Tazed[giveplayerid] =1;
      new tazername[30];
      GetPlayerName(playerid,tazername,30);
      format(szstring, sizeof(szstring), "Law Enforcement agent %s(%d) Has tazed suspect %s(%d)",tazername,playerid,pname,giveplayerid);
      SendClientMessageToAll(0x00C7FFAA, szstring);
      SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Law Enforcement Action_|");
      format(szstring, sizeof(szstring), "Officer %s(%d) Has tazed you", oname,playerid);
      SendClientMessage(giveplayerid,COLOR_DODGERBLUE, szstring);
      ApplyAnimation(giveplayerid,"PED","BIKE_fall_off",4.1,0,1,1,1,1);
      SetTimer("Tazingtime",3000,0);
      tazerank[i] +=1;
    
  }
  return 1;
}
Reply
#3

Quote:
Originally Posted by DJDhan
Might work :

Код:
if(strcmp(cmdtext, "/taze", true) == 0)
{
 
    if(IsSpawned[playerid] == 0) return SendClientMessage(playerid, COLOR_ERROR, "You are dead. You cannot use this command");
    
    if(gTeam[playerid] != TEAM_COP && gTeam[playerid] != TEAM_ARMY && gTeam[playerid] != TEAM_MARINE && gTeam[playerid] != TEAM_AIRSUPPORT) return SendClientMessage(playerid, COLOR_ERROR, "Only Law Enforcement can use this command");
     
    if(InDerby[playerid] == 1) return SendClientMessage(playerid,COLOR_ERROR,"You cannot use this command while you are in the stadium");
   
    if(Jailed[playerid] == 1) return SendClientMessage(playerid, COLOR_ERROR, "You cannot use this command in jail");
    
    tmp = strtok(cmdtext, idx);
    if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id)");
  
    if(!IsNumeric(tmp)) return SendClientMessage(playerid, COLOR_ERROR, "USAGE: /taze (id) ID Must be a number");
 
    giveplayerid = strval(tmp);
    GetPlayerName(playerid,oname, 24);
    GetPlayerName(giveplayerid, pname, 24);
    


    if(!IsPlayerConnected(giveplayerid)) 
    {
      format(szstring, sizeof(szstring), "(%d) is not an active player", giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(gTeam[playerid] == TEAM_COP && gTeam[playerid] == TEAM_ARMY && gTeam[playerid] == TEAM_MARINE && gTeam[playerid] == TEAM_AIRSUPPORT) return SendClientMessage(playerid, COLOR_ERROR, "You cannot taze another Law Enforcement agent");
   
    if(GetPlayerWantedLevel(giveplayerid) <= 3) 
    {
      format(szstring, sizeof(szstring), "%s (%d) Does not have a warrant. You cannot use your tazer on this player",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(GetDistanceBetweenPlayers(playerid,giveplayerid) > 10) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is not close enough to taze",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(cuffed[giveplayerid] == 1) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is in handcuffs and is restrained. You cannot taze a handcuffed player",pname, giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(giveplayerid)) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is in a vehicle. Get the player out the vehicle then use your tazer",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
      return 1;
    }
    if(IsPlayerInAnyVehicle(playerid)) 
    {
      SendClientMessage(playerid, COLOR_ERROR, "You cannot taze a player from inside a vehicle");
      return 1;
    }
    if(Tazed[giveplayerid] == 1) 
    {
      format(szstring, sizeof(szstring), "%s(%d) Is being tazed right now. You cannot taze a player while the player is being tazed",pname,giveplayerid);
      SendClientMessage(playerid, COLOR_ERROR, szstring);
    }
    
      Tazed[giveplayerid] =1;
      new tazername[30];
      GetPlayerName(playerid,tazername,30);
      format(szstring, sizeof(szstring), "Law Enforcement agent %s(%d) Has tazed suspect %s(%d)",tazername,playerid,pname,giveplayerid);
      SendClientMessageToAll(0x00C7FFAA, szstring);
      SendClientMessage(giveplayerid, 0xA9A9A9AA, "|_Law Enforcement Action_|");
      format(szstring, sizeof(szstring), "Officer %s(%d) Has tazed you", oname,playerid);
      SendClientMessage(giveplayerid,COLOR_DODGERBLUE, szstring);
      ApplyAnimation(giveplayerid,"PED","BIKE_fall_off",4.1,0,1,1,1,1);
      SetTimer("Tazingtime",3000,0);
      tazerank[i] +=1;
    
  }
  return 1;
}
Can you tell me what you changed to fix it? Also, I like having the code formated the way i have it lol....I havin't tested it, but can you tell me what you changed?
Reply
#4

Firstly: I removed the un-necessary if else brackets. You don't need them if you have a single function after a if statement.

Secondly: I removed the else condtion at the last which is not needed.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)