Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: MacTavish on Sep 07, 2015, 04:53 PM

Title: Stafflist System
Post by: MacTavish on Sep 07, 2015, 04:53 PM
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
Title: Re: Stafflist System
Post by: KAKAN on Sep 07, 2015, 05:31 PM
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";
}
}
Title: Re: Stafflist System
Post by: FinchDon on Sep 08, 2015, 02:52 PM
error I Add checkingstaff onPlayerDeath when i do /kill console says the index sl does not exist
Title: Re: Stafflist System
Post by: Xmair on Sep 08, 2015, 04:05 PM
Did you added the sl variable?
Title: Re: Stafflist System
Post by: MacTavish on Sep 08, 2015, 04:12 PM
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  :-\
Title: Re: Stafflist System
Post by: Mashreq on Sep 08, 2015, 04:19 PM
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) :)
Title: Re: Stafflist System
Post by: MacTavish on Sep 08, 2015, 04:22 PM
But how can we insert an offline admin status to array,
Title: Re: Stafflist System
Post by: 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.
Title: Re: Stafflist System
Post by: MacTavish on Sep 08, 2015, 04:39 PM
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
Title: Re: Stafflist System
Post by: KAKAN on Sep 08, 2015, 06:02 PM
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.
}
Title: Re: Stafflist System
Post by: KAKAN on Sep 08, 2015, 06:05 PM
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
Title: Re: Stafflist System
Post by: KAKAN on Sep 08, 2015, 06:11 PM
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
Title: Re: Stafflist System
Post by: MacTavish on Sep 08, 2015, 06:20 PM
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
Title: Re: Stafflist System
Post by: Thijn on Sep 08, 2015, 07:12 PM
Why would you set levels like that. Level 3 is admin, level 4 is not, level 5 is. What kinda sense is that?
Title: Re: Stafflist System
Post by: MacTavish on Sep 08, 2015, 07:55 PM
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
Title: Re: Stafflist System
Post by: FinchDon on Sep 09, 2015, 01:57 AM
So Where i add that???? it always say sl does not exist
Title: Re: Stafflist System
Post by: Thijn on Sep 09, 2015, 05:30 AM
Post the full error. Including locals.
Title: Re: Stafflist System
Post by: KAKAN on Sep 09, 2015, 08:31 AM
Quote from: Kusanagi on Sep 08, 2015, 06:20 PM
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

I too, but what about a blank script
Title: Re: Stafflist System
Post by: FinchDon on Sep 09, 2015, 11:07 AM
Thanks Fixed
Title: Re: Stafflist System
Post by: Wolf on Oct 03, 2015, 03:45 PM
What a Superb function i like this @kusanagi
Title: Re: Stafflist System
Post by: Thijn on Oct 03, 2015, 03:53 PM
Quote from: Wolf on Oct 03, 2015, 03:45 PMWhat a Superb function i like this @kusanagi
Stop bumping old topics to say thanks. There's a Like button for a reason...
Title: Re: Stafflist System
Post by: Wolf on Oct 03, 2015, 03:54 PM
Which
Title: Re: Stafflist System
Post by: Thijn on Oct 03, 2015, 03:56 PM
Quote from: Wolf on Oct 03, 2015, 03:54 PMWhich
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi0.kym-cdn.com%2Fphotos%2Fimages%2Fnewsfeed%2F000%2F173%2F576%2FWat8.jpg%3F1315930535&hash=6d43be9c940111ec2e6e00876606f99fb71ef0f5)
Title: Re: Stafflist System
Post by: Wolf on Oct 03, 2015, 04:14 PM
LoL @Thijn
Title: Re: Stafflist System
Post by: Stuart Eldin on Oct 04, 2015, 01:49 AM
@Thijn So Once Again Day is Same Thanks to Wolf for bump
Title: Re: Stafflist System
Post by: Wolf on Oct 04, 2015, 03:15 AM
We know @Stuart Eldin that you are @FinchDon  so anyone can't believe  you.
Title: Re: Stafflist System
Post by: KAKAN on Oct 04, 2015, 04:28 AM
You both make no sense for real!
Title: Re: Stafflist System
Post by: Stuart Eldin on Oct 04, 2015, 07:55 AM
OK Wolf I am Finch So What the fuck you can do? Ah?
Title: Re: Stafflist System
Post by: MacTavish on Oct 05, 2015, 09:28 AM
Locked