Pausear timer?
#1

Hola, tengo este comando para sancionar, pero queria que cuando un jugador sancionado salga del juego el timer pare y cuando entre de nuevo le ponga los minutos que le faltan. Como haria eso?
Comando:
pawn Код:
CMD:san(playerid,params[])
{
    if(AccountInfo[playerid][AdminLvl] >= 2)
    {
        new targetid, time, string1[250];
        if(sscanf(params, "dds[128]", targetid, time, params[3])) return SendClientMessage(playerid, -1, "[ERROR]: /san [ID] [Minutos] [Razon]");
            else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Usuario no conectado");
                else
                {
                    SetPlayerInterior(targetid, 3);
                    SetPlayerVirtualWorld(targetid,21);
                    SetPlayerPos(targetid, 291.282989,310.031982,999.148437);
                    SetTimerEx("UnJail",time*1000*60,false,"i",targetid);
                    AccountInfo[targetid][InJail] = 1;
                    ResetPlayerWeapons(targetid);
                    format(string1, sizeof(string1), "%s %s a sancionado a %s por %i minutos [Razon: %s]",GetAdminName(playerid),pNombre(playerid),pNombre(targetid),time,params[3]);
                    SendClientMessageToAll(COLOR_ERROR, string1);
                }
    }
    else {
        SendClientMessage(playerid,COLOR_AZUL,"No tienes permiso a usar este comando.");
    }
    return 1;
}

public UnJail(targetid)
{
   SetPlayerVirtualWorld(targetid,0);
   SpawnPlayer(targetid);
   SetPlayerInterior(targetid,0);
   SendClientMessage(targetid, -1, "{00FF00}» Tu sancion ha terminado, porfavor sigue las /reglas para la proxima.");
   AccountInfo[targetid][InJail] = 0;
   return 1;
}
Reply
#2

KillTimer
Reply
#3

Quote:
Originally Posted by OTACON
Посмотреть сообщение
ya yo conozco esa funcion, pero si pongo KillTimer cuando el jugador desconecte para cuando se conecte como puedo detectar en cuanto minutos le faltaron para que saliera?
Reply
#4

Es muy sencillo. Si usas un sistema de registro o tenes algъn sistema que guarde los datos del jugador, usas una variable y cuando el jugador conecte "cargas" esa variable como al momento de loguear.
Reply
#5

Quote:
Originally Posted by OTACON
Посмотреть сообщение
Debemos aprender a leer el tema antes de comentar, Tincho ya te ha dado la respuesta de como se hace
Reply
#6

Quote:
Originally Posted by TiNcH010
Посмотреть сообщение
Es muy sencillo. Si usas un sistema de registro o tenes algъn sistema que guarde los datos del jugador, usas una variable y cuando el jugador conecte "cargas" esa variable como al momento de loguear.
Todavia no entiendo bien, Como guardaria el tiempo que le quede cuando desconecte? Ya se que en una variable pero que tengo que poner en esa variable?
Reply
#7

Puedes usar la funcion gettime(), esta te regresa los segundos por ejemplo en tu timer usas variable[playerid] = gettime() y cuando se desconecte guarda el tiempo dado por gettime()-variable[playerid]
Reply
#8

hace esto:
en el cmd sancionar esto
TuVariableDeTiempoJail = gettime() + time;
despuйs en onplayerupdate pones
if(TuVariableDeTiempoJail < gettime())
y ahн liberas al jugador
Reply
#9

Quote:
Originally Posted by xSDx
Посмотреть сообщение
Puedes usar la funcion gettime(), esta te regresa los segundos por ejemplo en tu timer usas variable[playerid] = gettime() y cuando se desconecte guarda el tiempo dado por gettime()-variable[playerid]
Se bugean ahora los minutos, lo tengo hasi:
pawn Код:
CMD:san(playerid,params[])
{
    if(AccountInfo[playerid][AdminLvl] >= 2)
    {
        new targetid,string1[250];
        if(sscanf(params, "dds[128]", targetid, tiempo, params[3])) return SendClientMessage(playerid, -1, "[ERROR]: /san [ID] [Minutos] [Razon]");
            else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Usuario no conectado");
                else
                {
                    SetPlayerInterior(targetid, 3);
                    SetPlayerVirtualWorld(targetid,21);
                    SetPlayerPos(targetid, 291.282989,310.031982,999.148437);
                    tiempo[targetid] = gettime();
                    SetTimerEx("UnJail",tiempo[targetid]*1000*60,false,"i",targetid);
                    AccountInfo[targetid][InJail] = 1;
                    ResetPlayerWeapons(targetid);
                    format(string1, sizeof(string1), "%s %s a sancionado a %s por %i minutos [Razon: %s]",GetAdminName(playerid),pNombre(playerid),pNombre(targetid),tiempo,params[3]);
                    SendClientMessageToAll(COLOR_ERROR, string1);
                }
    }
    else {
        SendClientMessage(playerid,COLOR_AZUL,"No tienes permiso a usar este comando.");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(AccountInfo[playerid][InJail] == 1) return gettime()-tiempo[playerid];
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(AccountInfo[playerid][InJail] == 1)
    {
    SetPlayerInterior(playerid, 3);
    SetPlayerVirtualWorld(playerid,21);
    SetPlayerPos(playerid, 291.282989,310.031982,999.148437);
    SetTimerEx("UnJail",gettime()-tiempo[playerid]*1000*60,false,"i",playerid);
    }
    return 1;
}
Reply
#10

pawn Код:
CMD:san(playerid,params[])
{
    if(AccountInfo[playerid][AdminLvl] >= 2)
    {
        new targetid,string1[250];
        if(sscanf(params, "dds[128]", targetid, tiempo, params[3])) return SendClientMessage(playerid, -1, "[ERROR]: /san [ID] [Minutos] [Razon]");
            else if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid, -1, "Usuario no conectado");
                else
                {
                    SetPlayerInterior(targetid, 3);
                    SetPlayerVirtualWorld(targetid,21);
                    SetPlayerPos(targetid, 291.282989,310.031982,999.148437);
                    tiempo[targetid] = gettime();
                    SetTimerEx("UnJail",1000*60,false,"i",targetid);
                    AccountInfo[targetid][InJail] = 1;
                    ResetPlayerWeapons(targetid);
                    format(string1, sizeof(string1), "%s %s a sancionado a %s por %i minutos [Razon: %s]",GetAdminName(playerid),pNombre(playerid),pNombre(targetid),tiempo,params[3]);
                    SendClientMessageToAll(COLOR_ERROR, string1);
                }
    }
    else {
        SendClientMessage(playerid,COLOR_AZUL,"No tienes permiso a usar este comando.");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(AccountInfo[playerid][InJail] == 1) return tiempo[playerid]=(gettime()-tiempo[playerid]);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(AccountInfo[playerid][InJail] == 1)
    {
    SetPlayerInterior(playerid, 3);
    SetPlayerVirtualWorld(playerid,21);
    SetPlayerPos(playerid, 291.282989,310.031982,999.148437);
    SetTimerEx("UnJail",gettime()-tiempo[playerid]*60,false,"i",playerid);
    }
    return 1;
}
Recuerda que gettime devuelve el tiempo en segundos, no en milisegundos.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)