Help with jail timer and when connecting will check if in jail
#1

how can i add a check?

Code:
if(strcmp(cmd, "/prison", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			new playa;
			new money;
			new cell;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			money = strval(tmp);
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			cell = strval(tmp);
			if(cell > 24 || cell < 1) return SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell 1-24]");
			if (IsACop(playerid) || IsAPrisonGuard(playerid))
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
		        	    if(!PlayerToPoint(20, playerid,1834.0980,-1721.9845,5202.5859) || !PlayerToPoint(20, playerid,1827.5184,-1721.5369,5206.1860) ||  !PlayerToPoint(20, playerid,1844.3748,-1719.8369,5206.1870))// Jail spot
				        {
				           SendClientMessage(playerid, COLOR_GREY, "You cannot arrest anybody if your not near the prison`s cells!");
				           return 1;
				        }
       					if(GetDistanceBetweenPlayers(playerid,playa) < 10)
					    {//PlayerInfo[playerid][pJailCell] pPrisonDate
				        	GetPlayerName(playa, giveplayer, sizeof(giveplayer));
							GetPlayerName(playerid, sendername, sizeof(sendername));
							format(string, sizeof(string), "* You have arrested %s to los santos prison for %d minutes.", giveplayer, money);
							SendClientMessage(playerid, COLOR_RED, string);
							format(string, sizeof(string), "* You have been arrested for Los Santos Prison by %s for %d minutes.", sendername, money);
							SendClientMessage(playa, COLOR_YELLOWG, string);
							FullResetPlayerWeapons(playa);
							PlayerInfo[playa][pJailCell] = cell;
							PlayerInfo[playa][pArrested] += 1;
							new year, month,day;
							getdate(year, month, day);
							day += money;
							while(day > 31)
							{
								day -= 31;
								month++;
							}
							while(month > 12)
							{
							    month -= 12;
							    year++;
							}
							if(PlayerInfo[playa][pJailCell] == 1)
		    					SetPlayerPos(playa,1827.8213,-1731.9299,5202.5859);
		    				else if(PlayerInfo[playa][pJailCell] == 2)
								SetPlayerPos(playa,1831.0103,-1731.8927,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 3)
								SetPlayerPos(playa,1834.0918,-1732.0209,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 4)
								SetPlayerPos(playa,1837.2913,-1730.9072,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 5)
								SetPlayerPos(playa,1840.5859,-1731.9993,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 6)
								SetPlayerPos(playa,1843.7784,-1732.3024,5202.5859);	
							else if(PlayerInfo[playa][pJailCell] == 7)
								SetPlayerPos(playa,1843.7201,-1711.8350,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 8)
								SetPlayerPos(playa,1840.3660,-1712.1101,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 9)
								SetPlayerPos(playa,1837.1741,-1711.9928,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 10)
								SetPlayerPos(playa,1833.9534,-1712.1176,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 11)
								SetPlayerPos(playa,1830.5641,-1711.7528,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 12)
								SetPlayerPos(playa,1827.4946,-1711.4478,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 13)
								SetPlayerPos(playa,1827.7543,-1711.7517,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 14)
								SetPlayerPos(playa,1830.7646,-1711.9414,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 15)
								SetPlayerPos(playa,1834.0128,-1711.8164,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 16)
								SetPlayerPos(playa,1837.3129,-1711.6401,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 17)
								SetPlayerPos(playa,1840.5027,-1711.7007,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 18)
								SetPlayerPos(playa,1843.6472,-1711.7065,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 19)
								SetPlayerPos(playa,1843.6439,-1731.7734,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 20)
								SetPlayerPos(playa,1840.4283,-1731.8011,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 21)
								SetPlayerPos(playa,1837.1818,-1731.8258,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 22)
								SetPlayerPos(playa,1834.2139,-1732.4745,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 23)
								SetPlayerPos(playa,1831.0645,-1731.7957,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 24)
							SetPlayerPos(playa,1827.8179,-1731.8121,5206.1860);
							else
		    				{
								SetPlayerPos(playa,1827.5184,-1721.5369,5206.1860);
								//SetPlayerFacingAngle(playa, 269.8099);
							}
							TogglePlayerControllable(playa, 0);
							hostimer[playa] = SetTimerEx("EnterHospital",2000,1,"d",playa);
							SetPlayerInterior(playa, 2);
		    				PlayerInfo[playa][pInt] = 2;
						}
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "{BCD4E6}Error: {FFFFFF}Sorry, you cant use this command.");
			}
		}
		return 1;
	}
Reply
#2

Help please
Reply
#3

please help
Reply
#4

If I really understand what you want, then you should create a variable which would hold the time the player got jailed. After logging out, save that variable and upon connect, check if the variable is not equal to 0, then jail if its not. Dont forget to decrease the variables value as the player pass his time in jail.
Reply
#5

that what i was trying to do..
can u help me to do it?
Reply
#6

This is not a script request thread, you were asking for some help and I pointed out what and how things needs to be done. Now its your job to script it in PAWN, if you will need any help with doing that, feel free to ask here again. But Im sure, that noone is going to do this for you.
Reply
#7

I made something like this
PrisonTimer[playa] = SetTimerEx("SetFree", money * 60000, false, "d", playa);

and how i make that onplayerconnect it will check if he has time
Reply
#8

You can use "TimeStamp"
Reply
#9

Quote:
Originally Posted by PaulDinam
View Post
I made something like this
PrisonTimer[playa] = SetTimerEx("SetFree", money * 60000, false, "d", playa);

and how i make that onplayerconnect it will check if he has time
Save the array upon player disconnect. And then when he connects again, assign the saved value to the array and check.

pawn Code:
if(PrisonTimer[playerid] > 0)
     JailThePlayer(playerid);
Reply
#10

I made it finally everything works great.

here is the command

Code:
	if(strcmp(cmd, "/prison", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			new playa;
			new money;
			new cell;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			money = strval(tmp);
			tmp = strtok(cmdtext, idx);
			if(money > 300 || money < 10) return SendClientMessage(playerid, COLOR_GREY, "You can only prison someone for 10-300 minutes.");
			if(!strlen(tmp))
			{
				SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell]");
				return 1;
			}
			cell = strval(tmp);
			if(cell > 24 || cell < 1) return SendClientMessage(playerid, COLOR_GREY, "{33CCFF}USAGE:{FFFFFF} /prison [playerid/PartOfName] [Mins] [Cell 1-24]");
			if (IsACop(playerid) || IsAPrisonGuard(playerid))
			{
			    if(IsPlayerConnected(playa))
			    {
			        if(playa != INVALID_PLAYER_ID)
			        {
		        	    if(!PlayerToPoint(20, playerid,1834.0980,-1721.9845,5202.5859) || !PlayerToPoint(20, playerid,1827.5184,-1721.5369,5206.1860) ||  !PlayerToPoint(20, playerid,1844.3748,-1719.8369,5206.1870))// Jail spot
				        {
				           SendClientMessage(playerid, COLOR_GREY, "You cannot arrest anybody if your not near the prison`s cells!");
				           return 1;
				        }
       					if(GetDistanceBetweenPlayers(playerid,playa) < 10)
					    {
				        	GetPlayerName(playa, giveplayer, sizeof(giveplayer));
							GetPlayerName(playerid, sendername, sizeof(sendername));
							format(string, sizeof(string), "* You have arrested %s to los santos prison for %d minutes.", giveplayer, money);
							SendClientMessage(playerid, COLOR_RED, string);
							format(string, sizeof(string), "[Prison] Officer %s have arrested %s for los santos prison to %d minutes.", sendername, giveplayer, money);
							SendClientMessageToAll(COLOR_RED, string);
							format(string, sizeof(string), "* You have been arrested for Los Santos Prison by %s for %d minutes.", sendername, money);
							SendClientMessage(playa, COLOR_YELLOWG, string);
							FullResetPlayerWeapons(playa);
							PlayerInfo[playa][pPrisoned] = 5;
							PlayerInfo[playa][pPrisonTime] = money;
							PlayerInfo[playa][pJailCell] = cell;
							PlayerInfo[playa][pArrested] += 1;
							new year, month,day;
							getdate(year, month, day);
							day += money;
							while(day > 31)
							{
								day -= 31;
								month++;
							}
							while(month > 12)
							{
							    month -= 12;
							    year++;
							}
							if(PlayerInfo[playa][pJailCell] == 1)
		    					SetPlayerPos(playa,1827.8213,-1731.9299,5202.5859);
		    				else if(PlayerInfo[playa][pJailCell] == 2)
								SetPlayerPos(playa,1831.0103,-1731.8927,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 3)
								SetPlayerPos(playa,1834.0918,-1732.0209,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 4)
								SetPlayerPos(playa,1837.2913,-1730.9072,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 5)
								SetPlayerPos(playa,1840.5859,-1731.9993,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 6)
								SetPlayerPos(playa,1843.7784,-1732.3024,5202.5859);	
							else if(PlayerInfo[playa][pJailCell] == 7)
								SetPlayerPos(playa,1843.7201,-1711.8350,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 8)
								SetPlayerPos(playa,1840.3660,-1712.1101,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 9)
								SetPlayerPos(playa,1837.1741,-1711.9928,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 10)
								SetPlayerPos(playa,1833.9534,-1712.1176,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 11)
								SetPlayerPos(playa,1830.5641,-1711.7528,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 12)
								SetPlayerPos(playa,1827.4946,-1711.4478,5202.5859);
							else if(PlayerInfo[playa][pJailCell] == 13)
								SetPlayerPos(playa,1827.7543,-1711.7517,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 14)
								SetPlayerPos(playa,1830.7646,-1711.9414,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 15)
								SetPlayerPos(playa,1834.0128,-1711.8164,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 16)
								SetPlayerPos(playa,1837.3129,-1711.6401,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 17)
								SetPlayerPos(playa,1840.5027,-1711.7007,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 18)
								SetPlayerPos(playa,1843.6472,-1711.7065,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 19)
								SetPlayerPos(playa,1843.6439,-1731.7734,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 20)
								SetPlayerPos(playa,1840.4283,-1731.8011,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 21)
								SetPlayerPos(playa,1837.1818,-1731.8258,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 22)
								SetPlayerPos(playa,1834.2139,-1732.4745,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 23)
								SetPlayerPos(playa,1831.0645,-1731.7957,5206.1860);
							else if(PlayerInfo[playa][pJailCell] == 24)
							SetPlayerPos(playa,1827.8179,-1731.8121,5206.1860);
							else
		    				{
								SetPlayerPos(playa,1827.5184,-1721.5369,5206.1860);
							}
							TogglePlayerControllable(playa, 0);
							hostimer[playa] = SetTimerEx("EnterHospital",2000,1,"d",playa);
							SetPlayerInterior(playa, 2);
		    				PlayerInfo[playa][pInt] = 2;
						}
					}
				}
			}
			else
			{
				SendClientMessage(playerid, COLOR_GREY, "{BCD4E6}Error: {FFFFFF}Sorry, you cant use this command.");
			}
		}
		return 1;
	}
setting timer on gamemode.
unprisontimer = SetTimer("SetFree", 60000, 1);
everyminute the time goes down by 1

the public
Code:
forward SetFree(playa);
public SetFree(playa)
{
	if(PlayerInfo[playa][pPrisoned] > 0)
	{
	if(PlayerInfo[playa][pPrisonTime] > 0)
	{
	PlayerInfo[playa][pPrisonTime]--;
	}
	if(PlayerInfo[playa][pPrisonTime] <= 0)
	{
	PlayerInfo[playa][pPrisonTime] = 0;
	
	if(PlayerInfo[playa][pPrisoned] == 5)
	{
    SetPlayerInterior(playa, 0);
	SetPlayerVirtualWorld(playa,0);
	MedicBill[playa] = 0;
	PlayerInfo[playa][pJailed] = 0;
    SetPlayerSpawn(playa);
	PlayerInfo[playa][pInt] = 0;
	PlayerInfo[playa][pVirWorld] = 0;
	PlayerInfo[playa][pJailCell] = 0;
	new string[256];
	format(string, sizeof(string), "~g~Freedom~n~~w~Try to be a better citizen");
	GameTextForPlayer(playa, string, 5000, 1);
	if(gTeam[playa] == 4) { 
	gTeam[playa] = 3; 
	}
	ClearCrime(playa);
	SetPlayerToTeamColor(playa);
			}
		}
	}	
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)