Dealerships cause 3-5 seconds lag
#1

Alright so I'm using my script but dealerships are causing lag when being made/buying vehicles etc, anyways I've used my script before and this has never happened - what would be causing this?
Reply
#2

Large amount of files, slow connection to mysql database, too big loops, whatever. It is impossible to say anything specific without seeing the relevant code.
Reply
#3

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Large amount of files, slow connection to mysql database, too big loops, whatever. It is impossible to say anything specific without seeing the relevant code.
https://sampforum.blast.hk/showthread.php?tid=425546

I made the post about it ages ago - the code it there and everything.

Edit:
Most of the dealership commands and everything else is on that link above.
pawn Код:
CMD:editcardealership(playerid, params[])
{
    for(new d = 0 ; d < MAX_CARDEALERSHIPS; d++)
    {
        if(IsPlayerInRangeOfPoint(playerid, CarDealershipInfo[d][cdRadius], CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ])) {
            if(IsPlayerOwnerOfCDEx(playerid, d))
            {
                SetPVarInt(playerid, "editingcd", d);
                SetPVarInt(playerid, "editingcdveh", -1);
                SetPVarInt(playerid, "editingcdvehpos", 0);
                SetPVarInt(playerid, "editingcdvehnew", 0);
                new listitems[] = "1 New Vehicle\n2 My Vehicles\n3 Upgrade\n4 Till";
                ShowPlayerDialog(playerid,DIALOG_CDEDIT,DIALOG_STYLE_LIST,"Choose an item to continue", listitems,"Select","Cancel");
                return 1;
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_GREY, "You do not own that Car Dealership.");
                return 1;
            }
        }
    }
    SendClientMessageEx(playerid, COLOR_GREY, "ERROR: You must be standing inside the radius of the Car Dealership.");
    return 1;
}

CMD:editcar(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    new v, d;
    v = GetCarDealershipVehicleId(vehicleid);
    d = GetCarDealershipId(vehicleid);
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessageEx(playerid, COLOR_GREY, "ERROR: You are not in any car.");
    if(v != -1 && d != -1)
    {
        if(IsPlayerOwnerOfCDEx(playerid, d))
        {
            SetPVarInt(playerid, "editingcd", d);
            SetPVarInt(playerid, "editingcdveh", v);
            SetPVarInt(playerid, "editingcdvehpos", 0);
            SetPVarInt(playerid, "editingcdvehnew", 0);
            new listitems[] = "1 Edit Model\n2 Edit Cost\n3 Edit Park\n4 Delete Vehicle";
            ShowPlayerDialog(playerid,DIALOG_CDEDITONE,DIALOG_STYLE_LIST,"Car Dealership:", listitems,"Select","Cancel");
            return 1;
        }
        else
        {
            SendClientMessageEx(playerid, COLOR_GREY, "ERROR: You do not own that Car Dealership.");
        }
    }
    else
    {
        SendClientMessageEx(playerid, COLOR_GREY, "ERROR: Car is not part of a Car Dealership.");
    }
    return 1;
}

CMD:buydealership(playerid, params[])
{
    for(new d = 0 ; d < MAX_CARDEALERSHIPS; d++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ]))
        {
            if(!CarDealershipInfo[d][cdOwned])
            {
                if(GetPVarInt(playerid, "Cash") < CarDealershipInfo[d][cdPrice])
                {
                    SendClientMessageEx(playerid, COLOR_GREY, " You do not have enough money to buy this Car Dealership.");
                    return 1;
                }
                SetPVarInt(playerid, "Cash", GetPVarInt(playerid, "Cash")-CarDealershipInfo[d][cdPrice]);
                SetPlayerOwnerOfCD(playerid, d);
                PlayerPlayMusic(playerid);
                SendClientMessageEx(playerid, COLOR_WHITE, "Congratulations, On Your New Purchase.");
                SendClientMessageEx(playerid, COLOR_WHITE, "Type /help to review the new car dealership help section.");
                SendClientMessageEx(playerid, COLOR_GRAD1, " Please set the position you want your brought cars to spawn.");
                SendClientMessageEx(playerid, COLOR_GRAD2, " Stand where you want to have your brought vehicles spawn.");
                SendClientMessageEx(playerid, COLOR_GRAD2, " Once ready press the fire button.");
                SendClientMessageEx(playerid, COLOR_WHITE, " Note: If you don't set it your customers wont be able to buy any cars.");
                SetPVarInt(playerid, "editingcdvehpos", 2);
                SetPVarInt(playerid, "editingcd", d);
                return 1;
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_GREY, "That Car Dealership is already owned and it's not for sale.");
            }
        }
    }
    return 1;
}

CMD:selldealership(playerid, params[])
{
    new string[128];

    for(new d = 0 ; d < MAX_CARDEALERSHIPS; d++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ]))
        {
            if(IsPlayerOwnerOfCDEx(playerid, d))
            {
                SetPVarInt(playerid, "editingcd", d);
                format(string,128,"Are you sure you want to sell this Car Dealership for $%d?\n.", CarDealershipInfo[d][cdPrice] / 2);
                ShowPlayerDialog(playerid,DIALOG_CDSELL,DIALOG_STYLE_MSGBOX,"Warning:",string,"Sell","Cancel");
                return 1;
            }
            else
            {
                SendClientMessageEx(playerid, COLOR_GREY, "You are not the owner of this car dealership.");
                return 1;
            }
        }
    }
    SendClientMessageEx(playerid, COLOR_GREY, "You have to be near a car dealership.");
    return 1;
}

CMD:createcdveh(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 100004)
    {
        SendClientMessageEx(playerid, COLOR_GREY, " You are not allowed to use this command.");
        return 1;
    }

    new string[128], price, dealershipid, modelid;
    if(sscanf(params, "ddd", price, dealershipid, modelid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /createcdveh [price] [dealership] [modelid]");

    new Float:X,Float:Y,Float:Z,Float:A;
    GetPlayerPos(playerid,X,Y,Z);
    GetPlayerFacingAngle(playerid, A);
    new cdvehicleid = CreateCarDealershipVehicle(dealershipid, modelid, X, Y, Z, A, price);
    if(cdvehicleid == -1)
    {
        SendClientMessageEx(playerid, COLOR_GREY, "ERROR: cdVehicles limit reached.");
    }
    else
    {
        format(string, sizeof(string), " Car Dealership Vehicle created with ID %d.", cdvehicleid);
        SendClientMessageEx(playerid, COLOR_GRAD1, string);
    }
    return 1;
}

CMD:destroycdveh(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 100004)
    {
        SendClientMessageEx(playerid, COLOR_GREY, " You are not allowed to use this command.");
        return 1;
    }

    new string[128], vehid;
    if(sscanf(params, "d", vehid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /destroycdveh [vehicleid]");

    DestroyCarDealershipVehicle(GetCarDealershipId(vehid), GetCarDealershipVehicleId(vehid));
    SavecDealership(GetCarDealershipId(vehid));
    format(string, sizeof(string), " Car Dealership Vehicle destroyed with ID %d.", vehid);
    SendClientMessageEx(playerid, COLOR_GRAD1, string);
    return 1;
}

CMD:createdealership(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 100004)
    {
        SendClientMessageEx(playerid, COLOR_GREY, " You are not allowed to use this command.");
        return 1;
    }

    new string[128], price, radius, message[64];
    if(sscanf(params, "dds[64]", price, radius, message)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /createdealership [price] [radius] [message]");

    new Float:X,Float:Y,Float:Z;
    GetPlayerPos(playerid,X,Y,Z);
    new dealershipid = CreateCarDealership(X, Y, Z, radius, price, message);
    if(dealershipid == -1)
    {
        SendClientMessageEx(playerid, COLOR_GREY, "ERROR: Car Dealerships limit reached.");
    }
    else
    {
        format(string, sizeof(string), " Car Dealership created with ID %d.", dealershipid);
        SendClientMessageEx(playerid, COLOR_GRAD1, string);
    }
    return 1;
}

CMD:destroydealership(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 100004)
    {
        SendClientMessageEx(playerid, COLOR_GREY, " You are not allowed to use this command.");
        return 1;
    }

    new string[128], dealershipid;
    if(sscanf(params, "d", dealershipid)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /destroydealership [dealershipid]");

    for(new d = 0 ; d < MAX_CARDEALERSHIPS; d++)
    {
        if(IsPlayerInRangeOfPoint(playerid, 3.0, CarDealershipInfo[d][cdEntranceX], CarDealershipInfo[d][cdEntranceY], CarDealershipInfo[d][cdEntranceZ]))
        {
            DestroyCarDealership(d);
            format(string, sizeof(string), " Car Dealership destroyed with ID %d.", d);
            SendClientMessageEx(playerid, COLOR_GRAD1, string);
            return 1;
        }
    }
    if(dealershipid > MAX_CARDEALERSHIPS) return 1;
    if(dealershipid < 0) return 1;
    DestroyCarDealership(dealershipid);
    format(string, sizeof(string), " Car Dealership destroyed with ID %d.", dealershipid);
    SendClientMessageEx(playerid, COLOR_GRAD1, string);
    return 1;
}
Reply
#4

Why did you take out the djAutocommit(false) in the save code?
This way eventually you are recreating the whole file up to several hundered times for each saving. You should safe the file just once when youre done instead. It might also be worth to create separate files for each car dealer, this would reduce the overhead for saving a lot, just is a bit more complicated to load.
Reply
#5

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Why did you take out the djAutocommit(false) in the save code?
This way eventually you are recreating the whole file up to 50 times for each saving. You should safe the file just once when youre done instead. It might also be worth to create separate files for each car dealer, this would reduce the overhead for saving a lot, just is a bit more complicated to load.
Alright I see what you mean; but how do I go on doing that? It seems abit hard - Do you have Skype or can go on my TeamViewer and insist me on doing so?
Reply
#6

Sorry, I just give ideas what to do, but im not going to do your job.
To split them in single files, basically all you need to do is adding a number to the filenames, removing the index numbers from the ini entries, and create a file that contains all valid dealership ids, so you know what ids to load afterwards.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)