SA-MP Forums Archive
how people do not enter in this car ID - 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 people do not enter in this car ID (/showthread.php?tid=631161)



how people do not enter in this car ID - Jihanz - 24.03.2017

help me please

this my stock
PHP код:
stock ForTaxiJob(vehicleid)
{
     switch(
GetVehicleModel(vehicleid))
     {
      case 
420,438: return 1;
      }
      return 
0;




Re: how people do not enter in this car ID - Jelly23 - 24.03.2017

First of all, it's a function, not a "stock". If you want to stop people from entering those vehicles, just use that function of yours on OnPlayerEnterVehicle, or just put the code in the callback. If the vehicle model matches, clear player animations to stop them from entering it.


Re: how people do not enter in this car ID - w1z4rd - 24.03.2017

As Jelly23 said it would be better to use callback, in your stock you dont have playerid so you would have to loop through every player on server so it would take a while.
Insted you could use something like this in OnPlayerEnterVehicle callback
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid==420 || vehicleid == 438)
	{
		RemovePlayerFromVehicle(playerid);
		// Or if he didn't enter already and is about to enter then it's an animation
		// then use ClearAnimations(playerid);
		return SendClientMessage(playerid, 0xFF0000FF, "You cant enter this vehicle");
	}   
}



Re: how people do not enter in this car ID - Jihanz - 24.03.2017

Quote:
Originally Posted by w1z4rd
Посмотреть сообщение
As Jelly23 said it would be better to use callback, in your stock you dont have playerid so you would have to loop through every player on server so it would take a while.
Insted you could use something like this in OnPlayerEnterVehicle callback
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid==420 || vehicleid == 438)
	{
		RemovePlayerFromVehicle(playerid);
		// Or if he didn't enter already and is about to enter then it's an animation
		// then use ClearAnimations(playerid);
		return SendClientMessage(playerid, 0xFF0000FF, "You cant enter this vehicle");
	}   
}
Thanks Alot sir


Re: how people do not enter in this car ID - ISmokezU - 24.03.2017

Quote:
Originally Posted by w1z4rd
Посмотреть сообщение
As Jelly23 said it would be better to use callback, in your stock you dont have playerid so you would have to loop through every player on server so it would take a while.
Insted you could use something like this in OnPlayerEnterVehicle callback
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vehicleid==420 || vehicleid == 438)
	{
		RemovePlayerFromVehicle(playerid);
		// Or if he didn't enter already and is about to enter then it's an animation
		// then use ClearAnimations(playerid);
		return SendClientMessage(playerid, 0xFF0000FF, "You cant enter this vehicle");
	}   
}
Uh, why would you use RemovePlayerFromVehicle And the player isn't in a vehicle? Even the wiki provides a good example.

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger) {
    if(
vehicleid==420 || vehicleid == 438)     {
        new 
Float:Pos[3];//Not Fast.
                
GetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
                
SetPlayerPos(playeridPos[0], Pos[1], Pos[2]);
                
SendClientMessage(playerid0xFF0000FF"You cant enter this vehicle");
        return 
true;
    } 
That's Preventing them from entering the vehicle. ( https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle ).

If you want the player to enter the vehicle then remove them, then you use, ( https://sampwiki.blast.hk/wiki/OnPlayerEnterVehicle ).


Re: how people do not enter in this car ID - Mencent - 24.03.2017

Hello!

@w1z4rd: and @ISmokezU:

It should be like this because you check the vehicleid but it has to be check the modelid.
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    new 
modelid GetVehicleModel(vehicleid);
    if(
modelid == 420 || modelid == 438)
    {
        
RemovePlayerFromVehicle(playerid);
        
// Or if he didn't enter already and is about to enter then it's an animation
        // then use ClearAnimations(playerid);
        
return SendClientMessage(playerid0xFF0000FF"You cant enter this vehicle");
    }
    return 
1;




Re: how people do not enter in this car ID - jasperschellekens - 24.03.2017

How would that even work with OnPlayerEnterVehicle?
Use OnPlayerStateChange


PHP код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(
GetVehicleModel(GetPlayerVehicleID(playerid)) == 416// Ambulance vehicle ID
    
{
        if(
PlayerInfo[playerid][MDuty] == 0)  // If the player isn't on medic duty
        
{
              
RemovePlayerFromVehicle(playerid); // If the player isn't on medic duty remove him from car
            
SendClientMessage(playeridCOLOR_RED"You are not on medic duty!");
         }
    }
    return 
1;




Re: how people do not enter in this car ID - Jihanz - 24.03.2017

Thanks all