SA-MP Forums Archive
I don't understand what is wrong here... - 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: I don't understand what is wrong here... (/showthread.php?tid=208640)



I don't understand what is wrong here... - Outcast - 08.01.2011

I am currently learning to script. I made a /stats command but instead of showing:
-------Current stats: Player_Name------
blah blah blah...

it shows me:
-------Current stats: 32----------

32 is the ammount of money I have.

Here's the code:
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/stats", cmdtext, true, 10) == 0)
	{
		new statsname[128];
		new statsmsg[256];
		format(statsname, 128, "----------Current stats: %s----------", PLAYER_NAME);
		SendClientMessage(playerid, COLOR_YELLOW, statsname);
		PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
 		format(statsmsg, 256, "Level: [%b] Admin level: [%i] Money: [$%i]", PlayerInfo[playerid][pScore], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pCash]);
		SendClientMessage(playerid, COLOR_YELLOW, statsmsg);
		return 1;
	}
	return 1;
}
PLAYER_NAME is defined as MAX_PLAYER_NAME


I just don't get it.


Re: I don't understand what is wrong here... - Doom8890 - 08.01.2011

How about this?

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/stats", cmdtext, true, 10) == 0)
    {
        new statsname[128];
        new statsmsg[256];
                new pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pName,sizeof(pName));
        format(statsname, 128, "----------Current stats: %s----------", pName);
        SendClientMessage(playerid, COLOR_YELLOW, statsname);
        PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
        format(statsmsg, 256, "Level: [%b] Admin level: [%i] Money: [$%i]", PlayerInfo[playerid][pScore], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pCash]);
        SendClientMessage(playerid, COLOR_YELLOW, statsmsg);
        return 1;
    }
    return 1;
}



Re: I don't understand what is wrong here... - Joe Staff - 08.01.2011

A player's name is a string(text), MAX_PLAYER_NAME is '24' which is a number(integer). There's a function to place a player's name onto a variable designated as a string.

pawn Код:
new pname[24];
GetPlayerName(playerid,pname,24);
format(mystring,sizeof(mystring),"PlayerID %d's name is %s",playerid,pname);



Re: I don't understand what is wrong here... - Outcast - 08.01.2011

Quote:
Originally Posted by Doom8890
Посмотреть сообщение
How about this?

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/stats", cmdtext, true, 10) == 0)
    {
        new statsname[128];
        new statsmsg[256];
                new pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid,pName,sizeof(pName));
        format(statsname, 128, "----------Current stats: %s----------", pName);
        SendClientMessage(playerid, COLOR_YELLOW, statsname);
        PlayerInfo[playerid][pCash] = GetPlayerMoney(playerid);
        format(statsmsg, 256, "Level: [%b] Admin level: [%i] Money: [$%i]", PlayerInfo[playerid][pScore], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pCash]);
        SendClientMessage(playerid, COLOR_YELLOW, statsmsg);
        return 1;
    }
    return 1;
}
It works, thanks.
Fala lik


Re: I don't understand what is wrong here... - Haydz - 08.01.2011

also instead of using
pawn Код:
PlayerInfo[playerid][pScore]
you could use
pawn Код:
GetPlayerScore(playerid)
You could also do the same with money.