SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 14/01/2019, 04:47 PM   #1
NoteND
Big Clucker
 
Join Date: May 2016
Posts: 91
Reputation: 0
Default Spawn vehicle per player

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?
NoteND is offline   Reply With Quote
Old 14/01/2019, 08:44 PM   #2
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,229
Reputation: 376
Default Re: Spawn vehicle per player

pawn Code:
new PlayerVehicle[MAX_PLAYERS];

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

public OnPlayerDisconnect(playerid)
{
    DestroyVehicle(PlayerVehicle[playerid]);
    PlayerVehicle[playerid] = 0;
    return 1;
}
__________________
Be creative.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
Old 14/01/2019, 08:58 PM   #3
rockys
Little Clucker
 
Join Date: Oct 2018
Location: Romania
Posts: 25
Reputation: 0
Default Re: Spawn vehicle per player

PHP Code:
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
    
}

rockys is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Player vehicle spawn AlexBlack Scripting Help 2 26/06/2015 12:41 AM
Spawn a vehicle close to my player Dugzor Scripting Help 4 11/09/2013 02:10 PM
Spawn player in a vehicle Lz Scripting Help 5 28/11/2012 10:28 PM
Player spawn in Vehicle DexXxo Scripting Help 2 22/09/2012 12:25 PM
Player in vehicle after spawn Srdjan Help Archive 2 21/05/2011 10:31 PM


All times are GMT. The time now is 11:14 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.