Author Topic: Help On Scripting  (Read 1166 times)

Hey whats up guys & girls? I'm needing some help on my Chatbot that I'm making.
Note: I'm not going to make those Chatbots that spam up the server, later I'm going to try to make it not repeat Twice.

Whats the problem you say? Well that's just it I can't figure it out, No Syntax Errors or anything.
By the way I think it has something to do with the else function.

Code:

Code: [Select]
package Excella_03_WakeUp
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
        {
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);
                                if (%msg $= "Wake Up E3")
                                    if(%name $= "§gt. ßµïlÐêx")
                                  {
                       
                                       
                            commandToServer('messageSent',"Excella: I'm awake! I'm awake! I was sleeping... -_-");
                                ActivatePackage(Excella_3_0);
                                }

                                if (%msg $= "Shutup E3")
                                    if(%name $= "§gt. ßµïlÐêx")
                                  {
                       
                                       
                            commandToServer('messageSent',"Excella: But? Ah, ok.");
                                DeactivatePackage(Excella_3_0);
                                }
   
                     
                   
        }
};
ActivatePackage(Excella_03_WakeUp);
//Main Package Is Below...
package Excella_03
{
function clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg)
        {
parent::clientCmdChatMessage(%a,%b,%c,%fmsg,%cp,%name,%cs,%msg);

        if (%msg $= "You Awake?")
            if(%name $= "§gt. ßµïlÐêx")
          {
     
                                       
    commandToServer('messageSent',"Excella: Yeah.");
        }
        //NOTE: It Does Not Matter How Many Spaces Or Tabs You Put InBetween, InFront Or Behind It. It's Just A Factor Of It's Easier To Read & It's Cleaner!
       
        if (%msg $= "Hello")
        {
        commandToServer('messageSent',"Hi!");
        }

        if (%msg $= "ClearAllBricks")
            if(%name $= "§gt. ßµïlÐêx")
          {
     
                                       
    commandToServer('messageSent',"Excella: Please Hold.");
        commandToServer('ClearAllBricks');
        commandToServer('messageSent',"Excella: Done!");
       
        }
                else
                {
                commandToServer('messageSent',"Excella: Task Has Failed. Maybe You Don't Have The Right Permissions To Preform This Action?");
                }

        if (%msg $= "ClearSpamBricks")
            if(%name $= "§gt. ßµïlÐêx")
          {
     
                                       
    commandToServer('messageSent',"Excella: Please Hold.");
        commandToServer('ClearSpamBricks');
        commandToServer('messageSent',"Excella: Done!");
       
        }
                 else
                 {
                 commandToServer('messageSent',"Excella: Task Has Failed. Maybe You Don't Have The Right Permissions To Preform This Action?");
                 }

        if (%msg $= "ClearBricks")
            if(%name $= "§gt. ßµïlÐêx")
          {
                                 
    commandToServer('messageSent',"Excella: Please Hold.");
        commandToServer('ClearBricks');
        commandToServer('messageSent',"Excella: Done!");
       
        }
                else
                {
                commandToServer('messageSent',"Excella: Task Has Failed. Maybe You Don't Have The Right Permissions To Preform This Action?");
                }
        if (%msg $= "ClearFloatingBricks")
            if(%name $= "§gt. ßµïlÐêx")
          {
     
                                       
    commandToServer('messageSent',"Excella: Please Hold.");
        commandToServer('ClearFloatingBricks');
        commandToServer('messageSent',"Excella: Done!");
       
        }
                else
                {
                commandToServer('messageSent',"Excella: Task Has Failed. Maybe You Don't Have The Right Permissions To Preform This Action?");
                }
        }
};
ActivatePackage(Excella_03);

if (!$Excella_03Bindings)
{
 $remapDivision[$remapCount] = "Excella_03";
 $remapName[$remapCount] = "Activate/Deacticate";
 $remapCmd[$remapCount] = "Excella_03Toggle";
 $remapCount++;
 $Excella_03Bindings=true;
}

$Excella_03Flag=0;
function Excella_03Toggle(%notdepressed)
{
 if (!%notdepressed) return;
 if($Excella_03Flag==0)
 {
  $Excella_03Flag=1;
  deactivatePackage(Excella_03);
 } else
 if($Excella_03Flag==1)
 {
  activatePackage(Excella_03);
  $Excella_03Flag=0;
  exec("Add-ons/Client_Excella_03/Client.cs");
  echo("Shhhh. This is a secret message: Why The Hell Did You Wake Me?!");
 
 }
}

Thanks!

No one likes chatbots... Except mabey you.

It's difficult to tell what's going on because your formatting is bad. Here's an example of some better formatting:

Code: [Select]
function SlayerClient_TCP::onLine(%this, %line)
{
SlayerClient_Support::Debug(2, %this SPC "line received", %line);

if(%this.receiveData)
{
if(strPos(%this.headerField["Content-Type"], "text") == 0)
{
if(strLen(%line) < 2 || getSubStr(%line, 0, 2) !$= "//")
{
%this.handleLine(%line);
}
}
else
{
%this.setBinarySize(%this.headerField["Content-Length"]);
}
}
else
{
//snip
}
}

Use tabs for indentation.

No one likes chatbots... Except mabey you.

Lots of people use them to learn.

Thank you for the formatting tips, and also yes this is purely for my learning skills... The chatbot will later be used as a base to make a ServerBot that does everything from Help User on How to play the game to Automatically resetting the server & things like that.

What is going on is When I type like ClearAllBricks it clears my servers bricks which it's suppose to, but if I'm on another server & I don't have the right permissions I want it to say Sorry, you don't have the right permissions.

Later I might re-submit this with a better format that you gave me!

TorqueDev has a somewhat auto formatting thing. Try using that.

TorqueDev has a somewhat auto formatting thing. Try using that.
Don't you have to pay for that?
I Use Microsoft Visual Studio 2013 Ultimate.

If you're only allowing yourself to use the chatbot, use NMH_Type::Send instead of clientCmdChatMessage
Also use switches instead of a ton of if/else

Code: [Select]
package example
{
    function NMH_Type::send(%this)
    {
        %value = %this.getValue();
        
        switch$(%value)
        {
            case "hi":
                %response = "hello";
            case "bye":
                %response = "goodbye";
            case "cheese":
                %response = "cheddar";
        }
        commandtoserver('messagesent',%response);
        parent::send(%this);
    }
};

activatePackage(example);


Also I feel like dynamically reactivating/deactivating packages may be a bad idea, set and check a global variable instead


What is going on is When I type like ClearAllBricks it clears my servers bricks which it's suppose to, but if I'm on another server & I don't have the right permissions I want it to say Sorry, you don't have the right permissions.
There's a global variable you can check, I believe it's $iamadmin
If true, clear, if false, say you don't have permissions.
« Last Edit: February 07, 2014, 11:40:59 PM by Headcrab Zombie »

Don't you have to pay for that?
I Use Microsoft Visual Studio 2013 Ultimate.
Visual Studio is not an environment in which you are supposed to write Torque code. It'll work as a text editor, but it shouldn't provide much if any extra functionality, it'd actually probably try to tell you 99% of your code has improper syntax.

I'd recommend using a different text editor. Notepad works just fine, but if you like fancy features Sublime Text is my favorite bloated editor. TorqueDev is meant specifically for Torque, so if you want that extra feature set go with that. I personally use vim, but don't bother with that.

Don't you have to pay for that?
I Use Microsoft Visual Studio 2013 Ultimate.
TorqueDev is free, always has been.

Visual Studio is meant for .NET language development, and although Torque has quite a few syntactical similarities to C#, the two are nothing close to the same and as Trinick said the only real thing you're going to get out of it is VS saying you have a million syntax errors.

I suggest using Notepad++ with auto-indent and torque highlighting (which can be found in the coding resources megathread), TorqueDev (which is also in the resources thread), or Sublime Text, which is also free and has a package for torque syntax hilighting.

Another tip, Please Do Not Type Like This, It Is Incredibly Painful To Read.

TorqueDev is also quite similar to Visual Studio in the sense that it has live syntax error checking, and also has the Torquescript equivalent of Intellisense, which is quite useful. So if you can, I'd recommend getting and using that.


Is it possible the error occurs due to the loving crazy name?
Try using %client.bl_id instead of %client.name.

Thank you for the formatting tips, and also yes this is purely for my learning skills... The chatbot will later be used as a base to make a ServerBot that does everything from Help User on How to play the game to Automatically resetting the server & things like that.

What is going on is When I type like ClearAllBricks it clears my servers bricks which it's suppose to, but if I'm on another server & I don't have the right permissions I want it to say Sorry, you don't have the right permissions.

Later I might re-submit this with a better format that you gave me!
Can could also make a script that detects keywords eg "help" or "admin" by editing the servercmdmessagesent function