Author Topic: Questions [SQ-Lite]  (Read 1324 times)

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Questions [SQ-Lite]
« on: April 01, 2016, 06:29:42 am »
Code: [Select]
class playerstats And
Code: [Select]
class constructor
So what is the difference in both? It's Important to have both right?

This is where I would like to be corrected or explained more in detail.

It seems Class is for Blank values in the players data Example

Code: [Select]
class PlayerStats
{
     Kills = 0;
     Deaths = 0;
     Joins = 0;
     Cash = 0;
     Wanted_Level = 0;
     LastUsedIP = "0.0.0.0";
     LUID = "0000000000000000000000000000000000000000";
     PreviousData = false;
}
Personally Thats what I feel this is used for, 

Where as a
Code: [Select]
class constructor
Is for loading data? Yes??

I beleave a
Code: [Select]
class constructor would be used for something like this

Code: [Select]
         
          stats[ id ].Kills = sqlite_column_data( q, 0 );
          stats[ id ].Deaths = sqlite_column_data( q, 1 );
          stats[ id ].Joins = sqlite_column_data( q, 2 );
          stats[ id ].Cash = sqlite_column_data( q, 3 );
  stats[ id ].Wanted_Level = sqlite_column_data( q, 4 );
  stats[ id ].LastUsedIP = sqlite_column_data( q, 5 );
  stats[ id ].LUID = sqlite_column_data( q, 6 );
Getting the data from each column, Is this Important? Wouldn't this Be useful for a Login system. or could I just add in a function to call back on say on playerJoin if level = true tell them to login, else Please Register.???

I just need to clear up my mind on these two different style of classes

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Questions [SQ-Lite]
« Reply #1 on: April 01, 2016, 01:24:07 pm »
A constructor isn't different from a class, it's part of the class.

A constructor is used when you invoke the class (similar to calling a function). The code inside of the constructor is ran, and a class instance is created and returned.

Here is an example, using the class from your post:
Code: [Select]
class PlayerStats {
     Kills = 0;
     Deaths = 0;
     Joins = 0;
     Cash = 0;
     Wanted_Level = 0;
     LastUsedIP = "0.0.0.0";
     LUID = "0000000000000000000000000000000000000000";
     PreviousData = false;

constructor( ) {
// Do stuff here when the class is called like a function.
}
}

You can then use something like this, which will return a class instance:
Code: [Select]
PlayerStats( );


For the SQLite part of your post:
Yes, grabbing each row of data is necessary, but only once per player. If you don't, then you will have to query the database everytime you retrieve or update data, which is not recommended. You can just create an array, and store each player's stats in the array's slots via the PlayerStats class like the one in my code above.

Also, yes, you could match a value from the array in onPlayerJoin to make sure that data was loaded. This is actually my preferred method I personally use.
« Last Edit: April 01, 2016, 01:26:47 pm by Vortrex »

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Questions [SQ-Lite]
« Reply #2 on: April 01, 2016, 04:53:13 pm »
I thought so, so basically i can run Many functions in the class?
custom functions etc?

This Build is the slowest build I have ever done. I do not want Memory leakage, And I also do not want to kick a player if he does not login, as well I do not want a player to automatically login on join if IP, LUID = same. Rather create a command possibly for that. so far I am storing the players Data in a array when they join. and when they leave save that data, and if no account on player part free that array. So its hard to just start a login, register system as I am not really to sure how I want to go about it,.  I do not want to just throw it together as that is not good enough for me.

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Questions [SQ-Lite]
« Reply #3 on: April 15, 2016, 02:30:41 am »
Sorry for the late response on this. Didn't realize your replied.

For these two questions:
I thought so, so basically i can run Many functions in the class?
custom functions etc?


Yes, you can add functions to a class, however I believe they use the local scope of the class, so if you need anything global then you'll probably have to add a double colon before whatever it is you need to use (i.e. ::FindVehicle ).

As for the rest, you can add and remove these features yourself, as they aren't hardcoded into LU. For a login and register system, I recommend using one of the base scripts provided by members of the LU community found in the 'Script Releases' section

 

© Liberty Unleashed Team.