SA-MP Forums Archive
OnPlayerDisconnected loops - 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: OnPlayerDisconnected loops (/showthread.php?tid=650407)



OnPlayerDisconnected loops - AstroPoid - 27.02.2018

is loops working under onplayerdisconnected callback ? , because its seems to be not working right there.


Re: OnPlayerDisconnected loops - PepsiCola23 - 27.02.2018

what are you trying to achieve exactly?


Re: OnPlayerDisconnected loops - AstroPoid - 27.02.2018

I want to know why the same code of onplayerdeath that contain loops , doesn't work under onplayerdisconnect. and nothing happened after.


Re: OnPlayerDisconnected loops - PepsiCola23 - 27.02.2018

atleast give a code


Re: OnPlayerDisconnected loops - AstroPoid - 27.02.2018

I don't understand why you need a code. anyways here is it
Код:
public OnPlayerDisconnect(playerid, reason) // loops didn't work while they do same functions
{
	for(new i=0; i < MAX_PLAYERS; i++)
	{
		if (TaxiDuty[playerid] == 1)
		{
	    	     TaxiDuty[playerid] = 0;
	    	     Drivers -= 1;
                }
	    	if(TaxiDuty[i] == 1)
	    	{
				SendClientMessage(i, COLOR, "Has left the game");
		}
	}
	return 1;
}
public OnPlayerDeath(playerid, killerid, reason) // worked well
{
	for(new i=0; i < MAX_PLAYERS; i++)
	{
		if (TaxiDuty[playerid] == 1)
		{
	    	     TaxiDuty[playerid] = 0;
	    	     Drivers -= 1;
                }
	    	if(TaxiDuty[i] == 1)
	    	{
				SendClientMessage(i, COLOR, "Has left the game");
		}
	}
	return 1;
}



Re: OnPlayerDisconnected loops - Dayrion - 27.02.2018

This is not OnPlayerDisconnect(playerid), it's OnPlayerDisconnect(playerid, reason)


Re: OnPlayerDisconnected loops - AstroPoid - 27.02.2018

Quote:
Originally Posted by Dayrion
Посмотреть сообщение
This is not OnPlayerDisconnect(playerid), it's OnPlayerDisconnect(playerid, reason)
Mehhhhh. i expected that.
its just a test code to explain what i need.


Re: OnPlayerDisconnected loops - kingmk - 27.02.2018

Quote:
Originally Posted by AstroPoid
Посмотреть сообщение
I don't understand why you need a code. anyways here is it
Код:
public OnPlayerDisconnect(playerid, reason)
{
	for(new i=0; i < MAX_PLAYERS; i++)
	{
		if (TaxiDuty[playerid] == 1)
		{
	    	     TaxiDuty[playerid] = 0;
	    	     Drivers -= 1;
                }
	    	if(TaxiDuty[i] == 1)
	    	{
				SendClientMessage(i, COLOR, "Has left the game");
		}
	}
	return 1;
}
public OnPlayerDeath(playerid, killerid, hittype) // worked well
{
	for(new i=0; i < MAX_PLAYERS; i++)
	{
		if (TaxiDuty[playerid] == 1)
		{
	    	     TaxiDuty[playerid] = 0;
	    	     Drivers -= 1;
                }
	    	if(TaxiDuty[i] == 1)
	    	{
				SendClientMessage(i, COLOR, "Has left the game");
		}
	}
	return 1;
}
lel, that's so wrong. You basically check MAX_PLAYERS times, if the player WHO DISSCONNECT have TaxiDuty[playerid] == 1.

I think u want something like so.

Код:
public OnPlayerDisconnect(playerid, reason)
{
       new string[150];
       if (TaxiDuty[playerid] == 1)
       {
                new name[35];
	        TaxiDuty[playerid] = 0;
	        Drivers -= 1;
                for(new i=0; i < MAX_PLAYERS; i++)
	        {
                     GetPlayerName(playerid, name, sizeof(name));
                     format(string, sizeof(string), "%s has left the game", name);
                     SendClientMessage(i, -1, string);
                }
                  
       }
	return 1;
}
This can also be replace with
Код:
                for(new i=0; i < MAX_PLAYERS; i++)
	        {
                     GetPlayerName(playerid, name, sizeof(name));
                     format(string, sizeof(string), "%s has left the game", name);
                     SendClientMessage(i, -1, string);
                }
with this
Код:
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s has left the game", name);
SendClientMessageToAll(-1, string);



Re: OnPlayerDisconnected loops - AstroPoid - 27.02.2018

Guys , i don't need to fix the code. its just an example.
my problem is the whole code is not responding if it putted under onplayerdisconnect also under a loop. thats all
same code with same functions on player death that worked perfectly coping and pasting them at onplayerdisconnect, but it doesn't responde at all


Re: OnPlayerDisconnected loops - kingmk - 27.02.2018

Quote:
Originally Posted by AstroPoid
Посмотреть сообщение
Guys , i don't need to fix the code. its just an example.
my problem is the whole code is not responding if it putted under onplayerdisconnect also under a loop. thats all
same code with same functions on player death coping and pasting them at onplayerdisconnect, but it doesn't responde at all
Yes loops work on OnPlayerDisconnect, u just need to put them right.