SA-MP Forums Archive
How can i explain this function? - 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: How can i explain this function? (/showthread.php?tid=308173)



How can i explain this function? - Artie_Scorpion - 02.01.2012

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
	{
		//If they got into a car from being on foot.
		if( GetVehicleModel(GetPlayerVehicleID( playerid )) == 428 )
		{
			if( GetPlayerSkin(playerid) != 27 )
			{
				//If their skin is not 27
				//Remove them and send message.
				RemovePlayerFromVehicle( playerid );
				SendClientMessage( playerid,0xFF000000, "Noredami vairuoti si transporta turite buti elektriku" ); //-1
				return 1;
			}
			else
			{
				SendClientMessage(playerid, 0xFF000000, "Atsisedote i transporta. Jeigu dirbate, tada dirbkite savo darba");
				return 1;
			}
		}
	}
	return 1;
}
How can i make more drivable cars for other skins... Or more cars for same skin?


Re: How can i explain this function? - Artie_Scorpion - 02.01.2012

help me!!!


Re: How can i explain this function? - Danyal - 02.01.2012

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
        //If they got into a car from being on foot.
        if( GetVehicleModel(GetPlayerVehicleID( playerid )) == 428 )
        {
            if( GetPlayerSkin(playerid) != 27 ) ||  GetPlayerSkin(playerid) != /*skin id here*/ ||  GetPlayerSkin(playerid) != /* second skin id here*/ ||  GetPlayerSkin(playerid) != /* third skin id here*/ ||  GetPlayerSkin(playerid) != /*and so on...............*/   )
            {
                //If their skin is not 27
                //Remove them and send message.
                RemovePlayerFromVehicle( playerid );
                SendClientMessage( playerid,0xFF000000, "Noredami vairuoti si transporta turite buti elektriku" ); //-1
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFF000000, "Atsisedote i transporta. Jeigu dirbate, tada dirbkite savo darba");
                return 1;
            }
        }
    }
    return 1;
}



Re: How can i explain this function? - Artie_Scorpion - 02.01.2012

Quote:
Originally Posted by Danyal
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
        //If they got into a car from being on foot.
        if( GetVehicleModel(GetPlayerVehicleID( playerid )) == 428 )
        {
            if( GetPlayerSkin(playerid) != 27 ) ||  GetPlayerSkin(playerid) != /*skin id here*/ ||  GetPlayerSkin(playerid) != /* second skin id here*/ ||  GetPlayerSkin(playerid) != /* third skin id here*/ ||  GetPlayerSkin(playerid) != /*and so on...............*/   )
            {
                //If their skin is not 27
                //Remove them and send message.
                RemovePlayerFromVehicle( playerid );
                SendClientMessage( playerid,0xFF000000, "Noredami vairuoti si transporta turite buti elektriku" ); //-1
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFF000000, "Atsisedote i transporta. Jeigu dirbate, tada dirbkite savo darba");
                return 1;
            }
        }
    }
    return 1;
}
How with more cars?


Re: How can i explain this function? - KingHual - 02.01.2012

Use GetVehicleModel for GetPlayerVehicleID(playerid) https://sampwiki.blast.hk/wiki/GetVehicleModel


Re: How can i explain this function? - pmk1 - 02.01.2012

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
    //If they got into a car from being on foot.
        if( GetVehicleModel(GetPlayerVehicleID( playerid )) == 428 || /*2nd model*/ || /*3rd model*/ || /* & so on..*/)
        {
            if( GetPlayerSkin(playerid) != 27 || /*2nd model*/ || /*3rd model*/ || /* & so on..*/ )
            {
                //If their skin is not 27
                //Remove them and send message.
                RemovePlayerFromVehicle( playerid );
                SendClientMessage( playerid,0xFF000000, "Noredami vairuoti si transporta turite buti elektriku" );//-1
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFF000000, "Atsisedote i transporta. Jeigu dirbate, tada dirbkite savo darba");
                return 1;
            }
        }
    }
    return 1;
}
it's better like this


Re: How can i explain this function? - KingHual - 02.01.2012

Quote:
Originally Posted by pmk1
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if( oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER )
    {
    //If they got into a car from being on foot.
        if( GetVehicleModel(GetPlayerVehicleID( playerid )) == 428 || 429 || 430 || 431)
        {
            if( GetPlayerSkin(playerid) != 27 || 28 || 65 || 66 )
            {
                //If their skin is not 27
                //Remove them and send message.
                RemovePlayerFromVehicle( playerid );
                SendClientMessage( playerid,0xFF000000, "Noredami vairuoti si transporta turite buti elektriku" );//-1
                return 1;
            }
            else
            {
                SendClientMessage(playerid, 0xFF000000, "Atsisedote i transporta. Jeigu dirbate, tada dirbkite savo darba");
                return 1;
            }
        }
    }
    return 1;
}
it's better like this
I'm pretty sure using Switch and Case is better.