Jail Timer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Jail Timer (
/showthread.php?tid=367170)
Jail Timer -
Armands - 08.08.2012
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);
}
}
Re: Jail Timer -
Shetch - 09.08.2012
bump!
Re: Jail Timer -
Roko_foko - 09.08.2012
Quote:
Originally Posted by Shetch
bump!
|
Why have you bumped?
Re: Jail Timer -
Shetch - 09.08.2012
Quote:
Originally Posted by Roko_foko
Why have you bumped?
|
Because I am having the same problem.
Re: Jail Timer -
Roko_foko - 09.08.2012
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.
Re: Jail Timer -
IceMeteor - 09.08.2012
You have to save the time left in a database, what system do you use?