Disappearing vehicles
#1

So I'm having some some trouble with SetPlayerVirtualWorld and SetVehicleVirtualWorld.

I'm making a dealership system that sets the player's camera and creates the current vehicle they're looking at.

Everything works fine, up until I try to set the player and vehicle's virtual world, to allow multiple people to purchase vehicles at the same time.

I made two test commands, one that allows me to set the player's vw and one to set the vehicle's.

When I switch the vehicle through the virtual worlds it works fine. When I switch the vehicle to virtual world 1 it disappears, when I switch it back to 0 it reappears.

The problem comes when I try to set my own virtual world. For some reason the vehicle just disappears.

I could set both my and the vehicles virtual world to 2 and it disappears. I can reset it back to 0 and still nothing.

Not sure what code could be included to make this any easier, considering it's a simple:

PHP Code:
SetPlayerVirtualWorld(playeridplayerid 1000);
new 
veh CreateVehicle(...);
SetVehicleVirtualWorld(vehGetPlayerVirtualWorld(playerid)); 
Reply
#2

Vehicles can only be seen by players in the same interior

https://sampwiki.blast.hk/wiki/LinkVehicleToInterior
Reply
#3

Quote:
Originally Posted by Livity
View Post
Vehicles can only be seen by players in the same interior

https://sampwiki.blast.hk/wiki/LinkVehicleToInterior
Both are 0 as by default of SA-MP.

Like I said in the post. If I leave out the part where I'm setting the player and vehicle's virtual world's; the vehicle is visible. As in I can see the vehicle, sitting there on the ground where I've spawned it at.
Reply
#4

Quote:
Originally Posted by KtotheYle
View Post
Not sure what code could be included to make this any easier, considering it's a simple:
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?
Reply
#5

After setting the virtual world of the player and vehicle, try to use PutPlayerInVehicle and then reposition the player (SetPlayerPos) to the coordinates he should be standing.

That's how you show vehicles in class selection as well.
Just setting them in a virtual world and interior 0 won't show them.
You need to put the player inside, then outside the vehicle again to make it appear.
Reply
#6

Quote:
Originally Posted by Sew_Sumi
View Post
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(playeridsubtype) {
    
GetPlayerPos(playeridPlayerInfo[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(playerid0);
    new 
modelpricecategorydesc[128], str[128];
    
mysql_format(ourConnectionstrsizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i ORDER BY ds_id ASC LIMIT 1"subtype);
    new 
Cache:result mysql_query(ourConnectionstr);
    
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]"modelcategorypricedesc);
    
PDealerInfo[playerid][ds_vehicle] = CreateVehicle(model, -1947.6516259.065940.77500.352011, -10);
    
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(playeriddealership_bg);
    
TextDrawShowForPlayer(playeriddealership_purchase);
    
TextDrawShowForPlayer(playeriddealership_modify);
    
TextDrawShowForPlayer(playeriddealership_cancel);
    
format(strsizeof(str), "~b~%s"ReturnVehicleName(PDealerInfo[playerid][ds_vehicle]));
    
PlayerTextDrawSetString(playeriddealership_title[playerid], str);
    
PlayerTextDrawShow(playeriddealership_title[playerid]);
    
PlayerTextDrawSetString(playeriddealership_info[playerid], desc);
    
PlayerTextDrawShow(playeriddealership_info[playerid]);
    
format(strsizeof(str), "~r~Price: ~w~$%s"MoneyFormat(price));
    
PlayerTextDrawSetString(playeriddealership_price[playerid], str);
    
PlayerTextDrawShow(playeriddealership_price[playerid]);
    
PlayerTextDrawSetPreviewModel(playeriddealership_preview[playerid], model);
    
PlayerTextDrawShow(playeriddealership_preview[playerid]);
    
TextDrawShowForPlayer(playeriddealership_left);
    
TextDrawShowForPlayer(playeriddealership_right);
    
SelectTextDraw(playeridCOLOR_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(playerid0);
    
SetPlayerPos(playeridPlayerInfo[playerid][pLastPos][0], PlayerInfo[playerid][pLastPos][1], PlayerInfo[playerid][pLastPos][2]);
    
SetPlayerVirtualWorld(playeridPlayerInfo[playerid][pLastWorld]);
    
SetPlayerInterior(playeridPlayerInfo[playerid][pLastInterior]);
    
SetCameraBehindPlayer(playerid);
    
TogglePlayerControllable(playerid1);
    
PDealerInfo[playerid][ds_is_purchasing] = false;
    
//DestroyVehicle(PDealerInfo[playerid][ds_vehicle]);
    
TextDrawHideForPlayer(playeriddealership_bg);
    
TextDrawHideForPlayer(playeriddealership_purchase);
    
TextDrawHideForPlayer(playeriddealership_modify);
    
TextDrawHideForPlayer(playeriddealership_cancel);
    
PlayerTextDrawHide(playeriddealership_title[playerid]);
    
PlayerTextDrawHide(playeriddealership_info[playerid]);
    
PlayerTextDrawHide(playeriddealership_price[playerid]);
    
PlayerTextDrawHide(playeriddealership_preview[playerid]);
    
TextDrawHideForPlayer(playeriddealership_left);
    
TextDrawHideForPlayer(playeriddealership_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(playeridshift) {
    if(
PDealerInfo[playerid][ds_is_purchasing] == false)
        return 
0;
    if(
PDealerInfo[playerid][ds_current_shift] == && shift == DEALERSHIP_LEFT)
        return 
0;
    new 
str[128], type PDealerInfo[playerid][ds_current_type];
    switch(
shift) {
        case 
DEALERSHIP_RIGHT: {
            
mysql_format(ourConnectionstrsizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i AND ds_id > %i ORDER BY ds_id ASC LIMIT 1"typePDealerInfo[playerid][ds_current_shift]);
        }
        case 
DEALERSHIP_LEFT: {
            
mysql_format(ourConnectionstrsizeof(str), "SELECT * FROM dealership_vehicles WHERE ds_vehicle_category = %i AND ds_id < %i ORDER BY ds_id DESC LIMIT 1"typePDealerInfo[playerid][ds_current_shift]);
        }
    }
    new 
Cache:result mysql_query(ourConnectionstr);
    new 
rowscache_get_row_count(rows);
    if(
rows == 0)
        return 
0;
    new 
modelpricecategorydesc[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.6516259.065940.77500.3520color1color2, -10);
    
SetVehicleVirtualWorld(PDealerInfo[playerid][ds_vehicle], GetPlayerVirtualWorld(playerid));
    
PutPlayerInVehicle(playeridPDealerInfo[playerid][ds_vehicle], 0);
    
PlayerTextDrawHide(playeriddealership_title[playerid]);
    
format(strsizeof(str), "~b~%s"ReturnVehicleName(PDealerInfo[playerid][ds_vehicle]));
    
PlayerTextDrawSetString(playeriddealership_title[playerid], str);
    
PlayerTextDrawShow(playeriddealership_title[playerid]);
    
PlayerTextDrawHide(playeriddealership_info[playerid]);
    
format(strsizeof(str), "%s"desc);
    
PlayerTextDrawSetString(playeriddealership_info[playerid], str);
    
PlayerTextDrawShow(playeriddealership_info[playerid]);
    
PlayerTextDrawHide(playeriddealership_price[playerid]);
    
format(strsizeof(str), "~r~Price: ~w~$%s"MoneyFormat(price));
    
PlayerTextDrawSetString(playeriddealership_price[playerid], str);
    
PlayerTextDrawShow(playeriddealership_price[playerid]);
    
PlayerTextDrawHide(playeriddealership_preview[playerid]);
    
PlayerTextDrawSetPreviewModel(playeriddealership_preview[playerid], model);
    
PlayerTextDrawShow(playeriddealership_preview[playerid]);
    
cache_delete(result);
    return 
1;

Reply
#7

Nope. Even tried putting it in the function that I use to shift the vehicle up or down and it still didn't work (to make sure the objects were loaded, as the function destroys and re-creates the vehicle).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)