ban timer display

Started by Coolkid, Mar 23, 2016, 10:58 PM

Previous topic - Next topic

Coolkid

hi
   when i ban a player he is banned for right time but problem is it shows negative values as u can see in pictures here is my code
function Banned( player )
{
      local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_nick='" + player.Name + "' COLLATE NOCASE" ), Ip = player.IP.tostring();
   if( GetSQLColumnData( query, 0 )  )
   {
         if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
   {
       local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_nick='" + player.Name.tostring() + "'" );
    FreeSQLQuery( query2 );
       MessagePlayer(GREEN+"[RBAN] Your ban has been expired.", player );
    MessagePlayer(ORANGE+"[RBAN] Stick to the rules or you will get permanently banned.", player );
   }
   else
   {
        local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ) );
        //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
        MessagePlayer(RED+"[RBAN] Your ban has not expired.", player );
     MessagePlayer(ORANGE+"[RBAN] Your ban is set to expire in " + Time_Left, player );
Message(RED+" Enforcing prior ban on:["+player.Name+"] Reason:["+GetSQLColumnData( query, 6 )+"]Time left:["+Time_Left+"]")
EchoMessage(ICOL_RED+" Enforcing prior ban on:["+player.Name+"] Reason:["+GetSQLColumnData( query, 6 )+"]Time left:["+Time_Left+"]")
     KickPlayer( player );
   }
   }
   else if( GetSQLColumnData( QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" ), 0 ) )
   {
         local query = QuerySQL( database, "SELECT * FROM Banned WHERE ban_ip='" + Ip + "'" );
         if( ( time() - GetSQLColumnData( query, 2 ).tointeger() ) >= GetSQLColumnData( query, 3 ).tointeger() )
   {
       local query2 = QuerySQL( database, "DELETE FROM Banned WHERE ban_ip='" + player.IP.tostring() + "'" );
    FreeSQLQuery( query2 );
       MessagePlayer(RED+"[RBAN] Your ban has been expired.", player );
    MessagePlayer(ORANGE+"[RBAN] Stick to the rules or you will get permanently banned.", player );
   }
   else
   {
        local Time_Left = TimeRem( GetSQLColumnData( query, 2 ).tointeger(), GetSQLColumnData( query, 4 ).tostring() );
        //local splitban = split(  GetSQLColumnData( query, 4 ), ":"  ), Calc = splitban[ 0 ] + " Day(s), " + splitban[ 1 ] + " Hour(s), " + splitban[ 2 ] + " Minute(s).";
        MessagePlayer("[RBAN] Your ban has not expired.", player );
     MessagePlayer(ORANGE+"[RBAN] Your ban is set to expire in. " + Time_Left , player );
  Message(RED+" Enforcing prior ban on:["+player.Name+"] Reason:["+GetSQLColumnData( query, 6 )+"]Time left:["+Time_Left+"]")
EchoMessage(ICOL_RED+" Enforcing prior ban on:["+player.Name+"] Reason:["+GetSQLColumnData( query, 6 )+"]Time left:["+Time_Left+"]")
     KickPlayer( player );
   }
   }
   FreeSQLQuery( query );
}
function TimeRem( bantime,  banratio )
{
        local ban_current = time()-bantime, sp = split(banratio,":"), ban_Days = 0, ban_Hours = 0, ban_Minutes = 0,
  ban_Day = sp[ 0 ].tointeger(),
  ban_Hour = sp[ 1 ].tointeger(),
  ban_Minute = sp[ 2 ].tointeger();
  bantime = ban_Day + ban_Hour + ban_Minute;
  ban_Days = ban_current/86400;
  ban_current = ban_current%86400;
  ban_Hours = ban_current/3600;
  ban_current = ban_current%3600;
  ban_Minutes = ban_current/60;
  ban_current = ban_current%60;
  ban_Day -= ban_Days;
  ban_Hour -= ban_Hours;
  ban_Minute -= ban_Minutes;
  return ban_Day + " Day(s), " + ban_Hour + " Hour(s), " + ban_Minute + " Minutes.";
}


Mötley

You need to add more to it i do not understand the scripting language you use but
hear is my input

try {
local BanLST = XmlDocument ( );
BanLST.LoadFile ( "banlist.xml" );

local BanLST = XmlDocument ( );
BanLST.LoadFile ( "banlist.xml" );

local Geo = BanLST.FirstChild ( ).FirstChild ( );

while ( Geo != null ) {

 if ( IP != "0" && Name != "0" ) MessagePlayer ( "IP: " + IP + " - Name: " + Name, player );

 Hopefully you scripted this in rather than a plug-in. what I posted should help you with a concept of fixing the null issue

I did that example as if it was reading from one file that is .xml and correcting the null issues in the name

This has to help you in some way i hope
 

Thijn

Why all those string splitting when you can just check the remaining time using time() - GetSQLColumnData( query, 3 ).tointeger()?
If that column is what it says, atleast.