[HELP] Many private cars
#1

How can I make this code more private cars?

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    new 
pname[MAX_PLAYER_NAME];
    new 
car;
    
car AddStaticVehicle(437,-709.94384766,912.88665771,12.69688034,90.00000000,-1,3);
    
GetPlayerName(playeridpnamesizeof pname);
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        if(
vehicleid == car)
        {
            if(
strcmp(pname"Name"true) == 0)
              {
                return 
1;
            }
            else
              {
              
RemovePlayerFromVehicle(playerid);
            new 
string[50];
            
format(stringsizeof(string), "~r~This car is private!");
            
GameTextForPlayer(playeridstring30004);
            }
        }
}
    return 
1;

To not do so on each machine:
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    new 
pname[MAX_PLAYER_NAME];
    new 
car2;
    
car2 AddStaticVehicle(437,-709.94384766,912.88665771,12.69688034,90.00000000,-1,3);
    
GetPlayerName(playeridpnamesizeof pname);
    if(
newstate == PLAYER_STATE_DRIVER)
    {
        if(
vehicleid == car2)
        {
            if(
strcmp(pname"Name"true) == 0)
              {
                return 
1;
            }
            else
              {
              
RemovePlayerFromVehicle(playerid);
            new 
string[50];
            
format(stringsizeof(string), "~r~This car is private!");
            
GameTextForPlayer(playeridstring30004);
            }
        }
}
    return 
1;

Reply
#2

pawn Код:
new
    car[ 2 ] // increase the size to create more private vehs
;

public OnGameModeInit( )
{
    car[ 0 ] = addstaticveh....
    car[ 1 ] = addstaticveh....
    // why no 2 when the car[ 2 ] ? because it starts from 0.

    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new pname[MAX_PLAYER_NAME];

    GetPlayerName(playerid, pname, sizeof pname);

    if(newstate == PLAYER_STATE_DRIVER)
    {
        for ( new j = sizeof ( car ), i; i < j; i ++ ) // if its not working try 'for ( new j = sizeof ( car - 1 ), i; i < j; i ++ )
        {
            if ( vehicleid == car[ j ] )
            {
                if(strcmp(pname, "Name", true) == 0)
                {
                    return 1;
                }
                else
                {
                      RemovePlayerFromVehicle(playerid);
                     new string[50];
                     format(string, sizeof(string), "~r~This car is private!");
                     GameTextForPlayer(playerid, string, 3000, 4);
                }
             }
         }
    }
    return 1;
}
Hope it helps
Reply
#3

Quote:
Originally Posted by Basicz
Посмотреть сообщение
pawn Код:
new
    car[ 2 ] // increase the size to create more private vehs
;

public OnGameModeInit( )
{
    car[ 0 ] = addstaticveh....
    car[ 1 ] = addstaticveh....
    // why no 2 when the car[ 2 ] ? because it starts from 0.

    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new pname[MAX_PLAYER_NAME];

    GetPlayerName(playerid, pname, sizeof pname);

    if(newstate == PLAYER_STATE_DRIVER)
    {
        for ( new j = sizeof ( car ), i; i < j; i ++ ) // if its not working try 'for ( new j = sizeof ( car - 1 ), i; i < j; i ++ )
        {
            if ( vehicleid == car[ j ] )
            {
                if(strcmp(pname, "Name", true) == 0)
                {
                    return 1;
                }
                else
                {
                      RemovePlayerFromVehicle(playerid);
                     new string[50];
                     format(string, sizeof(string), "~r~This car is private!");
                     GameTextForPlayer(playerid, string, 3000, 4);
                }
             }
         }
    }
    return 1;
}
Hope it helps
Thanks, but still no works with successful compilation.
Reply
#4

There are alternatives?
Reply
#5

that will only let you have it if your name is name how do you know who the owner is?
Reply
#6

Hmm, it should works.
Did you even see this comment?

pawn Код:
// if its not working try 'for ( new j = sizeof ( car - 1 ), i; i < j; i ++ )
Don't create vehicle on OnPlayerStateChange
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)