SA-MP Forums Archive
[Help] /stats CMD fix - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Help] /stats CMD fix (/showthread.php?tid=154308)



[Help] /stats CMD fix - Thrarod - 13.06.2010

I made a command that shows your stats but HP and Armor doesnt show right like;

Health is 90 but shows 1, health is 100 but shows 1
Armor is 0 but shows 1, armor is 80 but shows 1

Code
pawn Код:
if(strcmp(cmdtext, "/stats", true) == 0)
    {
      new StatMSG[128];
        new pName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pName, sizeof(pName));
        new Float:pHealth;
        new Float:pArmour;
      format(StatMSG,sizeof(StatMSG),"[Stats] Name: %s, Health: %d, Armor: %d, Money: %d", pName, GetPlayerHealth(playerid, pHealth), GetPlayerArmour(playerid, pArmour), GetPlayerMoney(playerid));
        if (Job[playerid] == 0) {
        SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
        SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Cop");
        }else if (Job[playerid] == 1) {
        SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
        SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Criminal");
        }else if (Job[playerid] == 255) {
        SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
        SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: None");
        }
        return 1;
    }



Re: [Help] /stats CMD fix - Dark_Kostas - 13.06.2010

At formats you need to use %f for float, not %d and also it wont work like that
pawn Код:
if(strcmp(cmdtext, "/stats", true) == 0)
{
    new StatMSG[128];
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    new Float:pHealth;
    new Float:pArmour;
    GetPlayerHealth(playerid, pHealth);
    GetPlayerArmour(playerid, pArmour);
    format(StatMSG,sizeof(StatMSG),"[Stats] Name: %s, Health: %f, Armor: %f, Money: %d", pName, pHealth, pArmour, GetPlayerMoney(playerid));
    if (Job[playerid] == 0) {
    SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
    SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Cop");
    }else if (Job[playerid] == 1) {
    SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
    SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Criminal");
    }else if (Job[playerid] == 255) {
    SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
    SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: None");
    }
    return 1;
}
EDIT: I did some stupid things before, check again the code if you have already.


Re: [Help] /stats CMD fix - Thrarod - 13.06.2010

Changed anything?


Re: [Help] /stats CMD fix - DJDhan - 13.06.2010

Код:
if(strcmp(cmdtext, "/stats", true,6) == 0)
{
	new StatMSG[128];
	new pName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName, sizeof(pName));
	new Float:pHealth;
	new Float:pArmour;
       GetPlayerHealth(playerid, pHealth); 
	GetPlayerArmour(playerid, pArmour);
	
	format(StatMSG,sizeof(StatMSG),"[Stats] Name: %s, Health: %f, Armor: %f, Money: %d", pName, pHealth, pArmour, GetPlayerMoney(playerid));
	
	if (Job[playerid] == 0) 
	{
		SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
		SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Cop");
	}
	else if (Job[playerid] == 1) 
	{
		SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
		SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Criminal");
	}
	else if (Job[playerid] == 255) 
	{
		SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
		SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: None");
	}
	return 1;
}



Re: [Help] /stats CMD fix - Dark_Kostas - 13.06.2010

Quote:
Originally Posted by Thrarod
Changed anything?
Yes look it again.

DJDhan your code wont work. GetPlayerArmour and GetPlayerHealth doesnt return anything if you use it like that.


Re: [Help] /stats CMD fix - TheInnocentOne - 13.06.2010

Uhm none of that code will work. You need to get the health and armour into the floats BEFORE formatting the string. GetPlayerArmour and GetPlayerHealth do not return anything..

Replace your command with this code:

pawn Код:
if(strcmp(cmdtext, "/stats", true) == 0)
{
  new StatMSG[128];
     new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
new Float:pHealth;
new Float:pArmour;
GetPlayerHealth(playerid, pHealth);
GetPlayerArmour(playerid, pArmour);
  format(StatMSG,sizeof(StatMSG),"[Stats] Name: %s, Health: %f, Armor: %f, Money: %d", pName, pHealth, pArmour, GetPlayerMoney(playerid));
if (Job[playerid] == 0) {
SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Cop");
}else if (Job[playerid] == 1) {
SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: Criminal");
}else if (Job[playerid] == 255) {
SendClientMessage(playerid, COLOR_FLBLUE, StatMSG);
SendClientMessage(playerid, COLOR_FLBLUE, "[Stats] Job: None");
}
return 1;
}



Re: [Help] /stats CMD fix - DJDhan - 13.06.2010

Quote:
Originally Posted by Dark_Kostas
Quote:
Originally Posted by Thrarod
Changed anything?
Yes look it again.

DJDhan your code wont work. GetPlayerArmour and GetPlayerHealth doesnt return anything if you use it like that.
Well I edited it when I found out about my error.


Re: [Help] /stats CMD fix - TheInnocentOne - 13.06.2010

I already posted the correct code


Re: [Help] /stats CMD fix - Thrarod - 13.06.2010

Yeah yours is right but only %f may go crazy like 91.324123412151 etc. so changed to %0.f,

Thanks all, also TIO, PM me


Re: [Help] /stats CMD fix - Dark_Kostas - 13.06.2010

Quote:
Originally Posted by TheInnocentOne
Uhm none of that code will work. You need to get the health and armour into the floats BEFORE formatting the string. GetPlayerArmour and GetPlayerHealth do not return anything..

Replace your command with this code:
which is the difference between mine and yours? except that your code is not indicated?