Szerző Téma: strcmp  (Megtekintve 645 alkalommal)

strcmp
« Dátum: 2011. November 10. - 14:43:28 »
0 Show voters
Hi.
Mit ronthattam el, hogy az alábbi néhány sor használata esetén mindig a 2. lehetõséget hajtja végre?
[pawn]new string[256];
new n[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
    GetPlayerName(i, n, sizeof(n));
   if(!strcmp(n, \"Anonym\", true))
   {
       format(string, sizeof(string), \"%s%s: {FFFF00}[%d] {FFFFFF}%s\", GetColorCode(), BotName, i, BotText);
   }
   else
   {
       format(string, sizeof(string), \"%s%s: {FFFFFF}%s\", GetColorCode(), BotName, BotText);
   }
}
SendClientMessageToAll(0xFFFFFFFF, string);[/pawn]
Mindig ez történik, ha fennvan az Anonym nevû játékos ill. én esetembenaz Anonym nevû NPC, ha nincs:
 [pawn]format(string, sizeof(string), \"%s%s: {FFFFFF}%s\", GetColorCode(), BotName, BotText);[/pawn]

strcmp
« Válasz #1 Dátum: 2011. November 10. - 14:58:44 »
0 Show voters
Próbáld így:
[pawn]if(!strcmp(\"Anonym\",n,true))[/pawn]

strcmp
« Válasz #2 Dátum: 2011. November 10. - 15:05:17 »
0 Show voters
Jelenleg így néz ki:
[pawn]   new string[256];
new n[MAX_PLAYER_NAME];
for(new i = 0; i < MAX_PLAYERS; i++)
{
    GetPlayerName(i, n, sizeof(n));
   if(!strcmp(\"Anonym\",n,true))
   {
       format(string, sizeof(string), \"%s%s: {FFFF00}[%d] {FFFFFF}%s\", GetColorCode(), BotName, i, BotText);
   }
   else if(!strcmp(\"Anonym\",n,false))
   {
       format(string, sizeof(string), \"%s%s: {FFFFFF}%s\", GetColorCode(), BotName, BotText);
   }
}
SendClientMessageToAll(0xFFFFFFFF, string);[/pawn]
Ha fentvan Anonym a szerón akk id helyére 499-t ír -.-
Ha nincs fenn akk egy üres üzenetet küld el.

Dupla hozzászólás automatikusan összefûzve. ( 2011. November 10. - 16:00:49 )

EDIT:
Most így néz ki:
[pawn]   new string[256];
new n[MAX_PLAYER_NAME];
    new bool:found;
    new foundid;
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(i))
   {
       GetPlayerName(i,n,sizeof(n));
      if(!strcmp(n,\"Anonym\",false))continue;
      else
      {
          found = true;
          foundid = i;
          break;
      }
   }
}
if(found == true)
{
   format(string, sizeof(string), \"%s%s: {FFFF00}[%d] {FFFFFF}%s\", GetColorCode(), BotName, foundid, BotText);
}
else if(found == false)
{
       format(string, sizeof(string), \"%s%s: {FFFFFF}%s\", GetColorCode(), BotName, BotText);
}
SendClientMessageToAll(0xFFFFFFFF, string);[/pawn]
Viszont most mindig ír ID-t, és mindig a legelsõ játékos ID-jét írja aki természetesen nem NPC... -.- xD Ötlet?

Dupla hozzászólás automatikusan összefûzve. ( 2011. November 10. - 16:48:55 )

Megoldva:
[pawn]new string[256];
    new found = 0;
    new foundid;
for(new i = 0; i < MAX_PLAYERS; i++)
{
   if(IsPlayerConnected(i))
   {
      if(!strcmp(PlayerName(i),\"Anonym\",true) && IsPlayerNPC(i))
      {
         found++;
         foundid = i;
         break;
         }
   }
}
if(found > 0)
{
   format(string, sizeof(string), \"%s%s: {FFFF00}[%d] {FFFFFF}%s\", GetColorCode(), BotName, foundid, BotText);
}
else if(found == 0)
{
       format(string, sizeof(string), \"%s%s: {FFFFFF}%s\", GetColorCode(), BotName, BotText);
}
SendClientMessageToAll(0xFFFFFFFF, string);[/pawn]
zárok
« Utoljára szerkesztve: 2011. November 10. - 16:48:55 írta staubka »

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal