SA-MP Forums Archive
OnPlayerDisconnect [REPS Ofcourse :D] - 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: OnPlayerDisconnect [REPS Ofcourse :D] (/showthread.php?tid=491949)



OnPlayerDisconnect [REPS Ofcourse :D] - MahdiGames - 01.02.2014

Hello iv problem i maked that on player disconnect destroy his vehicle but what about if the player was Facilities (passenger) , so when a player get in my car and disconnect the car is destroy even if i was the Leadership here is the code:

Код:
public OnPlayerDisconnect(playerid, reason)
{
SetVehicleToRespawn(GetPlayerVehicleID(playerid));	
return 1;
}
How to ask if the playerid was Passenger return 0 ? or something like that , Thanks


Re: OnPlayerDisconnect [REPS Ofcourse :D] - TheFlyer - 01.02.2014

You mean when you disconnect the car respawns, and when a passenger disconnects if your the leadership you want the car not to respawn? I think this is how its made :P

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new iSeat = GetPlayerVehicleSeat(playerid);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(iSeat >= 1)
        {
            // Do nothing
        }
        else
        {
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        }
    }
    return 1;
}



Re: OnPlayerDisconnect [REPS Ofcourse :D] - Duck4coder - 01.02.2014

Quote:
Originally Posted by TheFlyer
Посмотреть сообщение
You mean when you disconnect the car respawns, and when a passenger disconnects if your the leadership you want the car not to respawn? I think this is how its made :P

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new iSeat = GetPlayerVehicleSeat(playerid);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(iSeat >= 1)
        {
            // Do nothing
        }
        else
        {
            SetVehicleToRespawn(GetPlayerVehicleID(playerid));
        }
    }
    return 1;
}
That wouldn't actually work, I would only do nothing if the player that disconnects is in the front passenger, if you use

Код:
public OnPlayerDisconnect(playerid, reason)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		SetVehicleToRespawn(GetPlayerVehicleID(playerid));
	}
	else
	{
		//Do Nothing
	}
	return 1;
}
This would allow it to only destroy the vehicle if the driver disconnects


Re: OnPlayerDisconnect [REPS Ofcourse :D] - MahdiGames - 01.02.2014

Quote:
Originally Posted by Duck4coder
Посмотреть сообщение
That wouldn't actually work, I would only do nothing if the player that disconnects is in the front passenger, if you use

Код:
public OnPlayerDisconnect(playerid, reason)
{
    for(new i = 0; i < MAX_PLAYERS; i++)
	if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
	{
		SetVehicleToRespawn(GetPlayerVehicleID(playerid));
	}
	else
	{
		//Do Nothing
	}
	return 1;
}
This would allow it to only destroy the vehicle if the driver disconnects
Helped thanks +rep && ~~CLOSED~~


Re: OnPlayerDisconnect [REPS Ofcourse :D] - CuervO - 01.02.2014

I recommend using this instead since what the code posted above does is remove the vehicle 500 times if the player is a driver.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            new people;
            for(new i = 0; i < MAX_PLAYERS; i ++)
            {
                if(!IsPlayerConnected(i))
                    continue;

                if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_PASSENGER)
                    people ++;
            }
            if(!people)
                SetVehicleToRespawn(vehicleid);
        }
    }
    return 1;
}
This code will respawn the vehicle if the driver disconnects and there's no one else in the vehicle, otherwise it'll keep it.


Re: OnPlayerDisconnect [REPS Ofcourse :D] - MahdiGames - 02.02.2014

Quote:
Originally Posted by CuervO
Посмотреть сообщение
I recommend using this instead since what the code posted above does is remove the vehicle 500 times if the player is a driver.

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicleid = GetPlayerVehicleID(playerid);
            new people;
            for(new i = 0; i < MAX_PLAYERS; i ++)
            {
                if(!IsPlayerConnected(i))
                    continue;

                if(GetPlayerVehicleID(i) == vehicleid && GetPlayerState(i) == PLAYER_STATE_PASSENGER)
                    people ++;
            }
            if(!people)
                SetVehicleToRespawn(vehicleid);
        }
    }
    return 1;
}
This code will respawn the vehicle if the driver disconnects and there's no one else in the vehicle, otherwise it'll keep it.
Thanks!! are u sure its working?