how people do not enter in this car ID
#1

help me please

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

Reply
#2

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.
Reply
#3

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");
	}   
}
Reply
#4

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
Reply
#5

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 ).
Reply
#6

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;

Reply
#7

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;

Reply
#8

Thanks all
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)