Error

Started by Cool, Apr 28, 2016, 03:18 PM

Previous topic - Next topic

Cool

error is tostring does not exists note: this all one function
function FindPlayerClan( player, string )
{
        string = string;
        q <- QuerySQL( sqliteDB, "SELECT * FROM ClanUsers WHERE Clans='" + GetTag( string ) + "' COLLATE NOCASE" );
       DBName <- GetSQLColumnData( q, 1 ).tostring();  error line
        TCC <- TruncateClan;
              if ( DBName.tolower().find( TCC( string.tolower() ) ) ) { PrivMessage( "Your Nick " + TCC( string ) + ", Clan: " + GetTag( string ), player ); } else { ClanKick( player ); return null; }
}

KAKAN

What if the column data is null?
oh no

kennedyarz


Cool

i goted where is problem its try to kick the the player because he doesnt in his clan but it does not kick it thats why to string error
here please fix function FindPlayerClan( player, string )
{
        string = string;
        q <- QuerySQL( sqliteDB, "SELECT * FROM ClanUsers WHERE Clans='" + GetTag( string ) + "' COLLATE NOCASE" );
         DBName <- GetSQLColumnData( q, 1 ).tostring();
        TCC <- TruncateClan;
              if ( DBName.tolower().find( TCC( string.tolower() ) ) ) { MessagePlayer( "Your Nick " + TCC( string ) + ", Clan: " + GetTag( string ), player ); } else { ClanKick( player ); return null; }
}

function ClanKick( player )
{
MessagePlayer( "Note: You Clan is here but you don't register by any manager in database bye! :(", player ), NewTimer( "KickPlayer", 2000, 1, player );
}

KAKAN

function ClanKick( player )
{
MessagePlayer( "Note: You Clan is here but you don't register by any manager in database bye! :(", player );
NewTimer( "KickPlayer", 2000, 1, player.ID );
}
function KickPlayer( pID ){
local p = FindPlayer( pID );
if( p ) p.Kick();
else return null;
}
Use this 2 functions.
oh no

Cool

not giving kick

KAKAN

Quote from: Hercules on Apr 29, 2016, 08:36 AMnot giving kick
Did you remove the old Kick function?
If not, then try this:
function ClanKick( player )
{
MessagePlayer( "Note: You Clan is here but you don't register by any manager in database bye! :(", player );
player.Kick();
Message("Keeked!");
}
oh no

Cool

take a look that function may its have prblem your give function not workedfunction onScriptLoad()
{

      sqliteDB<- ConnectSQL( "database.db" );
   }

function onServerStart()
{
     CreateTables();
}


function onPlayerJoin( player )
{

        Msg <- MessagePlayer; Clan <- GetTag( player.Name );

        ( Clan && Clan.len() <= 6 ) ? Msg( "Hey Welcome " + TruncateClan( player.Name ) + " to the clanstats script!", player ) : Msg( "Hey Welcome " + player.Name + " to the clanstats script!", player );
        if ( !Clan ) Msg( "Hey Welcome " + player.Name + " to the clanstats script!", player ), Msg( "Oh no you no have clan :(!", player );

        if ( Clan.len() <= 4 && !IsClanRegister( Clan.tolower() ) ) Msg( "Note: You have clan \"" + Clan + "\" you can add using, !regclan", player );
        else { if ( Clan.len() >= 5 ) Msg( "Note: Can't register your clan \"" + Clan + "\" is invalid :(!", player ); }
       
        if ( Clan && IsClanRegister( Clan.tolower() ) ) Msg( "Note: You clan \"" + Clan + "\" is in server :D!", player ), FindPlayerClan( player, player.Name );
}

function FindPlayerClan( player, string )
{
        string = string;
        q <- QuerySQL( sqliteDB, "SELECT * FROM ClanUsers WHERE Clans='" + GetTag( string ) + "' COLLATE NOCASE" );
         DBName <- GetSQLColumnData( q, 1 ).tostring();
        TCC <- TruncateClan;
              if ( DBName.tolower().find( TCC( string.tolower() ) ) ) { MessagePlayer( "Your Nick " + TCC( string ) + ", Clan: " + GetTag( string ), player ); } else { ClanKick( player ); return null; }
}

function ClanKick( player )
{
MessagePlayer( "Note: You Clan is here but you don't register by any manager in database bye! :(", player ), NewTimer( "KickPlayer", 2000, 1, player );
}

function onPlayerChat( player, text )
{

if ( text )
{
    if ( text.slice( 0, 1 ) == "!" )
    {
                local i = split( text.slice( 1 ), " " );
    if ( i.len() == 1 ) Commands( player, i[ 0 ], null );
    else Commands( player, i[ 0 ], text.slice( 1 ).slice( text.slice( 1 ).find( " " ) + 1 ) );
    }
        }
}



function CreateTables()
{
    QuerySQL( sqliteDB, "CREATE TABLE IF NOT EXISTS ClanStats ( Clan TEXT, Kills NUMERIC DEFAULT 0, Deaths NUMERIC DEFAULT 0, Deads NUMERIC DEFAULT 0, Leaders TEXT )" );
    QuerySQL( sqliteDB, "CREATE TABLE IF NOT EXISTS ClanUsers ( Clans TEXT, Users TEXT  )" );

}

function onPlayerKill( killer, player, weapon, bodypart )
{
      local KClan = GetTag( killer.Name ), DClan = GetTag( player.Name );

      if ( killer && player )
      {
                 if ( KClan && IsClanRegister( KClan ).tolower() ) { IncTagKills( KClan ); }

                 if ( DClan && IsClanRegister( DClan ).tolower() ) { IncTagDeaths( DClan ); }
      }         
}

function onPlayerDeath( player, reason )
{
try{
      if ( player )
      {
                  local Tag = GetTag( player.Name );

                  if ( Tag && IsClanRegister( Tag ).tolower() ) IncTagDeads( Tag );
      }
   } catch( e ) print( "onPlayerDeath Error: " + e );
}



//-----Clan-Stats System -----
function GetTag(strPlayer)
{

local
     D_DELIM = regexp(@"([\[(=^<]+\w+[\])=^>]+)").capture(strPlayer),
             S_DELIM = regexp(@"(\w.+[.*=]+)").capture(strPlayer);

if ( D_DELIM != null )
{
return strPlayer.slice( D_DELIM[ 0 ].begin + 1, D_DELIM[ 0 ].end - 1 );
}
else if ( S_DELIM != null )
{
return strPlayer.slice( S_DELIM[ 0 ].begin, S_DELIM[ 0 ].end - 1 );
}
}

function RegisteredClans()
{
        local a = 0, q = ::QuerySQL( sqliteDB, "SELECT * FROM ClanStats" );
        while ( ::GetSQLColumnData( q, 0 ) )
        {
                a ++;
                GetSQLNextRow( q );
        }
        return a;
FreeSQLQuery( q );
}


function IsClanRegister( clan )
{
        local Result = ::QuerySQL( sqliteDB, "SELECT Clan FROM ClanStats WHERE Clan='" + clan + "' COLLATE NOCASE" );
        local Reg = ::GetSQLColumnData( Result, 0 ); 
        return (Reg) ? Reg : null;
FreeSQLQuery( Result );
}

function IsClanManager( clan )
{

                local q = QuerySQL( sqliteDB, "SELECT Leaders FROM ClanStats WHERE Clan='" + GetTag( clan ).tolower() + "' COLLATE NOCASE" );
                local Leader = GetSQLColumnData( q, 0 );
                FreeSQLQuery( q );
if ( Leader )
{
local param = split( Leader, ", " );

                          if ( param[ 0 ].tolower() == clan )
                          {
                      local ResultFirst = TruncateClan( param[ 0 ].tolower() );
                                  Result <- ResultFirst == TruncateClan( clan );
                        if ( !Result ) return null;
                  else return Result.tointeger();
                          }
                          if ( param[ 1 ].tolower() == clan )
                          {
                      local ResultSec = TruncateClan( param[ 1 ].tolower() );
                                  Result <- ResultSec == TruncateClan( clan );
                        if ( !Result ) return null;
                  else return Result.tointeger();
                          }
                          if ( param[ 2 ].tolower() == clan )
                          {
                      local ResultTree = TruncateClan( param[ 2 ].tolower() );
                                  Result <- ResultTree == TruncateClan( clan );
                        if ( !Result ) return null;
                  else return Result.tointeger();
                          }
                 }
}

function RegisterClan( Clan )
{
QuerySQL( sqliteDB, "BEGIN TRANSACTION" );
        QuerySQL( sqliteDB, format( "REPLACE INTO ClanStats (Clan) VALUES ('%s')", Clan ) );
        QuerySQL( sqliteDB, format( "REPLACE INTO ClanUsers (Clans) VALUES ('%s')", Clan ) );
QuerySQL( sqliteDB, "END TRANSACTION" );
}

function ClanKills( Clan )
{
        if ( Clan != null )
        {
                local Result = ::QuerySQL( sqliteDB, "SELECT Kills FROM ClanStats WHERE Clan='" + Clan + "' COLLATE NOCASE" );
                local Kills = ::GetSQLColumnData( Result, 0 );
                if ( !Kills ) return 0;
        else return Kills.tointeger();
FreeSQLQuery( Result );
        }
        else return null;
}

function ClanDeaths( Clan )
{
        if ( Clan != null )
        {
                local Result = ::QuerySQL( sqliteDB, "SELECT Deaths FROM ClanStats WHERE Clan='" + Clan + "' COLLATE NOCASE" );
                local Deaths = ::GetSQLColumnData( Result, 0 );
                if ( !Deaths ) return 0;
        else return Deaths.tointeger();
FreeSQLQuery( Result );
        }
        else return null;
}

function ClanDeads( Clan )
{
        if ( Clan != null )
        {
                local Result = ::QuerySQL( sqliteDB, "SELECT Deads FROM ClanStats WHERE Clan='" + Clan + "' COLLATE NOCASE" );
                local Deads = ::GetSQLColumnData( Result, 0 );
                if ( !Deads ) return 0;
        else return Deads.tointeger();
FreeSQLQuery( Result );
        }
        else return null;
}

function IncTagKills( Clan )
{
                        local UP = ClanKills( Clan ) + 1;
                        local query1 = format( "UPDATE ClanStats SET Kills=%i WHERE Clan='" + Clan + "' COLLATE NOCASE", UP );
                        ::QuerySQL( sqliteDB, query1 );
}

function IncTagDeaths( Clan )
{
                        local DOWN = ClanDeaths( Clan ) + 1;
                        local query1 = format( "UPDATE ClanStats SET Deaths=%i WHERE Clan='" + Clan + "' COLLATE NOCASE", DOWN );
                        ::QuerySQL( sqliteDB, query1 );
}

function IncTagDeads( Clan )
{

                        local DOWN = ClanDeads( Clan ) + 1;
                        local query1 = format( "UPDATE ClanStats SET Deads=%i WHERE Clan='" + Clan + "' COLLATE NOCASE", DOWN );
                        ::QuerySQL( sqliteDB, query1 );
}

function GetPlayer( target )
{
target = target.tostring();

if ( IsNum( target ) )
{
target = target.tointeger();

if ( FindPlayer( target ) ) return FindPlayer( target );
else return null;
}
else if ( FindPlayer( target ) ) return FindPlayer( target );
else return null;
}

function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
  tokenized = split(string, separator),
  text = "";

if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}

function NumTok(string, separator)
{
local tokenized = split(string, separator);
return tokenized.len();
}

//-- Ratio --
function GetRatio( k, d, de )
{
local r;
if ((k>0)&&(d>0)) r = format("%.2f",k/(d+de));
return r;
}

function TruncateClan(strPlayer)
{

local
     D_DELIM = regexp(@"([\[(=^<]+\w+[\])=^>]+)").capture(strPlayer),
             S_DELIM = regexp(@"(\w.+[.*=]+)").capture(strPlayer);

if ( D_DELIM != null )
{

                                 // --- 2 letters in tag
                                 if ( GetTag( strPlayer ).len() == 2 )
                 { return strPlayer.slice( D_DELIM[ 0 ].begin + 4, D_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }



                                 // --- 3 letters in tag
                                 else if ( GetTag( strPlayer ).len() == 3 )
                 { return strPlayer.slice( D_DELIM[ 0 ].begin + 5, D_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


                                 // --- 4 letters in tag
                                 else if ( GetTag( strPlayer ).len() == 4 )
                 { return strPlayer.slice( D_DELIM[ 0 ].begin + 6, D_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


                                 // --- 5 letters in tag no found for valid
                                 else if ( GetTag( strPlayer ).len() == 5 )
                 { return strPlayer.slice( D_DELIM[ 0 ].begin + 7, D_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


                                 // --- 6 letters in tag no found for valid
                                 else if ( GetTag( strPlayer ).len() == 6 )
                 { return strPlayer.slice( D_DELIM[ 0 ].begin + 8, D_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


}
else if ( S_DELIM != null )
{
                                                 // --- 2 letters in tag
                                 if ( GetTag( strPlayer ).len() == 2 )

                { return strPlayer.slice( S_DELIM[ 0 ].begin + 3, S_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }



                                                  // --- 3 letters in tag
                                  else if ( GetTag( strPlayer ).len() == 3 )
                { return strPlayer.slice( S_DELIM[ 0 ].begin + 4, S_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }



                                                  // --- 4 letters in tag
                                  else if ( GetTag( strPlayer ).len() == 4 )
                { return strPlayer.slice( S_DELIM[ 0 ].begin + 5, S_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


                                                  // --- 5 letters in tag no found for valid
                                  else if ( GetTag( strPlayer ).len() == 5 )
                { return strPlayer.slice( S_DELIM[ 0 ].begin + 6, S_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


                                                  // --- 6 letters in tag no found for valid
                                  else if ( GetTag( strPlayer ).len() == 6 )
                { return strPlayer.slice( S_DELIM[ 0 ].begin + 7, S_DELIM[ 0 ].end + strPlayer.len() - FindClanTag(strPlayer).len() ); }


}
}

function FindClanTag(strPlayer)
{

local
     D_DELIM = regexp(@"([\[(=^<]+\w+[\])=^>]+)").capture(strPlayer),
             S_DELIM = regexp(@"(\w.+[.*=]+)").capture(strPlayer);

if ( D_DELIM != null )
{
return strPlayer.slice( D_DELIM[ 0 ].begin, D_DELIM[ 0 ].end );
}
else if ( S_DELIM != null )
{
return strPlayer.slice( S_DELIM[ 0 ].begin, S_DELIM[ 0 ].end );
}
}

KAKAN

I'm done with your script.
Note: You can't pass instances,classes,functions etc using a timer.
oh no

Cool

can you tell me what i do please

KAKAN

Quote from: Hercules on Apr 29, 2016, 10:02 AMcan you tell me what i do please
Use player.ID as the parameter and use FindPlayer inside the function to get the player instance.
For ex:
Replace this code:
function Me( player ){
player.Kick();
}
function onPlayerJoin( player ) NewTimer("Me",1000,1,player);
with this new one, and it'll work:
function Me( playerID ){
local player = FindPlayer( playerID );
if( player ) player.Kick();
}
function onPlayerJoin( player ) NewTimer("Me",1000,1,player.ID);
oh no

Cool

SOLVED
Thanks @KAKAN  thank you very much
really best scripter and using it for helping people its good