stats command
#1

Can someone help me to make stats form sendclientmessage to dialogstylemsgbox

heres the stats command i have now

Код:
#if defined USE_STATS
CMD:stats(playerid,params[]) {
	new string[128], pDeaths, player1, h, m, s;
	if(isnull(params)) player1 = playerid;
	else player1 = strval(params);

	if(IsPlayerConnected(player1)) {
	    TotalGameTime(player1, h, m, s);
 		if(PlayerInfo[player1][Deaths] == 0) pDeaths = 1; else pDeaths = PlayerInfo[player1][Deaths];
 		format(string, sizeof(string), "| %s's Stats:  Level: %d | Kills: %d | Deaths: %d | Ratio: %0.2f | Money: $%d | Bank: $%d | Time: %d hrs %d mins %d secs |",PlayerName2(player1), PlayerInfo[player1][Level],PlayerInfo[player1][Kills], PlayerInfo[player1][Deaths], Float:PlayerInfo[player1][Kills]/Float:pDeaths,GetPlayerMoney(player1),PlayerInfo[player1][bank], h, m, s);
		return SendClientMessage(playerid, green, string);
	} else return SendClientMessage(playerid, red, "Player Not Connected!");
}
#endif
Reply
#2

any help please?
Reply
#3

[TUT] How To Make A Dialog Menu

Or if you're too lazy
Код:
BEFORE:
format(string, sizeof(string), "| %s's Stats:  Level: %d | Kills: %d | Deaths: %d | Ratio: %0.2f | Money: $%d | Bank: $%d | Time: %d hrs %d mins %d secs |",PlayerName2(player1), PlayerInfo[player1][Level],PlayerInfo[player1][Kills], PlayerInfo[player1][Deaths], Float:PlayerInfo[player1][Kills]/Float:pDeaths,GetPlayerMoney(player1),PlayerInfo[player1][bank], h, m, s);
return SendClientMessage(playerid, green, string);

AFTER:
new playerName[MAX_PLAYER_NAME],
    dialogTitle[MAX_PLAYER_NAME+24],
    dialogString[128],
    killDeathRatio = Float:PlayerInfo[player1][Kills]/Float:pDeaths;
    
GetPlayerName(player1, playerName, sizeof(playerName));
format(dialogTitle, sizeof(dialogTitle), "Stats of %s", playerName);
format(dialogString, sizeof(dialogString), "Level: %d \nKills: %d \nDeaths: %d \nRatio: %0.2f \nMoney: $%d \nBank: $%d \nTime: %d hrs %d mins %d secs", PlayerInfo[player1][Level], PlayerInfo[player1][Kills], PlayerInfo[player1][Deaths], Float:killDeathRatio, GetPlayerMoney(player1), PlayerInfo[player1][bank], h, m, s);

ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, dialogTitle, dialogString, "Ok", "");
You shouldnt really be doing math in a format argument, so i fixed that too, but didnt test so not 100% sure if you need that Float: or not.
Reply
#4

so how do i combine it to a command?
Reply
#5

anyone?
Reply
#6

If you want to combine to a dialog use strcat if you want to use a simple /stats command with messages just use format and SendClientMessage.
Reply
#7

If talking about having looked at the tutorial and now wanting to implement it:
1] you should split your current string in two, one string will be title, other will be stats text
2] after that replace the pipe symbols (these: | ) in your string with these linebreaks: \n to improve readability
3] call the ShowPlayerDialog function instead of the SendClientMessage function, use the MSGBOX style dialog. (again, assuming you've read the tut, you should be capable of making ShowPlayerDialog do what you want with the 3 steps provided)

If talking about the code i provided
1] go too the command you have now (in your code, in pawno or whatever editor you use)
2] find the two lines mentioned below "BEFORE:" in my reply
3] replace them with the 8 lines mentioned below "AFTER:" in my reply
4] profit! or report back here again if it all goes to hell
Reply
#8

2 errors GOD DAMN


Код:
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32339) : warning 213: tag mismatch
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32344) : error 029: invalid expression, assumed zero
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32344) : warning 215: expression has no effect
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32344) : error 001: expected token: ";", but found "return"
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32345) : warning 225: unreachable code
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32329) : warning 204: symbol is assigned a value that is never used: "string"
C:\Users\Lietotajs\Desktop\Fire~SATDM.pwn(32329 -- 32347) : warning 209: function "cmd_stats" should return a value
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
and hoow the new code looks like

Код:
#if defined USE_STATS
CMD:stats(playerid,params[]) {
	new string[128], pDeaths, player1, h, m, s;
	if(isnull(params)) player1 = playerid;
	else player1 = strval(params);

	if(IsPlayerConnected(player1)) {
	    TotalGameTime(player1, h, m, s);
 		if(PlayerInfo[player1][Deaths] == 0) pDeaths = 1; else pDeaths = PlayerInfo[player1][Deaths];
        new playerName[MAX_PLAYER_NAME],
        dialogTitle[MAX_PLAYER_NAME+24],
        dialogString[128],
        killDeathRatio = Float:PlayerInfo[player1][Kills]/Float:pDeaths;
        GetPlayerName(player1, playerName, sizeof(playerName));
        format(dialogTitle, sizeof(dialogTitle), "Stats of %s", playerName);
        format(dialogString, sizeof(dialogString), "Level: %d \nKills: %d \nDeaths: %d \nRatio: %0.2f \nMoney: $%d \nBank: $%d \nTime: %d hrs %d mins %d secs", PlayerInfo[player1][Level], PlayerInfo[player1][Kills], PlayerInfo[player1][Deaths], Float:killDeathRatio, GetPlayerMoney(player1), PlayerInfo[player1][bank], h, m, s);
        ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, dialogTitle, dialogString, "Ok", "");
        else return SendClientMessage(playerid, red, "Player Not Connected!");
		return 1;
      }
}
#endif
Reply
#9

Use sscanf -.-
Reply
#10

You kinda screwed up with bracket/blocks usage, so my suggestion is to start using an indent style when you write code, to help you spot those kind of mistakes, also makes it alot easier to find a certain bit of code in a wall of text. Cleaned up the code a bit aswell, combined variable creation to top of function and some other small things.

Код:
#if defined USE_STATS
CMD:stats(playerid,params[]) {
	new playerName[MAX_PLAYER_NAME],
        dialogTitle[MAX_PLAYER_NAME+24],
        dialogString[128],
        killDeathRatio,
        pDeaths, player1, h, m, s;
        
	if(isnull(params)) {
            player1 = playerid;
	} else {
            player1 = strval(params);
        }
    
	if(IsPlayerConnected(player1)) {
	    TotalGameTime(player1, h, m, s);
 	    if(PlayerInfo[player1][Deaths] == 0) {
                pDeaths = 1;
            } else {
                pDeaths = PlayerInfo[player1][Deaths];
            }
            killDeathRatio = Float:PlayerInfo[player1][Kills]/Float:pDeaths;
            GetPlayerName(player1, playerName, sizeof(playerName));
            format(dialogTitle, sizeof(dialogTitle), "Stats of %s", playerName);
            format(dialogString, sizeof(dialogString), "Level: %d \nKills: %d \nDeaths: %d \nRatio: %0.2f \nMoney: $%d \nBank: $%d \nTime: %d hrs %d mins %d secs", PlayerInfo[player1][Level], PlayerInfo[player1][Kills], PlayerInfo[player1][Deaths], Float:killDeathRatio, GetPlayerMoney(player1), PlayerInfo[player1][bank], h, m, s);
            ShowPlayerDialog(playerid, 1, DIALOG_STYLE_MSGBOX, dialogTitle, dialogString, "Ok", "");
        } else {
            SendClientMessage(playerid, red, "Player Not Connected!");
        }
	return 1;
}
#endif
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)