Author Topic: Comparing strings from a file?  (Read 1192 times)

How would you do this? I am trying to see if someone's BL ID matches the text in the file, and if so, display a message.
I tried this:

Code: [Select]
function dostuff()
{
    %client.isThis = false;
    %blid = %client.bl_id;
    %fo = new FileObject();
    %path = "Add-Ons/Script_Stuff/stuff.txt";
    %fo.openForRead(%path)
    %line = %fo.readLine();
    if(!isFile(%path)
    {
        error("Stuff does not exist!");
        echo("Creating stuff...");
        %fo.openForWrite(%path);
        %fo.close();
    }
    else if(getWord(getSubStr(%line)) $="")
    {
        $BLIDcheck = false;
    }
    else if(getWord(getSubStr(%line)) $="%blid")
    {
        %client.isThis = true;
        messageAll('MsgAdminForce', "\c6" @ %client.getPlayerName @ "\c6 is a this!");
        $BLIDcheck = true;
    }
}

I don't get any syntax errors or anything, but am I doing the
Code: [Select]
getWord(getSubStr(%line)) $=""stuff correctly? Or is this wrong and there's a better way of doing it?
« Last Edit: March 17, 2014, 06:54:04 PM by Ninjaman 4 »

getWord(%string, %index)
getSubString(%string, %startIndex, %length)

You're using both functions wrong.

You're also missing semicolons and closing parenthesis, which means there are syntax errors. This script will not run.

OK. So how would I compare the blid inside the text file to someone that joins the server?


OK. So how would I compare the blid inside the text file to someone that joins the server?


package YourPackage
{
   function GameConnection::AutoAdminCheck(%this)
   {
      AddBLIDMatch(%this.getBLID());
      return Parent::AutoAdminCheck(%this);
   }
};
activatePackage(YourPackage);

function CheckBLIDMATCH(%ID)
{
   %ID = mFloor(%ID);
   %file = new FileObject();
   %file.openForRead("config/server/Blockland IDs.cs");
   %line = %file.readLine();
   for(%i=0;%i<getWordCount(%line);%i++)
      if(getWord(%line,%i) == %ID)
         return true;
      else
         return false;
   %file.close();
   %file.delete();
}

function AddBLIDMatch(%ID)
{
   %ID = mFloor(%ID);
   %fileA = new FileObject();
   %fileA.openForRead("config/server/Blockland IDs.cs");
   %lineA = %fileA.readLine();
   %fileA.close();
   %fileA.delete();

   %file = new FileObject();
   %file.openForWrite("config/server/Blockland IDs.cs");
   %file.writeLine(%lineA SPC %ID);
   %file.close();
   %file.delete();
}


When people connect, it automatically adds the ID.

AddBLIDMatch will check if an id exists in the database.
« Last Edit: March 18, 2014, 11:03:30 PM by Advanced Bot »


package YourPackage
{
   function GameConnection::AutoAdminCheck(%this)
   {
      schedule(0,0,AddBLIDMatch(%this.getBLID()));
      return Parent::AutoAdminCheck(%this);
   }
};
activatePackage(YourPackage);

function CheckBLIDMATCH(%ID)
{
   %ID = mFloor(%ID);
   %file = new FileObject();
   %file.openForRead("config/server/Blockland IDs.cs");
   %line = %file.readLine();
   for(%i=0;%i<getWordCount(%line);%i++)
      if(getWord(%line,%i) == %ID)
         return true;
      else
         return false;
   %file.close();
   %file.delete();
}

function AddBLIDMatch(%ID)
{
   %ID = mFloor(%ID);
   %fileA = new FileObject();
   %fileA.openForRead("config/server/Blockland IDs.cs");
   %lineA = %fileA.readLine();
   %fileA.close();
   %fileA.delete();

   %file = new FileObject();
   %file.openForWrite("config/server/Blockland IDs.cs");
   %file.writeLine(%lineA SPC %ID);
   %file.close();
   %file.delete();
}


When people connect, it automatically adds the ID.

AddBLIDMatch will check if an id exists in the database.

Why are you using a schedule when you can send the data after the parent and still return what you need to return..

Why are you using a schedule when you can send the data after the parent and still return what you need to return..

Not to mention that he's using schedules entirely wrong.

Not to mention that he's using schedules entirely wrong.
Oops.

Why are you using a schedule when you can send the data after the parent and still return what you need to return..
Ah.

Not to mention that the client's BLID is already set by the time autoAdminCheck is called; there's no need for the schedule at all.