Problem i can't solve this help me

Started by =RK=MarineForce, Sep 05, 2018, 11:11 AM

Previous topic - Next topic

=RK=MarineForce

class PlayerStats
{
level = 0;
}

function onScriptload()
{
db <- ConnectSQL( "DataBase.db" );
stats <- array( GetMaxPlayers(), null )
QuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, KILLS NUMERIC, DEATHS NUMERIC, CASH NUMERIC, Level NUMERIC )
}

function LoadStats(player)
{
local q = QuerySQL( "SELECT * FROM Stats WHERE Name = '"+player.Name+"'" )
if ( q )
{
stats[player.ID].Level = GetSQLColumnData( q, 4)
}
}

else if ( cmd == "level" )
{
Stats[player.ID].level >= 7;
}

else if ( cmd == "levels")
{
if ( stats[player.ID].Level >= 7  )
{
MessagePlayer(" if show works so works",player);
}
else MessagePlayer(" works ",player);
}

bro i made this. for admin level. but it didn't working.


rww

1. You gap " in QuerySQL line.
2. In /level command, you use Stats instead of stats (letter case it's important thing).
3. Also in /level command, you do something completely nosense? Why ">=" instead of "="?
4. I hope you have not forgotten use LoadStats function in onPlayerJoin event and stats[player.ID].Level = 0 (or something like this) in onPlayerPart event?
5. If after "if" you have only one line (like in /levels command), you can do it without { } like here:
else if ( cmd == "levels")
{
if (stats[player.ID].Level >= 7) MessagePlayer(" if show works so works",player);
else MessagePlayer(" works ",player);
}
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X

umar4911

Always post error to see the issue. There is no error in some cases.
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter

=RK=MarineForce

rww its showing me error.

can u make it ? if u make it i will understand when i read it . Plese?

i m using Kelvin Account System

Thomas

#5
Quote from: Xenon on Sep 05, 2018, 12:25 PMhttp://wiki.vc-mp.org/wiki/OnPlayerCommand

Quoteclass PlayerStats
   {
      constructor(){
      // do something here for default values.
      }
      level = 0;
   }

   function onScriptload()
   {
      db <- ConnectSQL( "DataBase.db" );
      /* to avoid confusion, i set this global variable to pstats instead of stats
                 to differentiate between table name and variable.*/
      pstats <- array( GetMaxPlayers(), null ); // semi-colon
      QuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, KILLS NUMERIC, DEATHS NUMERIC, CASH NUMERIC, Level NUMERIC ); // semi-colon
      /* table name is always case sensitive 'Stats' != 'stats', remember to use lower case for less mistakes.*/
   }
   function OnPlayerJoin( player )]
   {
   /* We will set default value for newly joined player so that scirpt won't crash if something is not in squirrel root table*/
   
      pstats[player.ID] = PlayerStats();
      // Give them shiny new welcome!
      MessagePlayer("Welcome to the shittest server of VC:MP",player);
      /*
      Do some stuff here like registration, ban check etc.
      */
      LoadStats(player);
   }
   function LoadStats(player)
   {   
      // Load some data if player exists!
      local q = QuerySQL( "SELECT * FROM Stats WHERE Name = '"+player.Name+"'" )
      if ( q )
      {
         pstats[player.ID].Level = GetSQLColumnData( q, 4);
      }
   }
   function onPlayerCommand( player, cmd, text )
   {
      /* we'll be using switch statement instead of old tragic if else if.
                since the player only changes value of same variable for different cmds, switch is in this case is essential and most efficent way to work with */
         // reference: https://www.programiz.com/cpp-programming/switch-case
         switch( cmd )
         {
            // start of our case.
            case "level": {
            /* we will be using if / else if / else condition statement if only if we're comparing values logically ( most preferable )*/
            local plrLevel = pstats[player.ID].level;
               if(plrLevel >= 7) {
                  MessagePlayer("Woah there! you're admin with level " + plrLevel ,player);
               }
               else {
                  MessagePlayer("hmm, you do not have level" ,player);
               }
            }
            break;
            // end of our case.
         }
   
   }
p.s using quote instead of code, because code fucks up indentation.
Code is untested, might have some missing links or bugs

=RK=MarineForce

all working fine

but this line giving error

QuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, KILLS NUMERIC, DEATHS NUMERIC, CASH NUMERIC, Level NUMERIC ); // semi-colon

my scriptload usage

function onScriptLoad()
{
 Stats <- array( GetMaxPlayers(), null );
    NPC <- array( GetMaxPlayers(), null );
    HealthNpc <- array( GetMaxPlayers(), 200 );
    NewNPC();
NewTimer("AutoMoveNpc",2000,0)
SetSpawnPlayerPos(-1168, -617.437, 12.7852);
SetSpawnCameraPos( -1170.91, -617.551, 11.8277 );
SetSpawnCameraLook( -1170.91, -617.551, 11.8277 );
LoadCars();
SetPassword("");
SetServerName( "Cubans VS Haitians Offical VC-MP Server.")
AddClass( 1, RGB( 255, 255, 3 ) ,83,Vector( -1167.65, -631.166, 11.8277 ), 0.0256715, 19, 999 ,18, 999, 23, 400 );
AddClass( 1, RGB( 255, 255, 3 ) ,84, Vector( -1161.51, -620.439, 11.6416 ), 2.34820, 21, 999 ,18, 999, 23, 400 );
AddClass( 2, RGB( 000, 000, 255 ) ,85, Vector( -1176.89, 69.6168, 17.9584 ), 2.34820, 19, 999 ,18, 999, 22, 400 );
AddClass( 2, RGB( 000, 00, 255 ) ,86, Vector( -1176.89, 69.6168, 17.9584 ), 2.34820, 21, 999 ,18, 999, 22, 400 );
AddClass( 0, RGB( 209, 209, 209 ) ,215, Vector( -1579.78, -412.739, 284.937 ), 2.34820, 10, 999 ,10, 999, 10, 400 );

 stats <- array( GetMaxPlayers(), null );
 database <- ConnectSQL( "data_base.db" );
 QuerySQL( database, "CREATE TABLE IF NOT EXISTS account ( player VARCHAR(32), password VARCHAR(255), uid VARCHAR(255), kills INTEGER, deaths INTEGER, headshots INTEGER, joins INTEGER, cash INTEGER )" );
 print( "Successfully Account System by =TRC=Kelvin." );
print( "Successfully SCript Loaded by =RK=MarineForce." );
H <- BindKey(true,0x48,0,0);
Heal <- array( GetMaxPlayers(), false );
NewTimer("Key_Pressing" , 1000, 0 );
IsMuted <- array( GetMaxPlayers(), false);
  antiSpamTime <- array( GetMaxPlayers(), 0 );
  antiSpamWarnings <- array( GetMaxPlayers(), 0 );
 //cUBAN
CreatePickup(284, Vector(-1169.43, -579.962, 11.6415 ));
CreatePickup(368, Vector(-1164.71, -579.601, 11.6416 ));
CreatePickup(287, Vector(-1158.8, -578.855, 11.6416 ));
CreatePickup(290, Vector(-1153.84, -578.873, 11.6417 ));
//Haitian
CreatePickup(284, Vector( -1197.89, 96.7103, 11.1281 ));
CreatePickup(368, Vector( -1197.38, 84.9993, 11.1281 ));
CreatePickup(287, Vector( -1197.64, 74.3451, 11.1281 ));
CreatePickup(290, Vector( -1187.6, 85.1885, 11.1281 ));
//BOMB
CreatePickup(380, Vector( -1187.42, 102.232, 11.1281 ));
CreatePickup(380, Vector( -1182.11, 80.8089, 11.1281 ));
CreatePickup(380, Vector( -1174.52, 69.3468, 17.9584));
}

Thomas

database <- ConnectSQL( "data_base.db" );
 QuerySQL( database, "CREATE TABLE IF NOT EXISTS account ( player VARCHAR(32), password VARCHAR(255), uid VARCHAR(255), kills INTEGER, deaths INTEGER, headshots INTEGER, joins INTEGER, cash INTEGER )" );
Quotedatabase <- ConnectSQL( "data_base.db" );

QuoteQuerySQL(db, "CREATE TABLE IF NOT EXISTS Stats( Name TEXT, KILLS NUMERIC, DEATHS NUMERIC, CASH NUMERIC, Level NUMERIC ); // semi-colon

change db to database.