.db

Started by Humzasajjad, Sep 19, 2018, 08:01 PM

Previous topic - Next topic

Humzasajjad

Can anyone give me admin.db..or where admins data will be saved....
Admin data saved in database.db?

Mahmoud Tornado

Saved in database.db like levels.
QuerySQL(db, "create table if not exists Database ( Name TEXT, LowerName TEXT, Password VARCHAR(255), Level NUMERIC DEFAULT 1, IP VARCHAR(255) ");

Or you can make another one with all things like an new account system.

class PlayerClass - Stats[player.ID].Level
Level = 0;

onScriptLoad() - New database to make admin levels.
Admindb <- ConnectSQL("AdminsDataBase.db");
 QuerySQL(Admindb, "create table if not exists Admins ( Name TEXT, LowerName TEXT, Level NUMERIC DEFAULT 0 ) ");
 Stats <- array(GetMaxPlayers(), null);

onPlayerJoin( player ) - Getting admin stats.
IfAdmin(player);
Stats[ player.ID ] = PlayerClass();

If Admin Function.
function IfAdmin(player)
{
 local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(player.Name) + "'");
 if (q)
 {
  Stats[ player.ID ].Level = GetSQLColumnData(q, 1);
 }
}

Setlevel Command.
if ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
  local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
else
{
         Stats[ plr.ID ].Level = lvl.tointeger();
QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}

doxuanhien2002

Quote from: Humzasajjad on Sep 19, 2018, 08:01 PMCan anyone give me admin.db..or where admins data will be saved....
Admin data saved in database.db?
https://forum.vc-mp.org/?topic=3364.0
Flooding the board with separate requests for many disparate items is not allowed.
If you need a whole set of things for your server, you should list them all in one thread rather than spamming this board with fifteen threads about each of the things you want your server to do.

Humzasajjad

 QuerySQL(db, "create table if not exists Database ( Name TEXT, LowerName TEXT, Password VARCHAR(255), Level NUMERIC DEFAULT 1, IP VARCHAR(255) ");
if ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
   local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
  if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
  else
 {
         Stats[ plr.ID ].Level = lvl.tointeger();
  QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}
bro when i add this there was on script load error comes

Mahmoud Tornado

Quote from: Humzasajjad on Sep 20, 2018, 11:49 AMQuerySQL(db, "create table if not exists Database ( Name TEXT, LowerName TEXT, Password VARCHAR(255), Level NUMERIC DEFAULT 1, IP VARCHAR(255) ");
if ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
   local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
  if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
  else
 {
         Stats[ plr.ID ].Level = lvl.tointeger();
  QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}
bro when i add this there was on script load error comes
This /setlevel command, for the second system not the first.
For the first will being like that,
else if ( cmd == "setlevel" )
{
   if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2);
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
         Stats[ plr.ID ].Level = lvl.tointeger();
         QuerySQL( db,"UPDATE Database SET Level='"+lvl+"' WHERE lower(Name) LIKE '"+plr.Name+"'");
         Message("Administration Command: Admin "+player.Name+" Has Set level of "+plr.Name+" to: "+lvl+".");
      }
   }
}

Humzasajjad

Quote from: Mahmoud Tornado on Sep 20, 2018, 01:03 PM
Quote from: Humzasajjad on Sep 20, 2018, 11:49 AMQuerySQL(db, "create table if not exists Database ( Name TEXT, LowerName TEXT, Password VARCHAR(255), Level NUMERIC DEFAULT 1, IP VARCHAR(255) ");
if ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
   local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
  if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
  else
 {
         Stats[ plr.ID ].Level = lvl.tointeger();
  QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}
bro when i add this there was on script load error comes
This /setlevel command, for the second system not the first.
For the first will being like that,
else if ( cmd == "setlevel" )
{
   if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2);
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
         Stats[ plr.ID ].Level = lvl.tointeger();
         QuerySQL( db,"UPDATE Database SET Level='"+lvl+"' WHERE lower(Name) LIKE '"+plr.Name+"'");
         Message("Administration Command: Admin "+player.Name+" Has Set level of "+plr.Name+" to: "+lvl+".");
      }
   }
}
it works but when i type /setlevel <myname> <lvl>there was no message and change...what to do?

=RK=MarineForce

i made this only :( :'( ...

Mahmoud Teach me on discord :P

class PlayerStats
{
Level = 1;
}

function onScriptLoad()
{
QuerySQL(level, "create table if not exists Level ( Name Text, Password VARCHAR(255), Level NUMERIC, IP VARCHAR(255) ");
Ldb <- ConnectSQL("LevelDatabase.db");
}

Function OnScriptUnload()
{
DisconnectSQL("level" )
}

function onPlayerJoin( player )
{
Stats[ player.ID ] = PlayerStats();
}


else if ( cmd == "setlevel" )
{
if(!text) MessagePlayer(" /" + cmd + " <Nick> <Level> ",player);
else{
local plr = FindPlayer(text);
if(!plr) MessagePlayer(" [#ff0000] Error " + text + " is not online ",player);
else{
Stats[ plr.ID ].Level = text.tointeger();
}
}
}

Mahmoud Tornado

@Humzasajjad, If you use the first on in your account system use this one.
else if ( cmd == "setlevel" )
{
   if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2);
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
         Stats[ plr.ID ].Level = lvl.tointeger();
         QuerySQL( db,"UPDATE Database SET Level='"+lvl+"' WHERE lower(Name) LIKE '"+plr.Name+"'");
         Message("Administration Command: Admin "+player.Name+" Has Set level of "+plr.Name+" to: "+lvl+".");
      }
   }
}

If you using the second one use this,
if ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
   local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
  if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
  else
 {
         Stats[ plr.ID ].Level = lvl.tointeger();
  QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}

It's not doing thing, as you are using the two systems together, and you can't make two level stats for the player.

Quote from: Humzasajjad on Sep 20, 2018, 11:49 AMQuerySQL(db, "create table if not exists Database ( Name TEXT, LowerName TEXT, Password VARCHAR(255), Level NUMERIC DEFAULT 1, IP VARCHAR(255) ");
This is the first system, this is a addition to accounts system.

But the command which you used is for the admins db.
Quote from: Humzasajjad on Sep 20, 2018, 11:49 AMif ( cmd == "setlevel" )
{
if ( !text ) MessagePlayer( "/"+cmd+" <Nick/id> <Level>", player );
   else
   {
      local
         plr = GetPlayer( GetTok( text, " ", 1 ) ),
         lvl = GetTok( text, " ", 2),
      if ( !plr ) MessagePlayer( "Unknown Player..", player );
     else if ( !lvl ) MessagePlayer("You must put a level.", player);
      else if ( !IsNum( lvl ) ) MessagePlayer("Level must be in numbers.", player);
      else
      {
   local q = QuerySQL(Admindb, "SELECT * FROM Admins WHERE Name = '" + escapeSQLString(plr.Name) + "'");
  if (!q)   QuerySQL( DataBase, "INSERT INTO Accounts ( Name, LowerName, Level ) VALUES ( '" + escapeSQLString(plr.Name) + "','" + escapeSQLString(plr.Name) + "','" + 0 + "')" );
  else
 {
         Stats[ plr.ID ].Level = lvl.tointeger();
  QuerySQL( Admindb, "UPDATE Admins SET Level='"+lvl+"' WHERE Name LIKE '" + plr.Name + "'" );
         Message("Administration Command: Admin "+player.Name+" Has Set "+plr.Name+" As an admin level: "+lvl+".");
      }
    }
   }
}
So it must get error.

=RK=MarineForce

#8
class PlayerStats
{
Level = 0;
Cash = 1;
Kills = 1;
Deaths = 1;
}

function OnScriptLoad()
{
Yesdb <- ConnectSQL("YesDatabase.db");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Admins ( Name TEXT, LowerName TEXT, Level NUMERIC DEFAULT 0 ) ");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Kills ( Name TEXT, LowerName TEXT, Kills NUMERIC DEFAULT 1 ) ");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Deaths ( Name TEXT, LowerName TEXT,Deaths NUMERIC DEFAULT 1 ) ");
QuerySQL(Yesdb, "CREATETABLE IF NOT EXISTS Cash ( Name TEXT, LowerName TEXT, Cash NUMERIC DEFAULT 1 ) ");
Stats <- array(GetMaxPlayers(), null);
}
function onPlayerJoin( player )
{
Stats[ player.ID ] = PlayerStats();
}
i made some thing like this but i don't know how can i save kills deaths etc. help..


KrOoB_

#10
Quote from: =RK=MarineForce on May 18, 2019, 02:23 AMclass PlayerStats
{
Level = 0;
Cash = 1;
Kills = 1;
Deaths = 1;
}

function OnScriptLoad()
{
Yesdb <- ConnectSQL("YesDatabase.db");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Admins ( Name TEXT, LowerName TEXT, Level NUMERIC DEFAULT 0 ) ");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Kills ( Name TEXT, LowerName TEXT, Kills NUMERIC DEFAULT 1 ) ");
QuerySQL(Yesdb, "CREATE TABLE IF NOT EXISTS Deaths ( Name TEXT, LowerName TEXT,Deaths NUMERIC DEFAULT 1 ) ");
QuerySQL(Yesdb, "CREATETABLE IF NOT EXISTS Cash ( Name TEXT, LowerName TEXT, Cash NUMERIC DEFAULT 1 ) ");
Stats <- array(GetMaxPlayers(), null);
}
function onPlayerJoin( player )
{
Stats[ player.ID ] = PlayerStats();
}
i made some thing like this but i don't know how can i save kills deaths etc. help..


why did u split them ?


class PlayerSystem
{
 Level = 0; // For Admin system
 Kills = 0;
 Deaths = 0;
 Cash = 0;
 Bank = 0;
...
...
...
}
QuerySQL(System, "create table if not exists Accounts ( Name TEXT, LowerName TEXT,  Level NUMERIC DEFAULT 1, Kills NUMERIC DEFAULT 0, Deaths NUMERIC DEFAULT 0, Cash NUMERIC DEFAULT 0, Bank NUMERIC DEFAULT 0 ) ");

...

=RK=MarineForce

Thanks Bro:

but how can i add kill system when players kill a player a die.

KrOoB_

#12
if u're using 7. Muhammed's Account System


and for onPlayerKill
stats[ killer.ID ].Kills ++;
stats[ player.ID ].Deaths ++;


KrOoB_

@Mohamed already add this in his script so u don't have to do this just download it and try to understand