28.10.2018, 19:00
You know the script for buying private vehicles. For example: In the living room there is an Elegy car and I get in this car and show Dialog. Buy or cancel.
// define dialogs first
public OnPlayerStateChange(playerid, newstate, oldstate){
if(newstate == PLAYER_STATE_DRIVER){ // You need to add another check here so this will be called only in showrooms
new string[128], price, carid, modelid;
carid = GetPlayerVehicleID(playerid); // Get the vehicle id for future use
SetVehicleParamsEx(carid, 0, 1, 0, 0, 0, 0, 0); // ENGINE OFF or player will run away with the car lol
modelid = GetVehicleModel(carid); // Model id, Elegy is 562
switch(modelid){
case 562:
{
price = 12500;
format(string, sizeof string, "Elegy1n Price: $%d", price);
ShowPlayerDialog(playerid, DIALOG_CAR_BUY, DIALOG_STYLE_MSGBOX, "Buy a car", string, "Buy", "Cancel");
}
}
}
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){
switch(dialogid){
case DIALOG_CAR_BUY:
{
if(response){
if(GetPlayerMoney(playerid) < 12500)return ShowPlayerDialog(playerid, DIALOG_NO_MONEY, DIALOG_STYLE_MSGBOX, "Buy a car", "You need 12500$ to buy a Elegy!", "Ok", "");
// Take money from player, save player data adding car property etc
return 1;
}
}
}
return 1;
}