Vehicle for specific player
#1

Код:
PlayerPrivateVehicle[???][name]=CreateVehicle(....
Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(vechileid==PlayerPrivateVehicle[???][name])
        {
        new string[64];
        format(string, sizeof(string),This car is owned by %s", name);
        SendClientMessage(playerid, -1, string);
        }
	return 1;
}
I'm trying to create private vehicle system and I don't really know how to create car for specific player when he joins server. I think I could use for cycle for vehicle ID creating, something like
Код:
for(new i; i<MAX_VEHICLES; i++) { if(PlayerPrivateVehicle[i][name]==0){ PlayerPrivateVehicle[i][name]=CreateVehicle(....);} }
But I still don't know how to set vehicle for one specific player...
Reply
#2

You should create a vehicle array
PHP код:
// global
new gVehicleOwner[MAX_VEHICLES 1]; 
The code gets way more simply
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate) {
    if(
newstate == PLAYER_STATE_DRIVER) {
        new
            
vehicleid GetPlayerVehicleID(playerid),
            
owner gVehicleOwner[vehicleid]
        ;
        if(
owner == INVALID_PLAYER_ID) {
            
// vehicle has no owner
        
} else {
            if(
owner == playerid) {
                
// Vehicle is owned by playerid
            
} else {
                
// Vehicle isn't owned by playerid
                
RemovePlayerFromVehicle(playerid);
            }
            new 
string[64];
            
GetPlayerName(ownerstringMAX_PLAYER_NAME);
            
format(stringsizeof(string), "This car is owned by %s"string);
            
SendClientMessage(playerid, -1string);
        }
    }
    return 
1;

Reply
#3

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger)
{
    new 
name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridnamesizeof(name));
        if(!
strcmp(name,"KillerDVX",true))
        {
          new 
string[64];
          
format(stringsizeof(string),This car is owned by %s", name);
          SendClientMessage(playerid, -1, string);
        }
    return 1;

Reply
#4

I still don't get how to create car for player...
Reply
#5

You can make like this
Код:
 new playercar[MAX_PLAYERS]; 
playercar[playerid] = CreateVehicle(411,0,0,0,2,-1,-1,3600);

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) 
{ 
  if(vehicleid==playercar[playerid])
  {
    SendClientMessage(playerid,-1,This is your car!);
  }
}
Reply
#6

Quote:
Originally Posted by Mister0
Посмотреть сообщение
You can make like this
Код:
 new playercar[MAX_PLAYERS]; 
playercar[playerid] = CreateVehicle(411,0,0,0,2,-1,-1,3600);

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger) 
{ 
  if(vehicleid==playercar[playerid])
  {
    SendClientMessage(playerid,-1,This is your car!);
  }
}
And if other player tries to enter car, how do I show him that car owner?
Reply
#7

PHP код:
new PlayerIDCar[MAX_VEHICLES];
new 
playercar[MAX_PLAYERS]; 
playercar[playerid] = CreateVehicle(411,0,0,0,2,-1,-1,3600);
PlayerIDCar[playercar[playerid] ] = playerid
PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger

  if(
vehicleid==playercar[playerid])
  {
    
SendClientMessage(playerid,-1,This is your car!);
  }
  else
  {
   new 
str[128];
   
format(str,sizeof(str),"This car is owned by %s",PlayerName(PlayerIDCar[vehicleid ] ) )
  
SendClientMessage(playerid,-1,str);
  }

And don't forget to destroy the car

OnPlayerDisconnect(playerid)
{
if(IsValidVehicle(playercar[playerid])
DestroyVehicle(playercar[playerid]);
}
Reply
#8

PHP код:
public OnPlayerEnterVehicle(playeridvehicleidispassenger

    if(
vehicleid==playercar[playerid])
    {
        
SendClientMessage(playerid,-1"This is your car!");
    }
    else
    {
        
SendClientMessage(playerid, -1"This is not your car!");
    }

Edit: Too late.
Reply
#9

pawn Код:
// global
new gVehicleOwner[MAX_VEHICLES + 1] = {INVALID_PLAYER_ID, ...};

new vehicleid = CreateVehicle(411,0,0,0,2,-1,-1,3600);
gVehicleOwner[vehicleid] = playerid;

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{

    if(gVehicleOwner[vehicleid] != INVALID_PLAYER_ID)
        if(gVehicleOwner[vehicleid] != playerid)
        {
            new string[64];
            GetPlayerName(gVehicleOwner[vehicleid], string, MAX_PLAYER_NAME);
            format(string, sizeof(string), "This car is owned by %s", string);
            SendClientMessage(playerid, -1, string);
            ClearAnimations(playerid);
        }

    return 1;
}
and for destroy

Change all DestroyVehicle to DestroyVehicleEx

pawn Код:
DestroyVehicleEx(vehicleid)
{
    if(!(0 < vehicleid < sizeof(gVehicleOwner))) return 0;
    gVehicleOwner[vehicleid] = INVALID_PLAYER_ID;
    return DestroyVehicle(vehicleid);
}
Reply
#10

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
// global
new gVehicleOwner[MAX_VEHICLES + 1] = {INVALID_PLAYER_ID, ...};

new vehicleid = CreateVehicle(411,0,0,0,2,-1,-1,3600);
gVehicleOwner[vehicleid] = playerid;

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{

    if(gVehicleOwner[vehicleid] != INVALID_PLAYER_ID)
        if(gVehicleOwner[vehicleid] != playerid)
        {
            new string[64];
            GetPlayerName(gVehicleOwner[vehicleid], string, MAX_PLAYER_NAME);
            format(string, sizeof(string), "This car is owned by %s", string);
            SendClientMessage(playerid, -1, string);
            ClearAnimations(playerid);
        }

    return 1;
}
and for destroy

Change all DestroyVehicle to DestroyVehicleEx

pawn Код:
DestroyVehicleEx(vehicleid)
{
    if(!(0 < vehicleid < sizeof(gVehicleOwner))) return 0;
    gVehicleOwner[vehicleid] = INVALID_PLAYER_ID;
    return DestroyVehicle(vehicleid);
}
I want to destroy vehicle when player disconnects. How do I do that?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)