SA-MP Forums Archive
Check unjail - 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: Check unjail (/showthread.php?tid=648508)



Check unjail - Longover - 23.01.2018

Hello!
I'm have a big problem:
I'm created a check for player is jailed
Код:
Variables:
unjailtimer,
PlayerText:Jailtime[MAX_PLAYERS],
Under ongamemodeinit
unjailtimer = SetTimer("SetPlayerUnjail", 1000, 1);---------check
Under GameModeExitFunc:
KillTimer(unjailtimer);
The public "SetPlayerUnjail"(IsToCheck)
public SetPlayerUnjail()
{
 	foreach(Player, i)
 	{
	if(Player[i][Jailed] > 0)
 	{
		if(Player[i][JailTime] > 0)
		{
			Player[i][JailTime]--;
			PlayerTextDrawShow(i, Jailtime[i]);
			new string3[60];
			format(string3,sizeof(string3),"ELIBERAT IN: ~r~%d MINUTE", Player[i][JailTime]/60+1);
			PlayerTextDrawSetString(i, Jailtime[i], string3);
		}
	}
	if(Player[i][JailTime] <= 0)
	{
		Player[i][JailTime] = 0;
		if(Player[i][Jailed] == 1)
		 	{
				SetPlayerInterior(i, 6);
		    	SetPlayerPos(i, 268.7461,76.8184,1001.0391);
			}
		if(Player[i][Jailed] == 2)
			{
			SetPlayerInterior(i, 0);
			SetPlayerVirtualWorld(i, 0);
			SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
			}
	}
	Player[i][Jailed] = 0;
	SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");----Line 9442
	SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
	PlayerTextDrawHide(i, Jailtime[i]);
	TogglePlayerControllable(i, 1);
	}
}
From second to second I display the message setplayerunjail (line 9442)
Why?
(for help: Line 9442 translated is "Your time is up! You have been relased from jail/prison.")
(sorry for my bad english)
EDIT: If i'm enter in jail,im released in 1 second from jail!


Re: Check unjail - Sew_Sumi - 23.01.2018

It's because that segment of code is shown because it's out of the loops, and you aren't excluding it.

Код:
}
	Player[i][Jailed] = 0;
	SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");----Line 9442
	SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
	PlayerTextDrawHide(i, Jailtime[i]);
	TogglePlayerControllable(i, 1);
All of that, should be in the previous loop where it's checking if the jailtime is up, not outside the loop.

Код:
if(Player[i][JailTime] <= 0)
	{
		Player[i][JailTime] = 0;
		if(Player[i][Jailed] == 1)
		 	{
				SetPlayerInterior(i, 6);
		    	SetPlayerPos(i, 268.7461,76.8184,1001.0391);
			}
		if(Player[i][Jailed] == 2)
			{
			SetPlayerInterior(i, 0);
			SetPlayerVirtualWorld(i, 0);
			SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
			}
        Player[i][Jailed] = 0;
        SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");----Line 9442
        SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
        PlayerTextDrawHide(i, Jailtime[i]);
        TogglePlayerControllable(i, 1);
	}
	
	}
You will need to test this thoroughly as it's a blind paste, but it's likely to be that, that the reason it was showing is because it's in the wrong section of the loop.


Re: Check unjail - Longover - 23.01.2018

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
It's because that segment of code is shown because it's out of the loops, and you aren't excluding it.

Код:
}
	Player[i][Jailed] = 0;
	SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");----Line 9442
	SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
	PlayerTextDrawHide(i, Jailtime[i]);
	TogglePlayerControllable(i, 1);
All of that, should be in the previous loop where it's checking if the jailtime is up, not outside the loop.

Код:
if(Player[i][JailTime] <= 0)
	{
		Player[i][JailTime] = 0;
		if(Player[i][Jailed] == 1)
		 	{
				SetPlayerInterior(i, 6);
		    	SetPlayerPos(i, 268.7461,76.8184,1001.0391);
			}
		if(Player[i][Jailed] == 2)
			{
			SetPlayerInterior(i, 0);
			SetPlayerVirtualWorld(i, 0);
			SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
			}
        Player[i][Jailed] = 0;
        SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");----Line 9442
        SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
        PlayerTextDrawHide(i, Jailtime[i]);
        TogglePlayerControllable(i, 1);
	}
	
	}
You will need to test this thoroughly as it's a blind paste, but it's likely to be that, that the reason it was showing is because it's in the wrong section of the loop.
Sorry but 10 minutes ago i'm edited code in:
Код:
public SetPlayerUnjail()
{
 	foreach(Player, i)
 	{
	if(Player[i][Jailed] > 0)
 	{
		if(Player[i][JailTime] > 0)
		{
			Player[i][JailTime]--;
			PlayerTextDrawShow(i, Jailtime[i]);
			new string3[60];
			format(string3,sizeof(string3),"ELIBERAT IN: ~r~%d MINUTE", Player[i][JailTime]/60+1);
			PlayerTextDrawSetString(i, Jailtime[i], string3);
		}
	}
	else if(Player[i][JailTime] <= 0)
	{
		Player[i][JailTime] = 0;
		if(Player[i][Jailed] == 1)
		 	{
		 	    Player[i][Jailed] = 0;
				SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");
				SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
				PlayerTextDrawHide(i, Jailtime[i]);
				TogglePlayerControllable(i, 1);
				SetPlayerInterior(i, 6);
		    	SetPlayerPos(i, 268.7461,76.8184,1001.0391);
			}
		if(Player[i][Jailed] == 2)
			{
			Player[i][Jailed] = 0;
			SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");
			SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
			PlayerTextDrawHide(i, Jailtime[i]);
			TogglePlayerControllable(i, 1);
			SetPlayerInterior(i, 0);
			SetPlayerVirtualWorld(i, 0);
			SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
			}
	}
	}
}
and now not work


Re: Check unjail - Sew_Sumi - 23.01.2018

That's not how I put the code up, why have you tried to change this?


The reason why it's not working is up top, you check first if Jailed is greater than 0, then you an ELSE IF statement, which means if it gets a hit on Jailed, it won't check the jailtime for the second check.



This should not be an else if, it should be an if.


I'd highly suggest you optimize your checks, and output. As I put up, the code goes through once, and shows the result... Your code duplicates lines for the sake of nothing.

The output that you had outside the loop was working, because it was outside of the checks, and now it's inside it's not working because of the else if statement.


Re: Check unjail - Longover - 23.01.2018

Код:
public SetPlayerUnjail()
{
 	foreach(Player, i)
 	{
	if(Player[i][Jailed] > 0)
 	{
	if(Player[i][JailTime] > 0)
	{
		Player[i][JailTime]--;
		PlayerTextDrawShow(i, Jailtime[i]);
		new string3[60];
		format(string3,sizeof(string3),"ELIBERAT IN: ~r~%d MINUTE", Player[i][JailTime]/60+1);
		PlayerTextDrawSetString(i, Jailtime[i], string3);
	}
	}
	if(Player[i][JailTime] <= 0)
	{
		Player[i][JailTime] = 0;
		if(Player[i][Jailed] == 1)
		{
			SetPlayerInterior(i, 6);
		    SetPlayerPos(i, 268.7461,76.8184,1001.0391);
		}
		if(Player[i][Jailed] == 2)
		{
			SetPlayerInterior(i, 0);
			SetPlayerVirtualWorld(i, 0);
			SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
		}
		Player[i][Jailed] = 0;
		SendClientMessage(i, COLOR_WHITE, "Ti-ai ispasit pedeapsa,sa nu mai faci vreo boacana.");
		SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
		PlayerTextDrawHide(i, Jailtime[i]);
		TogglePlayerControllable(i, 1);
	}
	}
}
tis is code
-
-
-
Not Work,same problem.


Re: Check unjail - Sew_Sumi - 23.01.2018

Is it even updating the time remaining?

use to paste code. Otherwise all formatting is lost and it looks like dogshit.


Chuck me a PM with what script it is as well if you can.

Edit - Have you tried going back to the initial scripts code, and looked at what else you've changed from that?

It looks fine, but it's quite different to what you've brought out. I'd be looking at where '[JailTime]' is being set in the script, maybe also put a line, that when you get jailed, it then gives you the JailTime back to you in seconds without having it changed to mins/seconds. Just a SendClientMessage would do it.

Код:
public SetPlayerUnjail()
{
	foreach(Player, i)
	{
		if(Player[i][JailTime] != 0)
		{
			if(Player[i][LoggedIn] == 1)
			{
				Player[i][JailTime]--;
				PlayerTextDrawShow(i, Jailtime[i]);
				new string3[60];
				format(string3,sizeof(string3),"ELIBERAT IN: ~r~%d MINUTE", Player[i][JailTime]/60+1);
				StopAudioStreamForPlayer(i);
				PlayerTextDrawSetString(i, Jailtime[i], string3);
			}
		}
		if(Player[i][JailTime] <= 0)
		{
			Player[i][JailTime] = 0;
			if(Player[i][Jailed] == 1)
			{
				SetPlayerInterior(i, 6);
		    	SetPlayerPos(i, 268.7461,76.8184,1001.0391);
		    	Player[i][Jailed] = 0;
				SendClientMessage(i, COLOR_WHITE, "Ai fost eliberat din inchisoare,sa nu mai faci vreo boacana...");
				SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
				PlayerTextDrawHide(i, Jailtime[i]);
				TogglePlayerControllable(i, 1);
				StopAudioStreamForPlayer(i);
			}
			if(Player[i][Jailed] == 2)
			{
				SetPlayerInterior(i, 0);
				SetPlayerVirtualWorld(i, 0);
				SetPlayerPos(i, 1800.1581,-1865.7731,13.5722);
				Player[i][Jailed] = 0;
				SendClientMessage(i, COLOR_WHITE, "Ai fost eliberat din inchisoare,sa nu mai faci vreo boacana...");
				SetPlayerSpecialAction(i,SPECIAL_ACTION_NONE);
				PlayerTextDrawHide(i, Jailtime[i]);
				TogglePlayerControllable(i, 1);
				StopAudioStreamForPlayer(i);
			}
		}
	}
}