[HELP] Unjail countdown
#1

Hello, i know there is many of topics like this but most of them are trash ... Did not help at all so...
I have CMD:Jail and i want to implement Time Countdown into my unjail timer.

Here is the command:

Код:
CMD:jail(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid,0xFFFFFFFF,"");
	new string[512], reason[256], targetid, time;
	if(sscanf(params,"uis[50]", targetid , time, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "");
	if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,0xFFFFFFFF,"");
	if(PlayerInfo[playerid][pAdmin] < 6 && PlayerInfo[targetid][pAdmin]  == 6) return 
        SendClientMessage(playerid,0xFFFFFFFF,"");
	format(string, sizeof(string), "",GetName(playerid), GetName(targetid), time);
	SendClientMessageToAll(0xCC000022, string);
	format(string, sizeof(string), "", reason);
	SendClientMessageToAll(0xCC000022, string);
	SetPlayerInterior(targetid, 6);
	SetPlayerPos(targetid,264.1800,77.5989,1001.0391);
	PlayerInfo[targetid][pJailed] = 1;
	PlayerInfo[targetid][pJailedTime] = time*1000;
	UnJailTimer[targetid] = SetTimerEx("UnJailPlayer",time*1000,0,"i",targetid);
	JailTime[playerid] = SetTimerEx("UpdateJailTime",time*1000,0,"d",targetid);
        return 1;
}
As you can see i have 2 timers here ... I really want to have countdown and UnJailTimer in one.
Here is my timer

Код:
forward UnJailPlayer(playerid);
public UnJailPlayer(playerid)
{
	KillTimer(UnJailTimer[playerid]);
	SetPlayerInterior(playerid, 0);
	SetPlayerPos(playerid,1552.5085,-1675.7572,16.1953);
	GameTextForPlayer(playerid, "~w~BlahBlah~r~!", 3000, 6);
	PlayerInfo[playerid][pJailed] = 0;
	PlayerInfo[playerid][pJailedTime] = 0;
	return 1;
}
And finally... Where to put this?
Код:
    

        PlayerInfo[playerid][pJailedTime]--;
	new UnjailTime[20];
	format(UnjailTime,sizeof(UnjailTime),"~r~%d",PlayerInfo[playerid][pJailedTime]);
	GameTextForPlayer(playerid,UnjailTime,1000,1);
Any idea how to make really simple countdown system here?
Reply
#2

pawn Код:
CMD:jail(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] == 0) return SendClientMessage(playerid,0xFFFFFFFF,"");
    new targetid, time, reason[256];
    if(sscanf(params,"uis[50]", targetid, time, reason)) return SendClientMessage(playerid, 0xFFFFFFFF, "");
    if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,0xFFFFFFFF,"");
    if(PlayerInfo[playerid][pAdmin] < 6 && PlayerInfo[targetid][pAdmin]  == 6) return SendClientMessage(playerid,0xFFFFFFFF,"");
    new string[128];
    format(string, sizeof(string), "",GetName(playerid), GetName(targetid), time);
    SendClientMessageToAll(0xCC000022, string);
    format(string, sizeof(string), "", reason);
    SendClientMessageToAll(0xCC000022, string);
    SetPlayerInterior(targetid, 6);
    SetPlayerPos(targetid,264.1800,77.5989,1001.0391);
    PlayerInfo[targetid][pJailed] = 1;
    PlayerInfo[targetid][pJailedTime] = time + 1;
    KillTimer(JailTime[targetid]);
    JailTime[targetid] = SetTimerEx("UpdateJailTime",1000,true,"d",targetid);
    return 1;
}

forward UpdateJailTime(playerid);
public UpdateJailTime(playerid)
{
    if(!IsPlayerConnected(playerid))
    {
        KillTimer(JailTime[playerid]);
        return 0;
    }

    if(--PlayerInfo[playerid][pJailedTime] < 1)
    {
        KillTimer(JailTime[playerid]);
        SetPlayerInterior(playerid, 0);
        SetPlayerPos(playerid,1552.5085,-1675.7572,16.1953);
        GameTextForPlayer(playerid, "~w~BlahBlah~r~!", 3000, 6);
        PlayerInfo[playerid][pJailed] = 0;
        PlayerInfo[playerid][pJailedTime] = 0;
        return 1;
    }

    new str[20];
    format(str,sizeof(str),"~r~%d",PlayerInfo[playerid][pJailedTime]);
    GameTextForPlayer(playerid,str,1200,1);
    return 0;
}
Reply
#3

Thanks alot that works!
The only one problem is that it does not countdown by 1 sec but by 7 sec so...
If i jail me for example 666 seconds, the game text is like:
666
659
652
645 ...


Another problem is when i disconect and connect back the timer is dead ...

I tried this... //OnPlayerSpawn
Код:
if(PlayerInfo[playerid][pJailed] == 1)
	{
	KillTimer(JailTime[playerid]);
	JailTime[playerid] = SetTimerEx("UpdateJailTime",1000,true,"d",playerid);
	}
Reply
#4

to fix this problem u have to save in his files the time left for him to get unjailed and when he connect check if it was more than 0 and then jail him with the new left time saved in his account
Reply
#5

SA-MP timers by default are grossly inaccurate if you're looking for an accurate countdown of jail time left. If you want to use native SA-MP timers, I'd recommend you use a timer fix (which attempt to fix timer inaccuracy). There's plenty, some includes and some plugins. Just search "SA-MP timer fix" in ******. Having two seperate timers for a countdown and for unjail is also inefficient and redudant. Example of how you could combine them:

pawn Код:
public _JailTimer(playerid)
{
      // subtract jail time --
      if(JailTime[playerid] == 0)
      {
             // release the player
             KillTimer(JailTimer[playerid]);
      }

      return 1;
}
/
Reply
#6

Quote:
Originally Posted by ThomasEvil
Посмотреть сообщение
The only one problem is that it does not countdown by 1 sec but by 7 sec so...
If i jail me for example 666 seconds, the game text is like:
666
659
652
645 ...
Impossible :> all time 7 sec ? something is wrong in your code somewhere also you need save jailtime into player account if he left
Reply
#7

I save jailed time with PlayerInfo[playerid][pJailedTime] so what i need to do is to set NEW timer when player connect if players PlayerInfo[playerid][pJailedTime] > 0 ? Can't start the same timer like i have for jail cmd?

PlayerInfo[playerid][pJailedTime] is the thing i use to save jailed time and use it for my jail timer.

I just want to use same timer: public UpdateJailTime(playerid)
Reply
#8

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Impossible :> all time 7 sec ? something is wrong in your code somewhere also you need save jailtime into player account if he left
I'am pretty sure that the timer works second by second but... GameTextForPlayer is shown after 7 seconds even if i set it to 1000ms or 500ms ... So GameTextForPlayer player can see one number for 7 seconds... Maybe the reading from file to check PlayerInfo[playerid][pJailedTime] is too slow? Idk..
Reply
#9

I can show similar code with chat mute system. I hope this helps you.

Код:
CMD:amute(playerid,params[])
{
	new banid, banname[MAX_PLAYER_NAME],adminName[MAX_PLAYER_NAME], string[129], reason[128], mtime;
	
	if(!pData[playerid][pAdmin]) 
		return SendClientMessage(playerid,COLOR_RED,"ERROR!");
	
	if(sscanf(params,"dds[128]",banid, mtime, reason)) 
		return SendClientMessage(playerid,-1,"{80BCFF}use:{FFFFFF} /mute <id> <time> <reason>");
	
	if(!IsPlayerConnected(banid)) 
		return SendClientMessage(playerid,COLOR_RED,"Wrong ID.");
	
	pData[banid][aMute] = gettime()+mtime*60; //write unixtime + mute time * 60

	return 1;
}

// Add to Secondary Timer

Код:
foreach (new i : Player)
{
	if(pData[i][aMute])
	{
	     if(gettime() >=  pData[i][aMute]) // if unixtime now > or = mute time, unmute player.
			pData[i][aMute] = 0;
	}
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
     if(pData[playerid][aMute] > gettime() && pData[playerid][aMute]) // if player have mute and time mute > or = mute time
	     pData[playerid][aMute] = pData[playerid][aMute] - gettime(); // reaming unix time - unix time
     else
          pData[playerid][aMute] = 0; // else set mute time 0


		mysql_format(mysql, query, sizeof(query),"UPDATE `login` SET `murders` = '%d', `death` = '%d', `reputation` = '%d', `description` = '%s', `mute` = '%d', `warn` = '%d' WHERE id='%d'", pData[playerid][pMurders], pData[playerid][pDeath], pData[playerid][pReputation], SQL_ReturnEscaped(pData[playerid][pDescription]), pData[playerid][aMute], pData[playerid][warn], pData[playerid][pID]);
		mysql_tquery (mysql, query)
; // here write reaming mute time on base or file

When player connect
Код:
                new temp[128];		
                cache_get_row(0, 11, temp, mysql, 12);
		pData[playerid][aMute] = gettime() + strval(temp);
Reply
#10

Guys this os worked for me:

1. cmd:jail - jail the player,settimer and save jailedtime
2. OnPlayerSpawn - check if jailed,killtimer, settimer(same timer)

So now everything works. If i jail player cmd:jail he is jailed for the time and if he reconnect i load the time and start timer again. Works

PROBLEM WITH 7 SECONDS GAMETEXT:

Style 1
Fades out after 8 seconds, regardless of time set. If you have a time setting longer than that, it will re-appear after fading out and repeat until the time ends.

This is the problem ... Well its better to use another type or textdraws

THANKS EVERYONE.
Especially Jefff - Your code works just needed some changes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)