SA-MP Forums Archive
foreach? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: foreach? (/showthread.php?tid=517533)



foreach? - CesarLT - 05.06.2014

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.


Re: foreach? - MacT - 05.06.2014

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;
}



Re: foreach? - Rittik - 05.06.2014

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


Re: foreach? - CesarLT - 05.06.2014

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. :/


Re: foreach? - Rittik - 05.06.2014

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"));



Re: foreach? - Konstantinos - 05.06.2014

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.


Re: foreach? - CesarLT - 05.06.2014

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.


Re: foreach? - CesarLT - 05.06.2014

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?


Re: foreach? - Konstantinos - 05.06.2014

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 ^.