Need help loading buyable vehicles
#1

Hi,

So I'm trying to load buyable vehicles from a .txt file to include the data into a dialog. So for example, the text file should look like this:

//name, price, vehicleid
Quote:

Sultan, 45000, 560

I then need to include that into a dialog, so when a player clicks 'next', it would keep moving down the list in the .txt file. The dialog should then display the vehicle's name, price and the ID that it should create the vehicle in the dealership, so the player can look at it.

Thanks for any help given! If you need more details, just reply to the thread, but there's not really much I can give. I've ******'d the solution, and could not find any answers. I've also looked at other scripts, but they do it awkwardly and hardly understandable.

Any help given, I will leave rep as appreciation.
Reply
#2

Well it depends on how you read those .txt files. Are you using something like dini or Y_ini?

If you're using native file functions, my suggestion would be to count and store the number of lines read and on second and later entries skipping until those lines. Although, if someone changes the file between reads, this will cause a problem.

Anoter approach, would be to store the last car loaded. Then reading the file again, skipping the lines until you find one which wasn't loaded.

Anyhow, I would advise you to load all vehicles on server startup. If you want to be able to add cars while server is running, you should add a command which reloads them but ofcourse you would limit the amount of vehicles that can be bought.
Reply
#3

Thanks for the reply,

I found a way of doing it using mSelection, however, I have to set all prices manually with the modelid... :L
So it's going to add around 300 more lines of script in one function, which is going to be kind of annoying. I'm still using y_ini, to sort my files. Although mostly the script is SQL based. But there's no need for an SQL for returning buyable vehicles right?
Reply
#4

I did it before with mSelection and a dialog to show the price (when you click on the vehicle it shows the price) in very few lines.

if you edit the include you could add the price dynamically I guess, and even make it show up right on the thing.

This is pulled from my Roleplay Gamemode (Pure Roleplay) and is somewhere on this forum, I think it was my first thread.

Yours will look different, and I didnt include the "new" statements.
pawn Код:
CMD:dealership(pid)
{
    if(!IsPlayerInRangeOfPoint(pid, 5.0, -1965.7666, 294.0730, 35.4688)) return ErrorMessage(pid, "You are not at Wang Cars.");
    Dealer = LoadModelSelectionMenu("vehs.txt");
    ShowModelSelectionMenu(pid, Dealer, "Wang Cars");
    return 1;
}
pawn Код:
public OnPlayerModelSelection(playerid, response, listid, modelid)

if(listid == Dealer)
    {
        if(!response) return InfoMessage(pid, "You've cancelled your purchase.");
        pDModel[pid] = modelid;
        switch(modelid)
        {
            case 463:
            {
                pDPrice[pid] = 8000; //Freeway
            }
            case 580:
            {
                pDPrice[pid] = 30000; //Stafford
            }
            case 534:
            {
                pDPrice[pid] = 16000; //Remmington
            }
            case 521:
            {
                pDPrice[pid] = 20000; //FCR
            }
            case 478:
            {
                pDPrice[pid] = 13500; //Walton
            }
            case 467:
            {
                pDPrice[pid] = 10000; //Oceanic
            }
            case 451:
            {
                pDPrice[pid] = 1200000; //Turismo
            }
            case 445:
            {
                pDPrice[pid] = 12500; //Admiral
            }
            case 411:
            {
                pDPrice[pid] = 1200000; //Infernus
            }
            case 405:
            {
                pDPrice[pid] = 6000; //Sentinel
            }
            case 404:
            {
                pDPrice[pid] = 25000; //Perenniel
            }
            case 461:
            {
                pDPrice[pid] = 15000; //PCJ
            }
            case 585:
            {
                pDPrice[pid] = 12500; //Emperor
            }
            case 579:
            {
                pDPrice[pid] = 30000; //Huntley
            }
            case 567:
            {
                pDPrice[pid] = 15000; //Savannah
            }
            case 561:
            {
                pDPrice[pid] = 6000; //Stratum
            }
            case 562:
            {
                pDPrice[pid] = 150000; //Elegy
            }
            case 554:
            {
                pDPrice[pid] = 15000; //Yosemite
            }
            case 551:
            {
                pDPrice[pid] = 10000; //Merit
            }
            case 609:
            {
                pDPrice[pid] = 45000; //Boxville
            }
            case 482:
            {
                pDPrice[pid] = 15000; //Burrito
            }
            case 480:
            {
                pDPrice[pid] = 50000; //Comet
            }
            case 475:
            {
                pDPrice[pid] = 13000; //Sabre
            }
        }
        new string[100];
        format(string, sizeof(string), "Are you sure you want to purchase\nthis vehicle for %d?", pDPrice[pid]);
        ShowPlayerDialog(pid, DealerDialog, DIALOG_STYLE_MSGBOX, "Confirmation", string, "Yes", "No");
    }
pawn Код:
if(dialogid == DealerDialog)
    {
        if(!response) return 1;
        VehicleCreate(pDModel[pid], -1973.8954, 301.1895, 34.9524, 0, 0, 0, playerid);
        if(GetPlayerMoney(pid) < pDPrice[pid]) return ErrorMessage(pid, "You do not have enough cash.");
        GivePlayerMoney(pid, -pDPrice[pid]);
        pDModel[pid] = 0;
        pDPrice[pid] = 0;
        new Query[150];
        format(Query, sizeof(Query), "INSERT INTO `VEHICLES` (`MODEL`) VALUES (%d)", pDModel[pid]);
        db_query(gamemode, Query);
    }
Reply
#5

Now that's a way to use a shit load of lines Sure it looks nice having that final line count.. But it's harder to edit. :3

Here's what I'm trying out:

Код:
	if(listid == saloons)
	{
	    if(response)
	    {
			new price, vehicleid;
			if(modelid == 445) { price = 45000; } // Admiral
			else if(modelid == 401) { price = 35000; } // Bravura
                        // And so on (Will not release anymore, due to people copying my hard work with no rep ;)
Rep given to both, I'm going to keep using mSelection, and try it out this way.
Also thanks for the approaches on the other post!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)