( Simple ) Admin System.

Started by Gito Baloch, Jul 11, 2021, 06:26 AM

Previous topic - Next topic

Gito Baloch

----------///---LEVEL SYSTEM---\\\----------

Player Class
class PlayerClass
{
    Level = 0;
}

Creating Database
Admin <- ConnectSQL("Level.db");
QuerySQL(Admin, "create table if not exists Level ( Name Text ,Level NUMERIC DEFAULT 0) ");

Functions
function AdminInfo(player)
{
    local q = QuerySQL(Admin, "SELECT * FROM Level WHERE Name = '" + escapeSQLString(player.Name) + "'");
    if (q)
    {
        stats[ player.ID ].Level = GetSQLColumnData(q, 1);
    }
    else QuerySQL( Admin, "INSERT INTO Level ( Name, Level ) VALUES ( '" + escapeSQLString(player.Name) + "', ' 0 ' )" );
}

function SaveAdmin(player)
{
    QuerySQL( Admin, "UPDATE Level SET Level='"+ stats[ player.ID ].Level +"' WHERE Name = '"+player.Name+"'");
}

OnPlayer Join
AdminInfo();

OnPlayer Part
SaveAdmin();
Set Level Command
   else if ( ( cmd == "setlevel" ) || ( cmd == "setlvl" ) )
{
if ( stats[ player.ID ].Level < 5 ) MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
else if ( !text ) PrivMessage( player, format( "Error: Use /%s <player> <Level>", cmd ) );
else
{
local txt = split( text, " " );
if ( txt.len() >= 2 )
{
local plr = FindPlayer( txt[ 0 ] ), lvl = txt[ 1 ];
if ( !plr ) PrivMessage( player, "Error: Unknown player." );
else if ( !IsNum( lvl ) ) ClientMessage( player, "Error: Level must be in numbers...",player, 255, 0, 0 );
else if ( ( lvl.tointeger() < 1 ) || ( lvl.tointeger() > 7 ) ) ClientMessage( "ERROR: Allowed Level amount are between 1 and 7.", player, 255, 0, 0 );
else if ( stats[ plr.ID ].Level == lvl.tointeger() ) PrivMessage( player, format( "Error: %s's Level is %d already.", plr.Name, lvl.tointeger() ) );
else
{
stats[ plr.ID ].Level = lvl.tointeger();
Message( "[#ffffff]"+player.Name+" [#25AAAA]changed the level of[#ffffff] "+plr.Name+"[#25AAAA] to [#ffffff]["+lvl.tointeger()+"].");
                }
}
else PrivMessage( player, format( "Error: Usage /%s <player> <Level>", cmd ) );
}
return 0;
}

Example command
else if ( cmd=="assrocket")
{
if(stats[player.ID].Level < 2) return MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
else
{
if (!text) MessagePlayer("[#51FF06]Usage :[#FFFFFF] /assrocket <Name/ID>",player);
else
{
local plr = FindPlayer(text);
plr.Pos = player.Pos;
Message("[#ffffff]"+player.Name+ "[#25AAAA] has bombed [#ffffff]" +plr.Name);
CreateExplosion( 1, 1,plr.Pos.x -3 , plr.Pos.y -5, plr.Pos.z, -1, true );
CreateExplosion( 1, 2,plr.Pos.x -3, plr.Pos.y -5, plr.Pos.z, -1, true );
CreateExplosion( 1, 3,plr.Pos.x -3, plr.Pos.y -5, plr.Pos.z, -1, true );
CreateExplosion( 1, 4,plr.Pos.x -3 , plr.Pos.y -5, plr.Pos.z, -1, true );
}
}
return 0;
}
Programming is the language I speak, the world I shape, and the future I code

GasanZ07

Hello buddy. You had a few mistakes on this, I fixed them and sent them to you.
 :)

class PlayerClass
{
    Level = 0;
}

function onScriptLoad()
{
stats <- array ( GetMaxPlayers(), null );
Admin <- ConnectSQL("Level.db");
QuerySQL(Admin, "create table if not exists Level ( Name Text ,Level NUMERIC DEFAULT 0) ");
}

function onPlayerJoin( player )
{
stats[ player.ID ] = PlayerClass();
AdminInfo(player);
}

function onPlayerPart( player, reason )
{
SaveAdmin(player);
}

function onPlayerCommand( player, cmd, text )
{
if ( ( cmd == "setlevel" ) || ( cmd == "setlvl" ) )
{
  if ( stats[ player.ID ].Level < 5 ) MessagePlayer("[#ff0000]Error: [#ffffff]You don't have permission to use this command.",player);
  else if ( !text ) PrivMessage( player, format( "Error: Use /%s <player> <Level>", cmd ) );
  else
  {
   local txt = split( text, " " );
   if ( txt.len() >= 2 )
   {
    local plr = FindPlayer( txt[ 0 ] ), lvl = txt[ 1 ];
    if ( !plr ) PrivMessage( player, "Error: Unknown player." );
    else if ( !IsNum( lvl ) ) ClientMessage( player, "Error: Level must be in numbers...",player, 255, 0, 0 );
    else if ( ( lvl.tointeger() < 1 ) || ( lvl.tointeger() > 7 ) ) ClientMessage( "ERROR: Allowed Level amount are between 1 and 7.", player, 255, 0, 0 );
    else if ( stats[ plr.ID ].Level == lvl.tointeger() ) PrivMessage( player, format( "Error: %s's Level is %d already.", plr.Name, lvl.tointeger() ) );
    else
    {
     stats[ plr.ID ].Level = lvl.tointeger();
     Message( "[#ffffff]"+player.Name+" [#25AAAA]changed the level of[#ffffff] "+plr.Name+"[#25AAAA] to [#ffffff]["+lvl.tointeger()+"].");
                }
   }
   else PrivMessage( player, format( "Error: Usage /%s <player> <Level>", cmd ) );
  }
  return 0;
 }
}

function AdminInfo(player)
{
    local q = QuerySQL(Admin, "SELECT * FROM Level WHERE Name = '" + escapeSQLString(player.Name) + "'");
    if (q)
    {
        stats[ player.ID ].Level = GetSQLColumnData(q, 1);
    }
    else QuerySQL( Admin, "INSERT INTO Level ( Name, Level ) VALUES ( '" + escapeSQLString(player.Name) + "', ' 0 ' )" );
}

function SaveAdmin(player)
{
    QuerySQL( Admin, "UPDATE Level SET Level='"+ stats[ player.ID ].Level +"' WHERE Name = '"+player.Name+"'");
}