Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: KAKAN on Sep 26, 2015, 05:46 PM

Title: rulk sunshine problem
Post by: KAKAN on Sep 26, 2015, 05:46 PM
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
Title: Re: rulk sunshine problem
Post by: Thijn on Sep 26, 2015, 06:29 PM
You can remove that FreeSQLQuery since an update query will not return anything.
Title: Re: rulk sunshine problem
Post by: KAKAN on Sep 26, 2015, 07:00 PM
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
Title: Re: rulk sunshine problem
Post by: MacTavish on Sep 26, 2015, 07:03 PM
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
Title: Re: rulk sunshine problem
Post by: rulk on Sep 26, 2015, 07:05 PM
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.
Title: Re: rulk sunshine problem
Post by: KAKAN on Sep 27, 2015, 04:14 AM
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 :(
Title: Re: rulk sunshine problem
Post by: rulk on Sep 27, 2015, 09:38 AM
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.
Title: Re: rulk sunshine problem
Post by: KAKAN on Sep 27, 2015, 01:32 PM
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
Title: Re: rulk sunshine problem
Post by: Thijn on Sep 27, 2015, 02:10 PM
How many vehicles do you have?
Title: Re: rulk sunshine problem
Post by: KAKAN on Sep 27, 2015, 03:32 PM
200
I'll update them to 700
Title: Re: rulk sunshine problem
Post by: Thijn on Sep 28, 2015, 05:37 AM
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.
Title: Re: rulk sunshine problem
Post by: rulk on Sep 29, 2015, 09:25 AM
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 :-/