Author Topic: Greet Bot (Modifying)  (Read 1908 times)

I'm trying to improve the GreetBot, but I'm having trouble.
Appears I have some syntax errors.
Code: [Select]
package niceToGreetYou
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "Destiny connected." into "Destiny"
%nameToGreet = strReplace(%text," connected.","");
//If the %nameToGreet variable is different to the original line greet them,
//otherwise it's something else
if(%nameToGreet !$= %text)
{
//Send a chat message saying hi to the player who joined (%nameToGreet)
%name = getWord(%msg,1);
%Greet[1] = Hey,;
%Greet[2] = Hello,;
%Greet[3] = Watsup,;
%Choose = %Greet[getRandom(1,3)];
schedule(1000,0,commandToServer,'messageSent',""@%Choose@" "@%nameToGreet@"");
}
}
};
activatePackage(niceToGreetYou);

package OnOff
{
    function NMH_type::Send(%this)
    {
        %msg = %this.getValue();
        parent::Send(%this);
        if($On)
        {
            if(strPos(%msg,"^GreetBotOff") $= 0)
            {
                schedule(1000,0,clientCmdServerMessage,'messageSent',"GreetBot is now on.");
                $On = 0;
            }
        }
        else
        {
            if(strPos(%msg,"^GreetBotOn") $= 0)
            {
                schedule(1000,0,clientCmdServerMessage,'',"GreetBot is now off.");
                $On = 1;
            }
        }
    }
};
activatePackage(OnOff);


I'd also like to make it only greet the people you have
build trust or full trust with. First, I want to get the syntax error/errors
out of the way.
« Last Edit: December 02, 2012, 12:24:37 PM by NAT3 »

Could you run and execute the script, then post the syntax error message?

Code: [Select]
Try this. It comes bonus with your trust list checker. If it doesn't work, post a console.log.
package niceToGreetYou
{
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "Destiny connected." into "Destiny"
%nameToGreet = strReplace(%text," connected.","");
//If the %nameToGreet variable is different to the original line greet them,
//otherwise it's something else
                %FO = new FileObject();
                %FO.openForRead("config/client/prefs-trustList.txt");
                while(!%FO.isEOF())
                {
                   %line = %file.readLine();
                   if(getWord(%line, 2) $= %nameToGreet)
                   {
                if(%nameToGreet !$= %text && $On)
                {
                //Send a chat message saying hi to the player who joined (%nameToGreet)
                %name = getWord(%msg,1);
                %Greet[1] = "Hey," @ %nameToGreet;
                %Greet[2] = "Hello," @ %nameToGreet;
                %Greet[3] = "Watsup," @ %nameToGreet;
                commandToServer('messageSent', %Greet[getRandom(1,3)]);
                }
                   }
                   else
                   {
                      continue;
                   }
                }
                %FO.close();
                %FO.delete();
    }

};
activatePackage(niceToGreetYou);

function toggleGreet()
{
   if($On)
   {
      $On = false;
   }
   else if(!$On)
   {
      $On = true;
   }
}
$remapDivision[$remapCount] = "Greet";
$remapName[$remapCount] = "On / Off";
$remapCmd[$remapCount] = "toggleGreet";
$remapCount++;

The main things that you messed up on were things like putting text out of quotes, and your schedule function.

Also sorry for my terrible formatting because I scripted on the reply box.
« Last Edit: December 02, 2012, 02:40:28 PM by Pacnet2012³ »

Code: [Select]

        function sendGreet()
        {
           commandToServer('messageSent', %Choose);
        }
And where dose %choose come from?

And where dose %choose come from?

%Choose = %Greet[getRandom(1,3)];

%Choose = %Greet[getRandom(1,3)];
but that's never defined within the sendgreet function

but that's never defined within the sendgreet function
Oops, I changed it to a global variable now.


Why do you need a function that does nothing but call one function?
Cut out the middle and just have the schedule call commandtoserver.
In fact, why is the schedule even necessary?

Why do you need a function that does nothing but call one function?
Cut out the middle and just have the schedule call commandtoserver.
In fact, why is the schedule even necessary?
Good point, I don't know why I didn't just remove the schedule from his original code.

Or you could use
secureclientcmd_clientjoin

Code: [Select]
Try this. It comes bonus with your trust list checker. If it doesn't work, post a console.log.
package niceToGreetYou
{
        ## <<SAYS ERROR IS HERE
        ##
function newChatHud_addLine(%text)
{
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "Destiny connected." into "Destiny"
%nameToGreet = strReplace(%text," connected.","");
//If the %nameToGreet variable is different to the original line greet them,
//otherwise it's something else
                %FO = new FileObject();
                %FO.openForRead("config/client/prefs-trustList.txt");
                while(!%FO.isEOF())
                {
                   %line = %file.readLine();
                   if(getWord(%line, 2) $= %nameToGreet)
                   {
                if(%nameToGreet !$= %text && $On)
                {
                //Send a chat message saying hi to the player who joined (%nameToGreet)
                %name = getWord(%msg,1);
                %Greet[1] = "Hey," @ %nameToGreet;
                %Greet[2] = "Hello," @ %nameToGreet;
                %Greet[3] = "Watsup," @ %nameToGreet;
                commandToServer('messageSent', %Greet[getRandom(1,3)]);
                }
                   }
                   else
                   {
                      continue;
                   }
                }
                %FO.close();
                %FO.delete();
    }

};
activatePackage(niceToGreetYou);

function toggleGreet()
{
   if($On)
   {
      $On = false;
   }
   else if(!$On)
   {
      $On = true;
   }
}
$remapDivision[$remapCount] = "Greet";
$remapName[$remapCount] = "On / Off";
$remapCmd[$remapCount] = "toggleGreet";
$remapCount++;

The main things that you messed up on were things like putting text out of quotes, and your schedule function.

Also sorry for my terrible formatting because I scripted on the reply box.
Did not work. Has a syntax error.
« Last Edit: December 02, 2012, 05:16:42 PM by NAT3 »

Delete the "Try this...." part at the beginning