Help plz
#1

I just made a command to some thing when an admin type /async playerid or part of name.

But the command works fine with playerid, when ever i use a name or part of it, it just does the command to id 0. can some one help to fix it

pawn Код:
new cmd[256];
  new idx;
  cmd = strtok(cmdtext, idx);
    new tmp[256];
    new giveplayer[MAX_PLAYER_NAME];
    new sendername[MAX_PLAYER_NAME];
  if(strcmp(cmd, "/async", true) == 0)
  {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /async [playerid/PartOfName]");
            return 1;
        }
        new playa;
        if(IsStringAName(tmp))
        {
            playa = GetPlayerID(tmp);
        }
        else
        {
            playa = strval(tmp);
        }
        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
        GetPlayerName(playerid, sendername, sizeof(sendername));
        if(GetAdminLevel(playerid) >= 2)
        {
      if(GetPlayerState(playa) == 9|| GetPlayerState(playa) == 5 || GetPlayerState(playa) == 6 ||GetPlayerState(playa) == 4|| GetPlayerState(playa) == 0)
            {
                SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization");
                return 1;
            }
            if(IsPlayerInAnyVehicle(playa))
            {
            SendClientMessage(playerid,COLOR_YELLOW," Unable to start synchronization while in a vehicle");
            return 1;
            }
            new string1[128];
            new string2[128];
            sync[playa] = 1;
            SyncPlayer(playa);
            format(string1, sizeof(string1), "%s has synced you",sendername);
            format(string2, sizeof(string2), "You have synced %s",giveplayer);
            SendClientMessage(playa, COLOR_WHITE, string1);
            SendClientMessage(playerid, COLOR_WHITE, string2 );
        }
        else
        {
            SendClientMessage(playerid, COLOR_YELLOW,"You are not authorized to use this command!");
        }
        return 1;
  }
and the function for it are
pawn Код:
forward GetPlayerID(string[]);
public GetPlayerID(string[])
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) == 1)
        {
            new testname[MAX_PLAYER_NAME];
            GetPlayerName(i, testname, sizeof(testname));
            if(strcmp(testname, string, true, strlen(string)) == 0)
            {
                return i;
            }
        }
    }
    return INVALID_PLAYER_ID;
}

forward IsStringAName(string[]);
public IsStringAName(string[])
{
    for(new i = 0; i <= MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) == 1)
        {
            new testname[MAX_PLAYER_NAME];
            GetPlayerName(i, testname, sizeof(testname));
            if(strcmp(testname, string, true, strlen(string)) == 0)
            {
                return 1;
            }
        }
    }
    return 0;
}
Reply


Messages In This Thread
Help plz - by cloud9 - 19.07.2009, 09:15
Re: Help plz - by cloud9 - 19.07.2009, 09:42

Forum Jump:


Users browsing this thread: 1 Guest(s)