rulk sunshine problem

Started by KAKAN, Sep 26, 2015, 05:46 PM

Previous topic - Next topic

KAKAN

Hello guys, I'm using rulk's sunshine buycar/getcar system, but I encountered an error.
Error on which function it happens
function SaveDatabase(database)
{
// Iterate the array
foreach ( obj in this[ MyArray ] )
{
// Check we have an actual instance in the array element.
if ( obj != null )
{
// Instance properties.
local
                            pVehicleID =    obj.VehicleID,
        pVehicleModel =    obj.VehicleModel,
        pVehicleCat = obj.VehicleCat,
        pVehiclePrice = obj.VehiclePrice,
        pIsPurchased = obj.IsPurchased != null ? obj.IsPurchased : "",
        pIsShared = obj.IsShared != null ? obj.IsShared   : "";

// The SQL Query we wish to execute.
local query = @" UPDATE " + MyArray +

           " SET VehicleModel=" + "'" + pVehicleModel + "'" + ", " +
    "VehicleCat=" + "'" + pVehicleCat + "'" + ", " +
    "VehiclePrice=" + "'" + pVehiclePrice + "'" + ", " +
    "IsPurchased=" + "'" + pIsPurchased + "'" + ", " +
    "IsShared=" + "'" + pIsShared + "'" +

            " WHERE VehicleID=" + pVehicleID;

        // Execute the query
          ::QuerySQL( db, query );

// Free it, thats the last time we need it
FreeSQLQuery( query );
}
}
}

The error line is:-
FreeSQLQuery( query );
The error is:-
parameter 0 has an invalid type 'class' ; expected: 'table'
Help me, I can't find the error
oh no

Thijn

You can remove that FreeSQLQuery since an update query will not return anything.

KAKAN

If i remove it, then the server behaves like a lag-bot, that action is performed when a player leaves, if i remove it, then when a player leaves, my server lags for a while, if i add it, the error is thrown, but the server doesn't lags
oh no

MacTavish

Quote from: KAKAN on Sep 26, 2015, 07:00 PMIf i remove it, then the server behaves like a lag-bot, that action is performed when a player leaves, if i remove it, then when a player leaves, my server lags for a while, if i add it, the error is thrown, but the server doesn't lags
because this system takes that while for saving the stats, As @Thijn says you can remove that line since you are just Updating database not selecting anything from database

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

rulk

hya KAKAN,

that line was commented out, it was me when I was testing. you can remove it like thijn says.

with ref to the lag, that cannot be the sunshine script, as it's reading from an array not the database.

the only time you need to query the database is when Loading or Saving, so check your code for other problems.

let me know what you've found, and i'lll try to help.
We are all god's children.

KAKAN

#5
That's the only problem, MAN!, if i remove that line from onPlayerPart, then my server is not getting lagged.

Before a few days, it was working perfectly, but now its not :(
oh no

rulk

Quote from: KAKAN on Sep 27, 2015, 04:14 AMThat's the only problem, MAN!, if i remove that line from onPlayerPart, then my server is not getting lagged.

Before a few days, it was working perfectly, but now its not :(

do you have other database queries in your script ?
because that one query would not lag the script.
We are all god's children.

KAKAN

I removed your query option(SaveDb), and everything works fine, when I add that, server lags
Yes, I have one more query, that is to update player stats
oh no

Thijn

How many vehicles do you have?

KAKAN

200
I'll update them to 700
oh no

Thijn

Then that's the problem, it's doing 200 update queries when someone leaves. The best way to make it faster is probably combining queries by using Transactions.

You probably also don't need to save the database each time someone leaves. Maybe you can keep a variable which will be set to true once something has changed, and only then save the database.

rulk

Hya KAKAN,

You could do what @Thijn recommends,
alternatively, I would do the following....

// Devision of 3600 ( 1 hour ) - This will trigger every 60 minutes.
if ( abs( clock() ) % 3600 == 0 ) SunshineAutos.SaveDatabase("sunshine.db");

This way, you are saving the array to the database once every hour, you can increase the time to once every two hours if you prefer.

Hope this helps.

rulk

Ps, sorry for the late reply :-/
We are all god's children.