Spawn vehicle per player
#3

PHP код:
new PlayerCars[MAX_PLAYERS]; // here is car id
new PlayerCarsOwner[MAX_VEHICLES][20]; // here is car owner
new PlayerCarsDB[MAX_VEHICLES]; // here is car owner id
go to public OnPlayerLogin(playerid) or public OnPlayerSpawn(playerid)
if(
PlayerCars[playerid] == 0) {
new 
Float:X,Float:Y,Float:Z,Float:angle 0.0,color1,color2,name[20];
color1 random(256); //car color 1
color2 random(256);// car color 2
model 411//infernus
GetPlayerPos(playeridX,Y,Z); //your pos
new carid PlayerCars[playerid] = CreateVehicle(modelX,Y,Zangle,  color1,color2,-1); //create vehicle at pos
GetPlayerName(playeridnamesizeof(name)); //get your name
format(PlayerCarsOwner[carid],20,"%s",name); //format car owner
PlayerCarsDB[carid] = playerid//car owner id
}
public 
OnPlayerStateChange(playeridnewstateoldstate// here you enter in vehicle
{
    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER) { // if you driver
        
new carid GetPlayerVehicleID(playerid); //getvehicleid
        
if(PlayerCarsDB[carid] != 0) { // if vehicle is owned
            
new string[128];
            
format(string,sizeof(string),"This vehicle is owned by %s",PlayerCarsOwner[carid]); //format message
            
SendClientMessage(playerid,-1,string); // send message
            
if(PlayerCarsDB[carid] != playeridRemovePlayerFromVehicle(playerid); // if owner is not you, you out vehicle
        
}
    }
return 
1;
}
public 
OnPlayerDisconnect(playeridreason) { // here out the server
    
if(PlayerCars[playerid] != 0) { // if you have vehicle
        
new carid PlayerCars[playerid]; //get vehicle id
        
DestroyVehicle(carid); //destroy
        
PlayersCarsOwner[carid] = (EOS); //empty vehicle name
        
PlayerCarsDB[carid] = 0//reset vehicel owner id
        
PlayerCars[playerid] = 0// reset your car id
    
}

Reply


Messages In This Thread
Spawn vehicle per player - by NoteND - 14.01.2019, 15:47
Re: Spawn vehicle per player - by RogueDrifter - 14.01.2019, 19:44
Re: Spawn vehicle per player - by rockys - 14.01.2019, 19:58

Forum Jump:


Users browsing this thread: 1 Guest(s)