Stafflist System

Started by MacTavish, Sep 07, 2015, 04:53 PM

Previous topic - Next topic

MacTavish

I know i used a quiet bad way but its easy to learn for newbies must read my comments in the code

/* Hello i am bringing this system for those who need it but ensure that you change every thing in this system that in incompatable with your script such as Database, Messages, Functions like GetLevel */



function onScriptLoad()
{
db <- ConnectSQL("staff.sqlite");
QuerySQL( db, "CREATE TABLE IF NOT EXISTS StaffList ( Name TEXT, Level INT, State TEXT )" );
}

function onPlayerCommand( player, cmd, text
{
if ( cmd == "stafflist" )
{
if ( GetLevel(player) < 2 ) return 0; // Change this if you want
else
{
            local q = QuerySQL(db, "SELECT * FROM StaffList"),a=0;
            if( !GetSQLColumnData( q, 0 ) ) MessagePlayer(">> None Of Staff Member Has Been Added Yet.",player);
            else
            {
            while( GetSQLColumnData( q, 0 ) )
            {
                MessagePlayer(GREY+">> (" + GetSQLColumnData( q, 0 ) + " :: " + GetSQLColumnData( q, 1 ) + " :: " + GetSQLColumnData( q, 2 ) + ")",player ); 
GetSQLNextRow( q );
                a++;
            }   
}
FreeSQLQuery(q);
        }
}
}

checkingstaff( player ); // put this in your login function and autologin function such as AccInfo and in your setlevel command


function checkingstaff( player )
{
if ( GetLevel(player) >= 2 ) // Change It if you aren't using GetLevel Function or change the numeric values
   {
   local sl = QuerySQL( db, "SELECT * FROM StaffList WHERE Name='" + player.Name + "'" );
   if ( GetSQLColumnData( sl, 0 ) == null )
   {
   QuerySQL(db, "INSERT INTO StaffList (Name, Level, State) VALUES ('"+ player.Name +"', '"+ GetLevel(player) +"', '"+ GetLevelTag(player) +"')");
   }
   else
   {
   QuerySQL(db, "UPDATE StaffList SET Level='" + GetLevel(player) + "' WHERE Name='" + player.Name + "'");
   QuerySQL(db, "UPDATE StaffList SET State='" + GetLevelTag(player) + "' WHERE Name='" + player.Name + "'");
   }
FreeSQLQuery(sl);
   }
   else
   {
   QuerySQL(db, "DELETE FROM StaffList WHERE Name='"+player.Name+"'");
   }
}


function GetLevelTag(player) // this function is used for State in Stafflist
{
local lvl = GetLevel(player);
if( lvl == 1 ) return "Member";
if( lvl == 2 ) return "Moderator";
if( lvl == 3 ) return "Admin";
if( lvl == 4 ) return "Head Admin";
if( lvl == 5 ) return "Manager";
if( lvl == 6 ) return "Server Owner";
}

function GetLevel( player ) // dont add it if you have your own
{
   local lvl =  GetSQLColumnData( QuerySQL( db, "SELECT Level FROM Account WHERE Name='" + player.Name + "'" ), 0 );
   if ( lvl ) return lvl;
   else return 0;
   FreeSQLQuery( lvl );
}


checkingstaff updated the index sl doesnt exist fixed., levels updated

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

Nice btw use this, this one is pretty easy
function GetLevelTag(player) // this function is used for State in Stafflist
{
local lvl = GetLevel(player);
switch(lvl)
{
case 1: return "User";
case 2: return "V.I.P";
case 3: return "Moderator";
case 4: return "Admin";
case 5: return "Head Admin";
case 6: return "Owner";
}
}
oh no

FinchDon

error I Add checkingstaff onPlayerDeath when i do /kill console says the index sl does not exist
For any help and support Join #s-s at IRC for Help in Scripting
( For Newbies )

Xmair

Did you added the sl variable?

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

MacTavish

Quote from: FinchDon on Sep 08, 2015, 02:52 PMerror I Add checkingstaff onPlayerDeath when i do /kill console says the index sl does not exist

Seriously onPlayerDeath  :-\

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Mashreq

Good one, will be helpfull for players who really needs this.
Why don't you make a array and check the level's of players instead of selecting the player's level from the database? (for stafflist command and checkingstaff function) :)

MacTavish

But how can we insert an offline admin status to array,

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Mashreq

Quote from: Kusanagi on Sep 08, 2015, 04:22 PMBut how can we insert an offline admin status to array,
The thing which i meant here is about GetLevel function which can be used by a array or a array with a class.

MacTavish

Quote from: Mashreq on Sep 08, 2015, 04:23 PM
Quote from: Kusanagi on Sep 08, 2015, 04:22 PMBut how can we insert an offline admin status to array,
The thing which i meant here is about GetLevel function which can be used by a array or a array with a class.
That function isnt recommended everyone has their own GetLevel, so they can use their own

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

Oh btw using array in his script is converting the whole one
Better one tho:-
function GetLevel( player )
{
return stats[ player.ID ].Level;
//Change it according to your script.
}
oh no

KAKAN

I pointed out 1 bug without even trying it...
AND THE BUG IS:-
You have missed this on onScriptLoad()
db <- ConnectSQL("staff.sqlite");
NOTE: Sorry for spamming
oh no

KAKAN

And yes:-
in the checkinfstaff function
add this:-
if( GetLevel(player) >= 2 )Instead ofif ( GetLevel(player) == 3 || GetLevel(player) == 5 || GetLevel(player) == 7 || GetLevel(player) == 9 || GetLevel(player) == 10 )THIS one is better i guess
oh no

MacTavish

Quote from: KAKAN on Sep 08, 2015, 06:05 PMI pointed out 1 bug without even trying it...
AND THE BUG IS:-
You have missed this on onScriptLoad()
db <- ConnectSQL("staff.sqlite");
NOTE: Sorry for spamming

I recommend to use Global database ( where your other tables are created like accounts ) btw added


Quote from: KAKAN on Sep 08, 2015, 06:11 PMAnd yes:-
in the checkinfstaff function
add this:-
if( GetLevel(player) >= 2 )Instead ofif ( GetLevel(player) == 3 || GetLevel(player) == 5 || GetLevel(player) == 7 || GetLevel(player) == 9 || GetLevel(player) == 10 )THIS one is better i guess

I done this because if by mistake we set someone's level 4 instead 3 then that will not be added in stafflist because he isnt admin but if you use levels like 2,3,4.5,6 then you can do it by yourself

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

Why would you set levels like that. Level 3 is admin, level 4 is not, level 5 is. What kinda sense is that?

MacTavish

Quote from: Thijn on Sep 08, 2015, 07:12 PMWhy would you set levels like that. Level 3 is admin, level 4 is not, level 5 is. What kinda sense is that?

Idk but some members likes the levels like this, is this necessary to discuss just end it here i am gonna change levels in system

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P