HELP: Spawning Cars In Virtual World
#1

Hello,
I have a problem linking my spawning system to any virtual world. I have implemented a system where a player may use his house's dynamic exit as his virtual world and must use a house menu to exit to the default world. Now they are all different virtual worlds and there are many houses, and I do not have time to script a custom spawning system for each house, PAWNO just sort of made the virtual world thing for me by accident and I liked the idea of players having a private world. My problem is that I do not know how to set it up so that when a player spawns a vehicle, it just detects HIS virtual world and spawns the vehicle for him there. Is that possible for a player to just do the spawn command in any virtual world and get his vehicle? I use PPC360's Commands from his trucking gamemode btw so it looks like this:
Quote:

// Lets the player choose a car to spawn (in a split list which shows only 10 cars at a time)
COMMAND:car(playerid, params[])
{

// Check if the player has logged in
if (APlayerData[playerid][LoggedIn] == true)
{
// Check if the player's admin-level is at least 1
if (APlayerData[playerid][PlayerLevel] >= 1)
{
// Make sure the player isn't inside a vehicle
if (GetPlayerVehicleID(playerid) == 0)
CarList_Create(playerid); // Create a list of cars (only the first 10 cars) and show the dialog so the player can choose a car
}
else
return 0;
}
else
return 0;

// Let the server know that this was a valid command
return 1;

Thanks!
Reply
#2

Yes.

https://sampwiki.blast.hk/wiki/SetVehicleVirtualWorld
https://sampwiki.blast.hk/wiki/GetPlayerVirtualWorld

pawn Код:
SetVehicleVirtualWorld(vehicleid, GetPlayerVirtualWorld(playerid));
Since you get the vehicleid from OnDialogResponse, set the vehicle virtual world in that callback. The ID of the dialog is in the CarList_Create(playerid) function.
Reply
#3

Thank you! But here exactly do I put it in the script?
Reply
#4

Post your OnDialogResponse and CarList_Create.
Reply
#5

Here would be the OnDialogResponse from the Trucking Gamemode:
Quote:

// This callback gets called when a player interacts with a dialog
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// Select the proper dialog to process
switch (dialogid)
{
case DialogRegister: Dialog_Register(playerid, response, inputtext); // The "Register"-dialog
case DialogLogin: Dialog_Login(playerid, response, inputtext); // The "Login"-dialog

case DialogStatsOtherPlayer: Dialog_StatsOtherPlayer(playerid, response, listitem);
case DialogStatsHouse: Dialog_StatsHouse(playerid, response, listitem);
case DialogStatsGoHouse: Dialog_StatsGoHouse(playerid, response, listitem);
case DialogStatsGoBusiness: Dialog_StatsGoBusiness(playerid, response, listitem);

case DialogRescue: Dialog_Rescue(playerid, response, listitem); // The rescue-dialog

case DialogBuyLicenses: Dialog_BuyLicenses(playerid, response, listitem); // The license-dialog (allows the player to buy trucker/busdriver licenses)

case DialogRules: Dialog_Rules(playerid, response);

case DialogTruckerJobMethod: Dialog_TruckerSelectJobMethod(playerid, response, listitem); // The work-dialog for truckers (shows the loads he can carry and lets the player choose the load)
case DialogTruckerSelectLoad: Dialog_TruckerSelectLoad(playerid, response, listitem); // The load-selection dialog for truckers (shows the startlocations for the selected load and let the player choose his startlocation)
case DialogTruckerStartLoc: Dialog_TruckerSelectStartLoc(playerid, response, listitem); // The start-location dialog for truckers (shows the endlocations for the selected load and let the player choose his endlocation)
case DialogTruckerEndLoc: Dialog_TruckerSelectEndLoc(playerid, response, listitem); // The end-location dialog for truckers (processes the selected endlocation and starts the job)

case DialogBusJobMethod: Dialog_BusSelectJobMethod(playerid, response, listitem); // The work-dialog for busdrivers (process the options to choose own busroute or auto-assigned busroute)
case DialogBusSelectRoute: Dialog_BusSelectRoute(playerid, response, listitem); // Choose the busroute and start the job

case DialogCourierSelectQuant: Dialog_CourierSelectQuant(playerid, response, listitem);

case DialogBike: Dialog_Bike(playerid, response, listitem); // The bike-dialog
case DialogCar: Dialog_Car(playerid, response, listitem); // The car-dialog (which uses a split dialog structure)
case DialogPlane: Dialog_Plane(playerid, response, listitem); // The plane-dialog (which uses a split dialog structure)
case DialogTrailer: Dialog_Trailer(playerid, response, listitem); // The trailer-dialog (which uses a split dialog structure)
case DialogBoat: Dialog_Boat(playerid, response, listitem); // The boat-dialog
case DialogNeon: Dialog_Neon(playerid, response, listitem); // The neon-dialog

case DialogRentCarClass: Dialog_RentProcessClass(playerid, response, listitem); // The player chose a vehicleclass from where he can rent a vehicle
case DialogRentCar: Dialog_RentCar(playerid, response, listitem); // The player chose a vehicle from the list of vehicles from the vehicleclass he chose before

case DialogPlayerCommands: Dialog_PlayerCommands(playerid, response, listitem); // Displays all commands in a split-dialog structure
case DialogPrimaryCarColor: Dialog_PrimaryCarColor(playerid, response, listitem);
case DialogSedundaryCarColor: Dialog_SedundaryCarColor(playerid, response, listitem);

case DialogWeather: Dialog_Weather(playerid, response, listitem); // The weather dialog
case DialogCarOption: Dialog_CarOption(playerid, response, listitem); // The caroption dialog

case DialogSelectConvoy: Dialog_SelectConvoy(playerid, response, listitem);

case DialogHouseMenu: Dialog_HouseMenu(playerid, response, listitem); // Process the main housemenu
case DialogUpgradeHouse: Dialog_UpgradeHouse(playerid, response, listitem); // Process the house-upgrade menu
case DialogGoHome: Dialog_GoHome(playerid, response, listitem); // Port to one of your houses
case DialogHouseNameChange: Dialog_ChangeHouseName(playerid, response, inputtext); // Change the name of your house
case DialogSellHouse: Dialog_SellHouse(playerid, response); // Sell the house
case DialogBuyCarClass: Dialog_BuyCarClass(playerid, response, listitem); // The player chose a vehicleclass from where he can buy a vehicle
case DialogBuyCar: Dialog_BuyCar(playerid, response, listitem); // The player chose a vehicle from the list of vehicles from the vehicleclass he chose before
case DialogSellCar: Dialog_SellCar(playerid, response, listitem);
case DialogBuyInsurance: Dialog_BuyInsurance(playerid, response);
case DialogGetCarSelectHouse: Dialog_GetCarSelectHouse(playerid, response, listitem);
case DialogGetCarSelectCar: Dialog_GetCarSelectCar(playerid, response, listitem);
case DialogUnclampVehicles: Dialog_UnclampVehicles(playerid, response);

case DialogCreateBusSelType: Dialog_CreateBusSelType(playerid, response, listitem);
case DialogBusinessMenu: Dialog_BusinessMenu(playerid, response, listitem);
case DialogGoBusiness: Dialog_GoBusiness(playerid, response, listitem);
case DialogBusinessNameChange: Dialog_ChangeBusinessName(playerid, response, inputtext); // Change the name of your business
case DialogSellBusiness: Dialog_SellBusiness(playerid, response); // Sell the business

case DialogBankPasswordRegister: Dialog_BankPasswordRegister(playerid, response, inputtext);
case DialogBankPasswordLogin: Dialog_BankPasswordLogin(playerid, response, inputtext);
case DialogBankOptions: Dialog_BankOptions(playerid, response, listitem);
case DialogBankDeposit: Dialog_BankDeposit(playerid, response, inputtext);
case DialogBankWithdraw: Dialog_BankWithdraw(playerid, response, inputtext);
case DialogBankTransferMoney: Dialog_BankTransferMoney(playerid, response, inputtext);
case DialogBankTransferName: Dialog_BankTransferName(playerid, response, inputtext);
case DialogBankCancel: Dialog_BankCancel(playerid, response);

case DialogHelpItemChosen: Dialog_HelpItemChosen(playerid, response, listitem);
case DialogHelpItem: Dialog_HelpItem(playerid, response);

case DialogOldPassword: Dialog_OldPassword(playerid, response, inputtext);
case DialogNewPassword: Dialog_NewPassword(playerid, response, inputtext);
case DialogConfirmPassword: Dialog_ConfirmPassword(playerid, response);
}

return 1;
}

And Here is the CarListCreate:
Quote:

// This function creates a list of cars, starting from the FirstCar and automatically shows the dialog
CarList_Create(playerid)
{
// Setup local variables
new Counter, CarList[500], DialogTitle[128];

// Only add 10 cars to the list, starting from the FirstCar
for (new i = APlayerData[playerid][DialogCarFirstCar]; i < sizeof(ACars); i++)
{
// Increase a counter (which holds the number of cars that have been added to the list
Counter++;

// Check if the maximum hasn't been reached yet
if (Counter <= 10)
{
// Add the carname to the list
if (strlen(CarList) == 0) // If this is the start of the list (no cars have been added yet)
format(CarList, 500, "%s", ACars[i][CarName]); // Add the name of the car at the start of the carlist
else
format(CarList, 500, "%s%s%s", CarList, "\n", ACars[i][CarName]); // Add the name of the next car to the list on the next line
}
else // 10 cars have been added to the list (now Counter = 11)
{
// Add an empty line and "Next..." to the list to let the player know there are more cars to choose from
format(CarList, 500, "%s%s%s", CarList, "\n \n", TXT_DialogEntryNext);
// Also stop the For-loop
break;
}
}

// Construct the title for the dialog (to include a page number)
format(DialogTitle, 128, TXT_DialogCarTitle, (APlayerData[playerid][DialogCarFirstCar] / 10) + 1);
// Ask which car the player wants to have by showing the dialog
ShowPlayerDialog(playerid, DialogCar, DIALOG_STYLE_LIST, DialogTitle, CarList, TXT_DialogButtonSpawn, TXT_DialogButtonCancel);

return 1;
}

Reply
#6

Since the responses show functions instead of the vehicle spawn, my guess would be take a look at Dialog_CarOption(playerid, response, listitem) and look for CreateVehicle. If it's not assigned to a variable, assign it to one, ex:

pawn Код:
new vehicleid = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
Then you can set the vehicle's virtual world with the variable.

Also in the future place your code in [PAWN] tags, makes things easier to read.
Reply
#7

Look I'm really sorry to be bothering you but I am a very basic Pawn scripter. Is it possible to just insert a line anywhere in the PPC Trucking gamemode? Sorry
Reply
#8

Assuming CreateVehicle is inside Dialog_CarOption you can just place SetVehicleVirtualWorld directly under CreateVehicle's variable. If you still need help post your Dialog_CarOption(playerid, response, listitem).

I would read the SA-MP wiki and the PAWN Language Guide to gain some basic knowledge.
Reply
#9

I am a beginner but I know enough, the Dialog_CarOption is a lead towards the Caroption menu for the engines and lights and such. The spawn COMMAND which is /car would allow a player to just spawn inside his car in his current position. So I want to add the vehicle to the interior WHEN the player enters the command in THAT interior.
Reply
#10

Alright so I downloaded the gamemode and it turns out the vehicle spawn was located under Dialog_Car. I assumed that Dialog_Car would open up another dialog whose response would lead to Dialog_CarOption, oh well. This is why it's important to know your code so I can pinpoint where you need to place the solution in the first post.

pawn Код:
Dialog_Car(playerid, response, listitem)
{
    // Just close the dialog if the player clicked "Cancel"
    if(!response)
    {
        // Reset the FirstCar (so the list won't start at an unexpected location in the list, but back at the start of the list)
        APlayerData[playerid][DialogCarFirstCar] = 0;
        return 1; // Exit the function
    }

    // Process the selected listitem
    switch (listitem)
    {
        case 10: // Player chooses the empty line between the carlist and "Next...", so refresh the current list
        {
            // Refresh the current list of cars and let the player choose one (show dialog)
            CarList_Create(playerid);
            // Exit the function
            return 1;
        }
        case 11: // Player chooses "Next..."
        {
            // Add 10 to the FirstCar, so the list will start further down the array (will show the next 10 cars)
            APlayerData[playerid][DialogCarFirstCar] = APlayerData[playerid][DialogCarFirstCar] + 10;
            // Create a new list of cars and show the dialog
            CarList_Create(playerid);
        }
        default: // Player chooses a car
        {
            // Setup local variables
            new Float:x, Float:y, Float:z, Float:rot, CarIndex, msg[128], vID, pName[24];
            new engine,lights,alarm,doors,bonnet,boot,objective;

            // FirstCar is the index of the first car in the list, so select the proper index when a car is chosen by the player
            CarIndex = APlayerData[playerid][DialogCarFirstCar] + listitem;

            // Get the player's position and name
            GetPlayerPos(playerid, x, y, z);
            GetPlayerFacingAngle(playerid, rot);
            GetPlayerName(playerid, pName, 24);

            // Spawn the vehicle based on the selection in the list with a random color
            // Also set max-fuel and save the model for the vehicle
            vID = Vehicle_Create(ACars[CarIndex][CarModel], x, y, z, rot, random(126), random(126), 600);
            // Set vehicle virtual world to player's
            SetVehicleVirtualWorld(vID, GetPlayerVirtualWorld(playerid));
            // Put the player in the vehicle
            PutPlayerInVehicle(playerid, vID, 0);
            // Turn on the engine and lights
            GetVehicleParamsEx(vID, engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(vID, 1, 1, alarm, doors, bonnet, boot, objective);
            // Store the player's current location and interior-id, otherwise anti-airbreak hack code could kick you
            GetPlayerPos(playerid, APlayerData[playerid][PreviousX], APlayerData[playerid][PreviousY], APlayerData[playerid][PreviousZ]);
            APlayerData[playerid][PreviousInt] = GetPlayerInterior(playerid);
            // Inform all players about it
            format(msg, 120, TXT_PlayerSpawnedVehicle, pName, vID, ACars[CarIndex][CarModel], x, y, z);
            SendClientMessageToAll(0xFFFFFFFF, msg);
            // Also, after spawning a vehicle, reset FirstCar (so next time, the list starts from the start)
            APlayerData[playerid][DialogCarFirstCar] = 0;
        }
    }

    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)