Author Topic: Bug command. I don't know whats bugged. Can't fix it  (Read 2490 times)

0 Members and 2 Guests are viewing this topic.

Offline saberman

  • Street Thug
  • *
  • Posts: 22
    • View Profile
Bug command. I don't know whats bugged. Can't fix it
« on: May 26, 2011, 03:25:24 pm »
Code: (Pawn) [Select]
else if(strcmp(cmd, "wepequip", true) == 0)
{
   new tmp2[126], tmp3[126], wep[126]; tmp = strtok(cmdtext, idx), tmp2 = strtok(cmdtext, idx), tmp3 = strtok(cmdtext, idx); new targetname[32]; targetname[0] = FindPlayerIDFromString(tmp);
   wep[0] = FindWepIDFromString(tmp2); new fbil[126];
   fbil = dini_Get(file, "FBI");
   if(strval(fbil) > 2) SendClientMessage(playerid, RED, "You have to be Agent+ to use this command!");
   else if(!strlen(tmp3)) SendClientMessage(playerid, RED, "USAGE: /c wepequip [id] [weapon] [ammo]");
   else
   {
  printf("%s(%d) has given %s(%d) weapon %s ammo %d - /c wepequip", gPlayers[playerid], playerid, gPlayers[strval(targetname)], strval(targetname), wep, tmp3);
  format(szMsg, 256, "You have been issued %s with %d ammo", wep, tmp3);
  SendClientMessage(strval(targetname), GREEN, szMsg);
  format(szMsg, 256, "You issued %s with %d ammo to %s(%d)", wep, tmp3, gPlayers[strval(targetname)], strval(targetname));
  SendClientMessage(playerid, GREEN, szMsg);
  SetPlayerWeapon(strval(targetname), strval(wep), strval(tmp3));
   }
   return 1;
}
Quote
        format(szMsg, 256, "You have been issued %s with %d ammo", wep, tmp3, gPlayers[strval(targetname)], strval(targetname));
It says: "You have been issued   with 40-50(like that) ammo"
Also, it deletes all my weapons and ammo. I don't see whats bugged. Help me!

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Bug command. I don't know whats bugged. Can't fix it
« Reply #1 on: May 26, 2011, 10:29:21 pm »
[pawn]
      new wep[126]; new targetname[32]; targetname[0] = FindPlayerIDFromString(tmp);
      wep[0] = FindWepIDFromString(tmp2);
[/pawn]
There's no need to use arrays for these. This is sufficient:

[pawn]
new wep; new targetname;
targetname = FindPlayerIDFromString(tmp);
wep = FindWepIDFromString(tmp2);
[/pawn]

[pawn]
        printf("%s(%d) has given %s(%d) weapon %s ammo %d - /c wepequip", gPlayers[playerid], playerid, gPlayers[strval(targetname)], strval(targetname), wep, tmp3);
        format(szMsg, 256, "You have been issued %s with %d ammo", wep, tmp3);
[/pawn]
Replace with:

[pawn]
printf("%s(%d) has given %s(%d) weapon %s ammo %d - /c wepequip", gPlayers[playerid], playerid, gPlayers[targetname], targetname, gWeapons[wep], strval(tmp3));
format(szMsg, 256, "You have been issued %s with %d ammo", gWeapons[wep], strval(tmp3));
[/pawn]

[pawn]
        format(szMsg, 256, "You issued %s with %d ammo to %s(%d)", wep, tmp3, gPlayers[strval(targetname)], strval(targetname));
        SendClientMessage(playerid, GREEN, szMsg);
[/pawn]
This isn't necessary since everyone is going to see the "ADMIN (0) has given PLAYER( 1) weapon GUN ammo 9999." including the admin.

[pawn]
SetPlayerWeapon(strval(targetname), strval(wep), strval(tmp3));
[/pawn]
Replace with:

[pawn]
SetPlayerWeapon(targetname, wep, strval(tmp3));
[/pawn]

The main problem was that you were trying to set the weapon and player in an array. However, numbers in an array can also be parsed as a string, so strval might's seen it as "Q." This isn't an integer, and can lead to some odd results. See if the suggestions I posted above work.
Do not PM me for support.




Offline saberman

  • Street Thug
  • *
  • Posts: 22
    • View Profile
Re: Bug command. I don't know whats bugged. Can't fix it
« Reply #2 on: May 27, 2011, 05:15:34 pm »
Its fixed, thank you for your help.