#1

PHP код:
CMD:stats(playerid,params[])
{
     new 
idhmd;
     
sscanf(params"u"id);
     if (
isnull(params))
     {
        new 
seconds gettime() - pInfo[playerid][ConnectedTime] + pInfo[playerid][TotalSecs];
        
format(Jstringsizeof(Jstring), "Name: %s | Score: %d | Money: $%d | Kills: %d | Deaths: %d | Ratio: %0.2f\nTotal spent Time: %s",GetName(playerid), GetPlayerScore(playerid), GetPlayerMoney(playerid), pInfo[playerid][Kills], pInfo[playerid][Deaths], Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths],ConvertTime(seconds,m,h,d));
        return 
ShowPlayerDialog(playerid,300,DIALOG_STYLE_MSGBOX,"Stats",Jstring"Ok","");
     }
     else if(
IsPlayerConnected(id))
     {
        new 
seconds gettime() - pInfo[id][ConnectedTime] + pInfo[id][TotalSecs];
        
format(Jstringsizeof(Jstring), "Name: %s | Score: %d | Money: $%d | Kills: %d | Deaths: %d | Ratio: %0.2f\nTotal spent Time: %s",GetName(id), GetPlayerScore(id), GetPlayerMoney(id), pInfo[id][Kills], pInfo[id][Deaths], Float:pInfo[id][Kills]/Float:pInfo[id][Deaths],ConvertTime(seconds,m,h,d));
        return 
ShowPlayerDialog(playerid,300,DIALOG_STYLE_MSGBOX,"Stats",Jstring"Ok","");
     }
     else return 
ShowMessage(playeridred2);

in game it show me
all work except Total SpendTime not work

example: 19 minutes 10 seconds

with hours :

1 hour 19 minutes 10 sec
i need

1 hour 19 minutes 10 seconds
Reply
#2

Try This And tell Me If It Working
PHP код:
CMD:stats(playerid,params[])
{
     new 
idhmd;
     
sscanf(params"u"id);
     if (
isnull(params))
     {
        
ConvertTime(seconds,m,h,d);
        
format(Jstringsizeof(Jstring), "Name: %s | Score: %d | Money: $%d | Kills: %d | Deaths: %d | Ratio: %0.2f\nTotal spent Time: %02d:%02d:%02d",GetName(playerid), GetPlayerScore(playerid), GetPlayerMoney(playerid), pInfo[playerid][Kills], pInfo[playerid][Deaths], Float:pInfo[playerid][Kills]/Float:pInfo[playerid][Deaths],m,h,seconds);
        return 
ShowPlayerDialog(playerid,300,DIALOG_STYLE_MSGBOX,"Stats",Jstring"Ok","");
     }
     else if(
IsPlayerConnected(id))
     {
        
ConvertTime(seconds,m,h,d);
        
format(Jstringsizeof(Jstring), "Name: %s | Score: %d | Money: $%d | Kills: %d | Deaths: %d | Ratio: %0.2f\nTotal spent Time: %02d:%02d:%02d",GetName(id), GetPlayerScore(id), GetPlayerMoney(id), pInfo[id][Kills], pInfo[id][Deaths], Float:pInfo[id][Kills]/Float:pInfo[id][Deaths],m,h,seconds);
        return 
ShowPlayerDialog(playerid,300,DIALOG_STYLE_MSGBOX,"Stats",Jstring"Ok","");
     }
     else return 
ShowMessage(playeridred2);

Reply
#3

First of all, ELSE IF cannot be used like that. You are checking if the parameters are empty (which you dont need to do since you have SSCANF) but then you check if they arent empty if the other player is connected?

this is the usage of else if
new number
PHP код:
if(number == 0)  //if the number is 0
else if(number == 1//if its not 0 and its 1
else if(number == 2//if its not 0,1 and its 2 
Thats the usage of else if.

Next to that, you dont need isnull at all, sscanf does that for you right away.

Example (modify your code with this if you want)
PHP код:
CMD:stats(playerid,params[]) {
    new 
someid;
    if(
sscanf(params,"u",someid)) {
        
//add code here if they didnt add any parameters and they just typed /stats
    
}
    if(
id == INVALID_PLAYER_ID) return SendClientMessage(playerid,COLOR_RED,"Invalid ID-part of the name"); //if they entered some parameter and if that player is connected
    
new string[128];
    new 
seconds gettime() - pInfo[someid][ConnectedTime] + pInfo[someid][TotalSecs];
    
format(string,sizeof(string),"Playtime: %s",DisplayPlaytime(seconds));
    
SendClientMessage(someid,COLOR_RED,string);
    return 
true;
}
stock DisplayPlaytime(Seconds// credits to Brokenbreaken
{
    new 
String[150];
    new 
Minutes,Hours,Days;
    if(
Seconds 59)
    {
        
Minutes Seconds 60;
        
Seconds Seconds - (Minutes 60);
    }
    if(
Minutes 59)
    {
        
Hours Minutes 60;
        
Minutes Minutes - (Hours 60);
    }
    if(
Hours 23)
    {
        
Days Hours 24;
        
Hours Hours - (Days 24);
    }
    
format(String,150,"%d days, %d hours, %d minutes, %d seconds",Days,Hours,Minutes,Seconds);
    return 
String;

Reply
#4

Fixed thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)