Only drive-able on duty
#1

I am creating a taxi job and i added vehicles with objects.
How do i make it, that you only can drive the vehicle when you are on taxi duty(so that passengers can still enter)?

When you go on taxi duty it does this:
PHP код:
PlayerInfo[playerid][TaxiDuty] = 1
This are the vehicles:
PHP код:
    g_Vehicle[9] = CreateVehicle(409952.2495, -1354.021213.1623271.494266, -1); //Stretch
    
g_Vehicle[10] = CreateVehicle(560966.7414, -1355.274713.0566179.64406175, -1); //Sultan
    
g_Vehicle[11] = CreateVehicle(420950.9326, -1390.557313.080490.2256612, -1); //Taxi
    
g_Vehicle[12] = CreateVehicle(438958.2101, -1390.483513.283988.7154670, -1); //Cabbie 
Reply
#2

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    
// check if vehicle id is g_Vehicle and the player is not on duty
    // if it is, send message and return 0.
    //else return 1

Reply
#3

Here is an example:

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    
// check if vehicle id is g_Vehicle and the player is not on duty
    
if(vehicleid == g_Vehicle[9] && !PlayerInfo[playerid][TaxiDuty]) {
        
// if it is, send message and return 0.
        
return 0;
    }
    
    
//else return 1
    
return 1;

Reply
#4

I did this but it doesn't work:
PHP код:
    new g_Vehicle[13];
    if(
GetVehicleModel(g_Vehicle[9]))
    {
        if(
PlayerInfo[playerid][TaxiDuty] == 0)
        {
            
RemovePlayerFromVehicle(playerid);
            
SendClientMessage(playeridCOLOR_RED"You are not on taxi duty!");
        }
    }
    return 
1
Reply
#5

That won't work because, GetVehicleModel returns modelid if the vehicle exists or 0 if the vehicle doesn't exists. So that piece of code never runs. More over, You declare new g_Vehicle just before that. Make it a variable on top of the script and then use it. Try my method, It's way easier.
Reply
#6

I have this now, but still doesn't work:
PHP код:
new g_Vehicle[13];
    if(
vehicleid == g_Vehicle[9] && PlayerInfo[playerid][TaxiDuty] == 0)
    {
        
SendClientMessage(playeridCOLOR_RED"You are not on taxi duty!");
        
RemovePlayerFromVehicle(playerid);
    } 
Reply
#7

PHP код:
new g_Vehicle[13]; 
You don't need that line! You use it once when you create the vehicles. Try to understand whats going on. You are setting an empty array. Ofcourse it will never work! Try it without that line.
Reply
#8

Put this somewhere:
PHP код:
stock in_array(needle, const haystack[], size sizeof haystack, &index 0)
{
    for(new 
isizei++)
    {
        if(
haystack[i] == needle)
        {
            
index i;
            return 
true;
        }
    }
        
    return 
false;

Then:
PHP код:
if(in_array(vehicleidg_Vehicle)  && PlayerInfo[playerid][TaxiDuty] == 0
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
Put this somewhere:
PHP код:
stock in_array(needle, const haystack[], size sizeof haystack, &index 0)
{
    for(new 
isizei++)
    {
        if(
haystack[i] == needle)
        {
            
index i;
            return 
true;
        }
    }
        
    return 
false;

Then:
PHP код:
if(in_array(vehicleidg_Vehicle)  && PlayerInfo[playerid][TaxiDuty] == 0
Can you explain Why we use index = i in the loop?
Reply
#10

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
Can you explain Why we use index = i in the loop?
Because it's there in the function, stating &index = 0
It can be used like this:

PHP код:
new true_or_false_shit;
in_array(the statements that should be used and thentrue_or_false_shit);
if(
true_or_false_shit == 1)
   print(
"it exists in the array"); 
I'm not sure why anyone would like to have their code like this but somewhy some people want so and it's just to accept it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)