Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: KAKAN on Aug 29, 2015, 04:50 PM

Title: Ban system error
Post by: KAKAN on Aug 29, 2015, 04:50 PM
[spoiler="Ban cmd"]    else if ( cmd == "ban" )
    {
       if ( stats[ player.ID ].Level < 4 ) MessagePlayer(">> Error - You don't have access to it.", player);
       else if ( !text ) MessagePlayer(">> Error - Syntax: /ban <player> <reason>", player);
       else
       {
         local plr = GetPlayer( GetTok( text, " ", 1 ) );
         if ( !plr ) MessagePlayer(">> Error - Unknown player.", player);
         else
         {
           local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
           if ( !reason ) reason = "None";
           Ban( plr, player, reason );
         }
       }
    }[/spoiler]
[spoiler="Ban Function"]function Ban( plr, player, reason )
{
    QuerySQL( sqliteDB, "INSERT INTO Bans(Name, IP, UID, Reason, Time, Admin) VALUES('" + plr.Name + "', '" + plr.IP + "', '" + plr.UniqueID + "', '" + reason + "', '" + GetFullTime() + "', '"+player+"')" );
    EMessage( "Admin " + player + " has banned "+plr.Name+" from this server. Reason: " + reason + "." );
    plr.Kick();
}[/spoiler]

The ban system is working perfectly. I use the same function in IRC too

UBAN:-
Its the error, it says "The nick isn't banned....."
[spoiler="Unban cmd"]    else if ( cmd == "unban" )
    {
       if ( stats[ player.ID ].Level < 4 ) MessagePlayer(">> Error - You don't have access to it.", player);
       else if ( !text ) MessagePlayer(">> Error - Syntax: /unban <player name>", player);
       else
       {
         local query = QuerySQL( sqliteDB, "SELECT * FROM Bans WHERE Name='" + text + "'" );
         if( GetSQLColumnData( query, 0 ) )
       {
       Unban( text );
              EMessage(">>  Admin " + player.Name + " has unbanned " + text );
       }
         else MessagePlayer(">> This nick isn't banned. Please type the banned nick.", player );
         FreeSQLQuery( query );
       }
    }[/spoiler]

[spoiler="Unban Function"]function Unban( text )
{
    QuerySQL( sqliteDB, "DELETE FROM Bans WHERE Name='" + text + "'" );
}[/spoiler]
Title: Re: Ban system error
Post by: Thijn on Aug 29, 2015, 05:08 PM
Check your database. Try executing the query manually to see if it actually works.
Title: Re: Ban system error
Post by: KAKAN on Aug 29, 2015, 05:12 PM
Yup tried it, it creates it in database, tried executing it manually still then didn't work
Title: Re: Ban system error
Post by: . on Aug 29, 2015, 05:18 PM
Don't take this as advertising but I really do recommend this SQLite plugin (http://forum.vc-mp.org/?topic=420.0) instead. It's way easier to debug because you get a descriptive error message if something fails in the query. And it's pretty much similar to the official one except the function names are different to avoid conflict.
Title: Re: Ban system error
Post by: KAKAN on Aug 29, 2015, 05:38 PM
I'm never gonna take your posts as advertise, I'm gonna try that SQLite plugin made by you
Title: Re: Ban system error
Post by: KAKAN on Aug 30, 2015, 05:49 PM
Thanks all! its working NOW!