Loop problem
#1

hi, guys can someone tell me why my ping code doesn't work?
I tried a lot of times to fix that but nothing happens. (lol I never liked loops)
i hope u can tell me what i did wrong so i can learn about that.
pawn Код:
public player_ping(playerid)
{
   new string[256];
   new ping[playerid];
   for(new i=0; i<MAX_PLAYERS; i++)
   ping=GetPlayerPing(playerid);
   format(string,sizeof(string),"ping: %d",ping[playerid]);
   SendClientMessage(i,COLOR_LILA,string);
}
sry i forgot to tell u what actually should do the code. It has to send a message to the player who wanna see his ping.
Reply
#2

Код:
public player_ping(playerid)
{
   new string[256];
   new ping[playerid];
   for(new i=0; i<MAX_PLAYERS; i++)
   {
   ping=GetPlayerPing(i);
   format(string,sizeof(string),"ping: %d",ping[i]);
   SendClientMessage(i,COLOR_LILA,string);
   }
}
i think now works
Reply
#3

htanks for the anwser but it still doesen't work. (lol i thought it isn't relevant to set brackets to a for loop)
Can u or someone fix that or explain me my mistake pls.
Reply
#4

Код:
public player_ping()
{
   new string[256];
   new ping;
   for(new i; i<MAX_PLAYERS; i++)
   {
   ping=GetPlayerPing(i);
   format(string,sizeof(string),"ping: %d",ping);
   SendClientMessage(i,COLOR_LILA,string);
   }
}
Try this..
Reply
#5

thanks but i get errors if i compile your code
Reply
#6

What errors? and.. send me bigger part of your code please..
Reply
#7

When you do that loop it makes playerid to i.

With loop this will be correct:
SetPlayerScore(i, 1234);

without loop this will be correct:
SetPlayerScore(playerid, 1234);
Reply
#8

ok here the rest of the code:
pawn Код:
forward player_ping(playerid);
pawn Код:
SetTimer("player_ping", 250, true); //ONGamemodeInit
pawn Код:
public player_ping(playerid)
{
   new string[256];
   new ping[playerid];
   for(new i=0; i<MAX_PLAYERS; i++)
   {
   ping=GetPlayerPing(i);
   format(string,sizeof(string),"ping: %d",ping);
   SendClientMessage(i,COLOR_LILA,string);
   }
}
hope this wil help u
Reply
#9

Quote:
Originally Posted by nesty
ok here the rest of the code:
pawn Код:
forward player_ping(playerid);
pawn Код:
SetTimer("player_ping", 250, true); //ONGamemodeInit
pawn Код:
public player_ping(playerid)
{
  new string[256];
  new ping[playerid];
  for(new i=0; i<MAX_PLAYERS; i++)
  {
  ping=GetPlayerPing(i);
  format(string,sizeof(string),"ping: %d",ping);
  SendClientMessage(i,COLOR_LILA,string);
  }
}
hope this wil help u
This will not help...
Why to do: forward player_ping(playerid); when it is under game mode init? USE: forward player_ping();
and
pawn Код:
public player_ping()
{
   new string[50];
   new ping;
   for(new i; i<GetMaxPlayers(); i++)
   {
   ping = GetPlayerPing(i);
   format(string,sizeof(string),"ping: %d",ping);
   SendClientMessage(i,COLOR_LILA,string);
   }
}
Reply
#10

hey thanks its work perfectly really thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)