Quote:
Originally Posted by Sew_Sumi
That's more when you've been working on something, know it's broken, and yet won't share the code simply asking if things could happen.
Your problem though, I don't think is with the spawning of the vehicle, or it's linked interior... It's likely more to do with another portion of code that works with the vehicles.
Does the vehicle actually destroy, and have you tried to teleport to it and see which interior/Virtual World it's in?
|
The script is completely bare. Apart from this dealership system and supporting system, it's a blank script.
The vehicle is created in the function the player calls when they use the dealership (posted below).
PHP Code:
stock LoadPlayerDealership(playerid, subtype) {
GetPlayerPos(playerid, PlayerInfo[playerid][pLastPos][0], PlayerInfo[playerid][pLastPos][1], PlayerInfo[playerid][pLastPos][2]);
PlayerInfo[playerid][pLastWorld] = GetPlayerVirtualWorld(playerid);
PlayerInfo[playerid][pLastInterior] = GetPlayerInterior(playerid);
SetPlayerCameraPos(playerid, -1952.6205,266.6597,41.5596);
SetPlayerCameraLookAt(playerid, -1947.6516,259.0659,40.7750);
SetPlayerPos(playerid, -1952.6205,266.6597,-10.5596);
TogglePlayerControllable(playerid, 0);
new model, price, category, desc[128], str[128];
mysql_format(ourConnection, str, sizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i ORDER BY ds_id ASC LIMIT 1", subtype);
new Cache:result = mysql_query(ourConnection, str);
PDealerInfo[playerid][ds_current_shift] = 0;
PDealerInfo[playerid][ds_current_type] = subtype;
PDealerInfo[playerid][ds_is_purchasing] = true;
cache_get_value_name_int(0, "ds_vehicle_model", model);
cache_get_value_name_int(0, "ds_vehicle_category", category);
cache_get_value_name_int(0, "ds_vehicle_price", price);
cache_get_value_name(0, "ds_vehicle_desc", desc);
printf("[DEBUG] [Model: %d] [Category: %d] [Price: %d] [Desc: %s]", model, category, price, desc);
PDealerInfo[playerid][ds_vehicle] = CreateVehicle(model, -1947.6516, 259.0659, 40.7750, 0.3520, 1, 1, -1, 0);
PDealerInfo[playerid][ds_color_1] = 1;
PDealerInfo[playerid][ds_color_2] = 1;
PDealerInfo[playerid][ds_alarm] = ALARM_BASIC;
PDealerInfo[playerid][ds_stereo] = STEREO_BASIC;
TextDrawShowForPlayer(playerid, dealership_bg);
TextDrawShowForPlayer(playerid, dealership_purchase);
TextDrawShowForPlayer(playerid, dealership_modify);
TextDrawShowForPlayer(playerid, dealership_cancel);
format(str, sizeof(str), "~b~%s", ReturnVehicleName(PDealerInfo[playerid][ds_vehicle]));
PlayerTextDrawSetString(playerid, dealership_title[playerid], str);
PlayerTextDrawShow(playerid, dealership_title[playerid]);
PlayerTextDrawSetString(playerid, dealership_info[playerid], desc);
PlayerTextDrawShow(playerid, dealership_info[playerid]);
format(str, sizeof(str), "~r~Price: ~w~$%s", MoneyFormat(price));
PlayerTextDrawSetString(playerid, dealership_price[playerid], str);
PlayerTextDrawShow(playerid, dealership_price[playerid]);
PlayerTextDrawSetPreviewModel(playerid, dealership_preview[playerid], model);
PlayerTextDrawShow(playerid, dealership_preview[playerid]);
TextDrawShowForPlayer(playerid, dealership_left);
TextDrawShowForPlayer(playerid, dealership_right);
SelectTextDraw(playerid, COLOR_GRAD1);
cache_delete(result);
return 1;
}
In the above code, I've removed the functions switching the player's and the vehicle's virtual worlds. This version works with no issues.
There is no issue with the MySQL information loading (which can been seen when the function runs, and the 'printf' fires).
The destroying of the vehicle works, as I've tested it without the virtual world portion and the vehicle isn't still there when I re-enter the UI. (Function is below aswell)
PHP Code:
stock HideDealership(playerid) {
if(PDealerInfo[playerid][ds_is_purchasing] == false)
return 0;
TogglePlayerSpectating(playerid, 0);
SetPlayerPos(playerid, PlayerInfo[playerid][pLastPos][0], PlayerInfo[playerid][pLastPos][1], PlayerInfo[playerid][pLastPos][2]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pLastWorld]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pLastInterior]);
SetCameraBehindPlayer(playerid);
TogglePlayerControllable(playerid, 1);
PDealerInfo[playerid][ds_is_purchasing] = false;
//DestroyVehicle(PDealerInfo[playerid][ds_vehicle]);
TextDrawHideForPlayer(playerid, dealership_bg);
TextDrawHideForPlayer(playerid, dealership_purchase);
TextDrawHideForPlayer(playerid, dealership_modify);
TextDrawHideForPlayer(playerid, dealership_cancel);
PlayerTextDrawHide(playerid, dealership_title[playerid]);
PlayerTextDrawHide(playerid, dealership_info[playerid]);
PlayerTextDrawHide(playerid, dealership_price[playerid]);
PlayerTextDrawHide(playerid, dealership_preview[playerid]);
TextDrawHideForPlayer(playerid, dealership_left);
TextDrawHideForPlayer(playerid, dealership_right);
CancelSelectTextDraw(playerid);
return 1;
}
When I goto the vehicle while the default VW of 0 is used, it's still there (provided I remove the DestroyVehicle()
.
When I manually set the VW of both the vehicle and myself, it disappears. When I goto the vehicle (still, removing the DestroyVehicle(); portion) it's still not visible.
I should also add that when I exit the UI and use a command to reset my VW to 0 (If I were to set it myself) I'm still unable to see vehicles.
The script worked within another gamemode without any issue, however there was a problem with the MySQL, so I decided to make this dealership system within it's own.
Edit: Decided I mine as well post the command that shifts the vehicle's aswell, as it also creates a vehicle and experiences the same issue.
PHP Code:
stock ShiftDealershipVehicle(playerid, shift) {
if(PDealerInfo[playerid][ds_is_purchasing] == false)
return 0;
if(PDealerInfo[playerid][ds_current_shift] == 0 && shift == DEALERSHIP_LEFT)
return 0;
new str[128], type = PDealerInfo[playerid][ds_current_type];
switch(shift) {
case DEALERSHIP_RIGHT: {
mysql_format(ourConnection, str, sizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i AND ds_id > %i ORDER BY ds_id ASC LIMIT 1", type, PDealerInfo[playerid][ds_current_shift]);
}
case DEALERSHIP_LEFT: {
mysql_format(ourConnection, str, sizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i AND ds_id < %i ORDER BY ds_id DESC LIMIT 1", type, PDealerInfo[playerid][ds_current_shift]);
}
}
new Cache:result = mysql_query(ourConnection, str);
new rows; cache_get_row_count(rows);
if(rows == 0)
return 0;
new model, price, category, desc[128];
cache_get_value_name_int(0, "ds_id", PDealerInfo[playerid][ds_current_shift]);
cache_get_value_name_int(0, "ds_vehicle_model", model);
cache_get_value_name_int(0, "ds_vehicle_category", category);
cache_get_value_name_int(0, "ds_vehicle_price", price);
cache_get_value_name(0, "ds_vehicle_desc", desc);
new color1 = PDealerInfo[playerid][ds_color_1],
color2 = PDealerInfo[playerid][ds_color_2];
DestroyVehicle(PDealerInfo[playerid][ds_vehicle]);
PDealerInfo[playerid][ds_vehicle] = CreateVehicle(model, -1947.6516, 259.0659, 40.7750, 0.3520, color1, color2, -1, 0);
SetVehicleVirtualWorld(PDealerInfo[playerid][ds_vehicle], GetPlayerVirtualWorld(playerid));
PutPlayerInVehicle(playerid, PDealerInfo[playerid][ds_vehicle], 0);
PlayerTextDrawHide(playerid, dealership_title[playerid]);
format(str, sizeof(str), "~b~%s", ReturnVehicleName(PDealerInfo[playerid][ds_vehicle]));
PlayerTextDrawSetString(playerid, dealership_title[playerid], str);
PlayerTextDrawShow(playerid, dealership_title[playerid]);
PlayerTextDrawHide(playerid, dealership_info[playerid]);
format(str, sizeof(str), "%s", desc);
PlayerTextDrawSetString(playerid, dealership_info[playerid], str);
PlayerTextDrawShow(playerid, dealership_info[playerid]);
PlayerTextDrawHide(playerid, dealership_price[playerid]);
format(str, sizeof(str), "~r~Price: ~w~$%s", MoneyFormat(price));
PlayerTextDrawSetString(playerid, dealership_price[playerid], str);
PlayerTextDrawShow(playerid, dealership_price[playerid]);
PlayerTextDrawHide(playerid, dealership_preview[playerid]);
PlayerTextDrawSetPreviewModel(playerid, dealership_preview[playerid], model);
PlayerTextDrawShow(playerid, dealership_preview[playerid]);
cache_delete(result);
return 1;
}