SA-MP Forums Archive
Spawn vehicle per player - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Spawn vehicle per player (/showthread.php?tid=662888)



Spawn vehicle per player - NoteND - 14.01.2019

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?


Re: Spawn vehicle per player - RogueDrifter - 14.01.2019

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;
}



Re: Spawn vehicle per player - rockys - 14.01.2019

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
    
}