Szerző Téma: Rppont kiirás hiba  (Megtekintve 694 alkalommal)

Rppont kiirás hiba
« Dátum: 2011. Június 28. - 13:18:00 »
0 Show voters
CMD:rppont(playerid, params[])
{
    if(IsLogged[playerid] == 1)
{
    if(IsPlayerAdmin(playerid) ||   Info[playerid][admin] >= 2)
    {
        new id;
        if(sscanf(params, \"u\", id)) SendClientMessage(playerid, COLOR_WHITE, \"Használat: /rppont [iD]\");
          else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_WHITE, \"Nincs ilyen játékos!\");
          else
          {
              if(Info[id][rppontszam] != 0)
              {
                 new str[128];
         format(str,128,\"% jelenglegi állása: %d pontozás, átlag: %d\", Info[id][rppontszam],Info[id][rppont]/Info[id][rppontszam]);
         SendClientMessage(playerid, COLOR_WHITE, str);
         printf(\"%s használta a /rppont parancsot %s-ra\", PlrName(playerid), PlrName(id));
      }
      else
      {
         SendClientMessage(playerid, COLOR_WHITE, \"Az illetõnek nincs rppontja!\");
      }
   }
}
}
else
{
    SendClientMessage(playerid, COLOR_WHITE, \"Nem vagy bejelentkezve!\");
}
return 1;
}

 
Ha pontozások számát jól kiirja, de az átlagot nem. Mi lehet a baj?

Rppont kiirás hiba
« Válasz #1 Dátum: 2011. Június 28. - 15:16:22 »
0 Show voters
Mert egy átlag általában egy nem egész szám tehát float típusú. (0.34)
 
Idézetet írta: Detrot date=1309259880\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"9240\" data-ipsquote-contentclass=\"forums_Topic
format(str,128,\"% jelenglegi állása: %d pontozás, átlag: %d\", Info[id][rppontszam],Info[id][rppont]/Info[id][rppontszam]);
 
Próbáld ki így:
 

format(str,128,\"Jelenlegi állása: %d pontozás, átlag: %f\", Info[id][rppontszam], float( Info[id][rppont] / Info[id][rppontszam] ));

Rppont kiirás hiba
« Válasz #2 Dátum: 2011. Június 28. - 19:25:02 »
0 Show voters
CMD:rppont(playerid, params[])
{
    if(IsLogged[playerid] == 1)
{
    if(IsPlayerAdmin(playerid) || Info[playerid][admin] >= 2)
    {
        new id;
        if(sscanf(params, \"u\", id)) SendClientMessage(playerid, COLOR_WHITE, \"Használat: /rppont [iD]\");
          else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_WHITE, \"Nincs ilyen játékos!\");
          else
          {
              if(Info[id][rppontszam] != 0)
              {
                 new str[128];
                    new Float:atlag = Info[id][rppont]/Info[id][rppontszam];
         format(str,128,\"%s jelenglegi állása: %d pontozás, átlag: %.2f\", PlrName(id), Info[id][rppontszam], atlag);
         SendClientMessage(playerid, COLOR_WHITE, str);
         printf(\"%s használta a /rppont parancsot %s-ra\", PlrName(playerid), PlrName(id));
      }
      else
      {
         SendClientMessage(playerid, COLOR_WHITE, \"Az illetõnek nincs rppontja!\");
      }
   }
}
}
else
{
    SendClientMessage(playerid, COLOR_WHITE, \"Nem vagy bejelentkezve!\");
}
return 1;
}

 
Így se írja ki rendesen, csak egész számot ír ki:S
« Utoljára szerkesztve: 2011. Június 28. - 19:48:41 írta Detrot »

Rppont kiirás hiba
« Válasz #3 Dátum: 2011. Június 29. - 03:55:51 »
0 Show voters
Most lehet nagy baromságot mondok de hagyd ki a kettest a float-nál a formatban és úgy próbáld ki ha úgyse megy akkor passzolok...=/
Vampy

GroX

  • Vendég
Rppont kiirás hiba
« Válasz #4 Dátum: 2011. Június 30. - 11:14:39 »
0 Show voters
Idézetet írta: Detrot date=1309281902\" data-ipsquote-contentapp=\"forums\" data-ipsquote-contenttype=\"forums\" data-ipsquote-contentid=\"9240\" data-ipsquote-contentclass=\"forums_Topic

CMD:rppont(playerid, params[])
{
    if(IsLogged[playerid] == 1)
{
    if(IsPlayerAdmin(playerid) || Info[playerid][admin] >= 2)
    {
        new id;
        if(sscanf(params, \"u\", id)) SendClientMessage(playerid, COLOR_WHITE, \"Használat: /rppont [iD]\");
          else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, COLOR_WHITE, \"Nincs ilyen játékos!\");
          else
          {
              if(Info[id][rppontszam] != 0)
              {
                 new str[128];
                    new Float:atlag = Info[id][rppont]/Info[id][rppontszam];
         format(str,128,\"%s jelenglegi állása: %d pontozás, átlag: %.2f\", PlrName(id), Info[id][rppontszam], atlag);
         SendClientMessage(playerid, COLOR_WHITE, str);
         printf(\"%s használta a /rppont parancsot %s-ra\", PlrName(playerid), PlrName(id));
      }
      else
      {
         SendClientMessage(playerid, COLOR_WHITE, \"Az illetõnek nincs rppontja!\");
      }
   }
}
}
else
{
    SendClientMessage(playerid, COLOR_WHITE, \"Nem vagy bejelentkezve!\");
}
return 1;
}

 
Így se írja ki rendesen, csak egész számot ír ki:S
 
Zsolesszka errõl beszélt:
[pawn]format(str,128,\"Jelenlegi állása: %d pontozás, átlag: %f\", Info[id][rppontszam], float( Info[id][rppont] / Info[id][rppontszam] ));[/pawn]
Nem arról, hogy lebegõpontosként hozd is létre...

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal