Spawn vehicle per player
#1

Hey!

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?
Reply
#2

pawn Код:
new PlayerVehicle[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    PlayerVehicle[playerid] = CreateVehicle//...etc
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    DestroyVehicle(PlayerVehicle[playerid]);
    PlayerVehicle[playerid] = 0;
    return 1;
}
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)