I wanna spawn vehicle per player and make it player vehicle, now making it player vehicle isnt a big deal, but I cant seem to get vehicles to spawn equal to players in the server. How do I do that?
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(playerid, X,Y,Z); //your pos
new carid = PlayerCars[playerid] = CreateVehicle(model, X,Y,Z, angle, color1,color2,-1); //create vehicle at pos
GetPlayerName(playerid, name, sizeof(name)); //get your name
format(PlayerCarsOwner[carid],20,"%s",name); //format car owner
PlayerCarsDB[carid] = playerid; //car owner id
}
public OnPlayerStateChange(playerid, newstate, oldstate) // 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] != playerid) RemovePlayerFromVehicle(playerid); // if owner is not you, you out vehicle
}
}
return 1;
}
public OnPlayerDisconnect(playerid, reason) { // 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
}
}