Jail Timer
#1

Hello! I've got a problem with my jail timer. I want the jail timer to be active even if the jailed player is disconnected. I attempted it, but when a different player connects with the same ID, the server assumes that it's the jailed player. Help would be appriciated!

This happens, when player gets jailed (I am using dialogs):
Код:
JailTime[AdminPlayer[playerid]]=JailTime[AdminPlayer[playerid]]*60;
	JailTimer(AdminPlayer[playerid]);
	Jailed[AdminPlayer[playerid]]=true;
	GetPlayerPos(AdminPlayer[playerid],LastX,LastY,LastZ);
	GetPlayerFacingAngle(AdminPlayer[playerid],LastA);
	SetPlayerPos(AdminPlayer[playerid],-27.2693,2320.6797,24.3034);
	SetPlayerFacingAngle(AdminPlayer[playerid],0.0);
	SetPlayerVirtualWorld(AdminPlayer[playerid],1);
This is the timer:
Код:
public JailTimer(playerid)
{
	new string1[256];
	JTimer[playerid] = SetTimerEx("JailTimer",1000,false,"i",playerid);
	format(string1,256,"JAIL: ~W~%d",JailTime[playerid]-1);
	TextDrawSetString(JailTimeText,string1);
	TextDrawShowForPlayer(playerid,JailTimeText);
	JailTime[playerid]--;
	if(JailTime[playerid] <= 0)
	{
	    Jailed[playerid]=false;
		KillTimer(JTimer[playerid]);
		TextDrawHideForPlayer(playerid,JailTimeText);
		SetPlayerPos(playerid,LastX,LastY,LastZ);
		SetPlayerFacingAngle(playerid,LastA);
		SendClientMessage(playerid,COLOR_WHITE,"UNJAILED!");
		SetPlayerVirtualWorld(playerid,0);
	}
}
Reply
#2

bump!
Reply
#3

Quote:
Originally Posted by Shetch
Посмотреть сообщение
bump!
Why have you bumped?
Reply
#4

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
Why have you bumped?
Because I am having the same problem.
Reply
#5

Okay. This can be scripted, but it will have one problem. The problem is you will have limited number of players that are jailed.
pawn Код:
//--------------definitions-----------------
#define MAX_JAILED_PLAYERS 1500
//_________________________________________________
//--------------global variables------------
new JailedName[MAX_JAILED_PLAYERS][MAX_PLAYER_NAME];
new JailedTime[MAX_JAILED_PLAYERS];
//_________________________________________________
//-------------forwarded functions-----------------
forward public OneSecondTimer();
//-------------------------------------------------
public OnGameModeInit()
{
    new i;
    for(i=0;i<MAX_JAILED_PLAYERS;i++)
    {
        JailedName[i][0]=0;
        JailedTime[i]=0;
    }
    SetTimer("OneSecondTimer",1000,true);
}
ReleasePlayerFromJail(num)
{
    new i;
    for(i=0;i<MAX_PLAYERS;i++)if(IsPlayerConnected(i))
    {
         if(!strcmp(JailedName[num],GetPlayerName(i))
         {
             SendClientMessage(i,0x00FF00FF,"You have served you time in jail.");
            //released player is online, set him on his "released" position
         }
    }
    for(i=num;i<MAX_JAILED_PLAYERS && JailedName[i][0]!=0;i++)
    {
        JailedName[i]="";
        strcat(JailedName[i],JailedName[i+1]);
        JailedTime[i]=JailedTime[i+1];
    }
}
public OneSecondTimer()// It would be good if you use this timer not only for Jailed peapole.
{
   for(new i=0;i<MAX_JAILED_PLAYERS && JailedName[i][0]!=0;i++)
   {
       if(--JailedTime[i]==0)ReleasePlayerFromJail(i);
   }  
}
//when prisoning someone
{
    new i;
    for(i=0;JailedName[i][0]!=0 &&i<MAX_JAILED_PLAYERS;i++)
    if(i==MAX_JAILED_PLAYERS)SendClientMessage(PlayerThatIsPrisoning,0xFF0000FF,"Prison is full at moment");
    else
    {
        JailedTime[i]=TimeToServeInJailInSeconds;
        JailedName[i]="";
        strcat(JailedName[i],GetPlayerName(PrisonedGuyID));
    }
}
Didn't test it, but checked it few times, and it looks good.
Reply
#6

You have to save the time left in a database, what system do you use?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)