foreach?
#1

Hello, so I've this CMD:
pawn Код:
CMD:showcontrats(playerid, params[])
{
      if(HitContract[playerid] < 1) return 1;
      new name[MAX_PLAYER_NAME+1];
      SendClientMessage(playerid, -1, "--------- List of the contracts -----------");
      foreach(new i : Player) // line 801
      {
            if(Hitman[i]) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
      }
      return 1;
}
And, I am getting these errors, even though I've included foreach, and downloaded it.

pawn Код:
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(801) : error 017: undefined symbol "foreach"
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(801) : error 029: invalid expression, assumed zero
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(801) : error 017: undefined symbol "i"
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(801) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
Thanks in advance.
Reply
#2

You need include foreach.inc: http://pastebin.com/Seseuh2x
Second, you have incorrect foreach:
pawn Код:
CMD:showcontrats(playerid, params[])
{
      if(HitContract[playerid] < 1) return 1;
      new name[MAX_PLAYER_NAME+1];
      SendClientMessage(playerid, -1, "--------- List of the contracts -----------");
      foreach(Player,i)
      {
            if(Hitman[i]) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
      }
      return 1;
}
Reply
#3

Did you included foreach.inc in your pawno\include folder ?
Reply
#4

Quote:
Originally Posted by MacT
Посмотреть сообщение
You need include foreach.inc: http://pastebin.com/Seseuh2x
Second, you have incorrect foreach:
pawn Код:
CMD:showcontrats(playerid, params[])
{
      if(HitContract[playerid] < 1) return 1;
      new name[MAX_PLAYER_NAME+1];
      SendClientMessage(playerid, -1, "--------- List of the contracts -----------");
      foreach(Player,i)
      {
            if(Hitman[i]) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
      }
      return 1;
}
Thanks, the foreach is now fixed.

Quote:
Originally Posted by Rittik
Посмотреть сообщение
Did you included foreach.inc in your pawno\include folder ?
Yeah, thanks.

Another problem accured, with this line:
pawn Код:
if(Hitman[i]) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
It sais it has arguments mismatch. :/
Reply
#5

pawn Код:
if(Hitman[i]==1(or any other value according to your script)) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
Reply
#6

pawn Код:
...  SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
You need to use format first and then send the formatted string in SendClientMessage function.
Reply
#7

pawn Код:
if(Hitman[i]==1) GetPlayerName(i, name, sizeof(name)), SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
Getting these:

pawn Код:
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(763) : warning 202: number of arguments does not match definition
C:\Users\Arty\Desktop\CesarLT\gamemodes\FCG.pwn(763) : warning 202: number of arguments does not match definition
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


2 Warnings.
:O Sorry for the struggle.
Reply
#8

Quote:
Originally Posted by ******
Посмотреть сообщение
All the information in MacT's post is wrong. Your original code was correct - the format he posted hasn't been used for literally years! Check the foreach topic for more up-to-date versions of the include.
If my code was correct, why am I getting 4 errors?
Reply
#9

Because your code is wrong. I already explained it above that you need to use format and not to pass arguments in SendClientMessage function like it's format function - it is not.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
...  SendClientMessage(playerid, -1, "- Target : %s || Amount : %i", name, GetPVarInt(i, "hitmanmoney"));
You need to use format first and then send the formatted string in SendClientMessage function.
That's your code which is incorrect ^.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)