[Pedido] Calcular Tempo
#1

Salve rapaziada, entгo eu estava criando alguns sistemas temporбrios e eu usava a seguinte syntax de cmd (EX: /ban [ID] [Dia] [Mкs] [Ano]) e eu sei que essa maneira nгo й a mais adequada, queria saber se tem algum tutorial aqui no fуrum falando sobre, porquк meu cуdigo fica muito poluнdo com todos esses parвmetros se й que me entende. Jб procurei usando o search e nada, talvez uma explicaзгo de vocкs jб me ajuda...
Reply
#2

Vocк pode fazer assim, apenas uma base:

PHP код:
#define MAX_DIAS 365 + 365 + 365 // 3 Anos
new SegundosBanido[MAX_PLAYERS];
CMD:banir(playerid, params[]) {
    if(!
IsPlayerAdmin(playerid)) return SCM(playerid, COLOR_ERRO, "| ERRO | Vocк nгo tem permissгo!");
    
    new 
zNick[MAX_PLAYER_NAME], Dias;
    
    if(
sscanf(params, "s[24]i", zNick, Dias)) return SCM(playerid, COLOR_ERRO, "| ERRO | Digite: /Banir [Nick] [Dias]");
    if(!
DOF2_FileExists(...)) // Se voce quiser verificar se a conta dele nгo existe.
    
if(Dias < 1 || Dias > MAX_DIAS) return SCM(playerid, COLOR_ERRO, "| ERRO | Os dias й no mбximo entre 1 e "#MAX_DIAS".");
    
    
new TimeBanido = gettime() + (Dias * 86400), string[80];
    
    
DOF2_SetInt(..., "SegundosBanido", TimeBanido); // Setando os Dias Aqui
    
DOF2_SaveFile();
    
    
format(string, sizeof(string), "| BANIMENTO | Vocк baniu o Nick ' %s ' por um total de %d Dias.", zNick, Dias);
    
SCM(playerid, -1, string);
    
    return 
true;
}
public 
OnPlayerConnect(playerid) {
    new 
SegundosBanido[playerid] = DOF2_GetInt(Conta, "SegundosBanido")),
        
string[100];
    if(
SegundosBanido[playerid] != 0)
    {
        new 
Dia, Mes, Ano, Horas, Minutos, Segundos;
        
TimestampToDate(SegundosBanido, Dia, Mes, Ano);
        
TimestampToClock(SegundosBanido, Horas, Minutos, SegundosBanido);
        
SCM(playerid, -1, "| BAN | Vocк estб banido(a), visite o Fуrum: "#SEU_FORUM_AQUI".");
        //-------------//
        
format(string, sizeof(string), "| DIAS | Vocк serб desbanido em: %s, %d, do mкs de: %s, do ano de: %d аs %02d:%02d:%02d",
        
GetDayName(Dia, Mes, Ano), Dia, GetMonthName(Mes), Ano, Horas, Minutos, SegundosBanido));
        
SCM(playerid, -1, string);
    }
    return 
true;
}
stock GetMonthName(m) {
    new 
nM[11];
    switch(
m)
    {
        case 
1: nM= "Janeiro";
        case 
2: nM= "Fevereiro";
        case 
3: nM= "Marзo";
        case 
4: nM= "Abril";
        case 
5: nM= "Maio";
        case 
6: nM= "Junho";
        case 
7: nM= "Julho";
        case 
8: nM= "Agosto";
        case 
9: nM= "Setembro";
        case 
10: nM= "Outubro";
        case 
11: nM= "Novembro";
        case 
12: nM= "Dezembro";
    }
    return 
nM;
}
stock TimestampToClock(gettime, &hour, &minute, &second) {
    new 
tm<tmTime>;
    
localtime(Time:gettime, tmTime);
    
hour = tmTime[tm_hour];
    
minute = tmTime[tm_min];
    
second = tmTime[tm_sec];
}
// ---------------------------------------------------------------------------------------------------------------------------------- //
stock TimestampToDate(gettime, &day, &month, &year) {
    new 
tm<tmTime>;
    
localtime(Time:gettime, tmTime);
    
tmTime[tm_year] += 1900;
    
tmTime[tm_mon] += 1;
    
day = tmTime[tm_mday];
    
month = tmTime[tm_mon];
    
year = tmTime[tm_year];
}
// ------------------------------------------------------------------------------------------------------------------------------------------ //
stock GetDayName(bDia, bMes, bAno) {
    new 
tm<tmWeekDay>;
    
tmWeekDay[tm_mday] = bDia;
    
tmWeekDay[tm_mon] = bMes - 1;
    
tmWeekDay[tm_year] = bAno - 1900;
    
mktime(tmWeekDay);
    new 
DiasDaSemana[][15] =
    {
        { 
"Domingo" },
        { 
"Segunda" },
        { 
"Terзa" },
        { 
"Quarta" },
        { 
"Quinta" },
        { 
"Sexta" },
        { 
"Sбbado" }
    };
    return 
DiasDaSemana[tmWeekDay[tm_wday]];
} 
Vocк precisarб usar a Include CTime:

https://sampforum.blast.hk/showthread.php?tid=652653
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)