Author Topic: Toggling A Mod  (Read 3711 times)

-code-

logic errors, misplaced brackets, unnecessary semicolons. see if it works.
Still not working
Code: [Select]
        $remapDivision[$remapCount] = "Chatbot";
        $remapName[$remapCount] = "Toggle Auto Greeter";
        $remapCmd[$remapCount] = "ToggleGreet";
        $remapCount++;

package AutoGreeter
{
function newChatHud_addLine(%text)
{
if($canGreet == 1)
{   
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%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)
commandtoserver('messagesent',"Hi, " @ %nameToGreet);
        }
}
}
};
activatePackage(AutoGreeter);

function ToggleGreet()
if($canGreet == 1) {
$canGreet = 0;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: Off.");

} else if($canGreet == 0) {
$cangreet = 1;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: On.");
}
}

Still not working
Code: [Select]
       $remapDivision[$remapCount] = "Chatbot";
        $remapName[$remapCount] = "Toggle Auto Greeter";
        $remapCmd[$remapCount] = "ToggleGreet";
        $remapCount++;

package AutoGreeter
{
function newChatHud_addLine(%text)
{
if($canGreet == 1)
{  
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%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)
commandtoserver('messagesent',"Hi, " @ %nameToGreet);
        }
}
}
};
activatePackage(AutoGreeter);

function ToggleGreet()
if($canGreet == 1) {
$canGreet = 0;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: Off.");

} else if($canGreet == 0) {
$cangreet = 1;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: On.");
}
}

Jesus, your formatting. Each bracket should have its own line, like so:


function code(%arg)
{
     if(%arg)
     {
          //code
     }
}


Now look at the function you have, togglegreet. It is missing an opening bracket; this isn't Python.
« Last Edit: September 04, 2011, 08:23:33 PM by infiniteLoop »

If you fixed your damn formatting you'd probably see these mistakes yourself

Code: [Select]
package AutoGreeter
{
function newChatHud_addLine(%text)
{
if($canGreet == 1)
{   
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%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)
commandtoserver('messagesent',"Hi, " @ %nameToGreet);
}
}
}
};
activatePackage(AutoGreeter);

function ToggleGreet()
{
if($canGreet == 1) {
$canGreet = 0;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: Off.");

} else if($canGreet == 0) {
$cangreet = 1;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: On.");
}
}
This should work I tested it and ironed out the bugs

slightly simpler version.  Also with formatting fixed.

Code: [Select]
package AutoGreeter
  {
   function newChatHud_addLine(%text)
     {
      Parent::newChatHud_addLine(%text);

      if ($canGreet)
        {   
         //Called when any line of text is added to the chat box

         //This will turn the "jes00 connected." into "jes00"
         %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)
            commandtoserver('messagesent',"Hi, " @ %nameToGreet);
           }
        }
     }
  };

activatePackage(AutoGreeter);


function ToggleGreet()
  {
   $canGreet = !$canGreet;

   if ($canGreet)
      clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: Off.");
   else
      clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: On.");
  }

$canGreet=true;


Whenever I push the keybind it turns it on then off a few milliseconds late : /

connected. i am a gigantic friend

Have fun with your getting banned from stuff, still, for using a stuffty mod that is coded badly, and whose very purpose annoys the forget out of many people.

I've had people say that "it shows we care" when in fact it's automatic, thus showing that you don't care because you can't be bothered to type "Hi!" yourself (you lazy forget). When this is pointed out, I've then had those people say "NUH-UH IT SHOWS I CARE UR GAY" at which point I add them to my ever-growing list of people whose chat my client ignores (it's literally over three hundred people now) and permaban them if I can.


So here's a couple of pointers:
1) Everybody hates these, don't make them
2) If you are going to make them at least write them yourself instead of copy-pasting the code from that horribly broken abusable one (oh wait you can't actually code so you'll just be typing the same code instead of copy-pasting it)

3) Since the keybind problem is something that you can learn from:
Code: [Select]
function thCIAAKeybind(%down)
{
   if(%down)
   {
      // The key has been depressed
      // Do stuff for when it's pressed
   } else {
      // The key has been released
      // So it's turning on then off again because you're toggling it on depression and release of the key
   }
}

In conclusion: I hate you, please die. Good luck with learning to code better!

slightly simpler version.  Also with formatting fixed.
While that is better, it's a rather odd formatting style, and inconsistent in a few places.

Explaining the problem in just a little bit more detail (if you can't figure it out yourself) - the function is called both when you press the key, and when you release the key, and there's an argument passed to indicate whether you're pressing or releasing it. So like in the above post, you need to check the value of it.

As for using this - please don't. It's fine as a learning exercise, but don't use it beyond one test, and make sure you're not in a server with people who get really annoyed by it.

Code: [Select]
package AutoGreeter
{
function newChatHud_addLine(%text)
{
if($canGreet == 1)
{   
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%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)
commandtoserver('messagesent',"Hi, " @ %nameToGreet);
}
}
}
};
activatePackage(AutoGreeter);

function ToggleGreet()
{
if($canGreet == 1) {
$canGreet = 0;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: Off.");

} else if($canGreet == 0) {
$cangreet = 1;
clientCmdMessageBoxOK("Auto Greeter, by jes00","Auto Greeter is now: On.");
}
}
This should work I tested it and ironed out the bugs
Wow I retested and it breaks the chat when its off

Code: [Select]
package AutoGreeter
{
function newChatHud_addLine(%text)
if($Greeter::On == 1)
{
{  
//Called when any line of text is added to the chat box
Parent::newChatHud_addLine(%text);
//This will turn the "jes00 connected." into "jes00"
%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)
commandtoserver('messagesent',"Hi, " @ %nameToGreet);
        }
}
}
};
activatePackage(AutoGreeter);

function GreetToggle()
{
 switch$($Greeter::On)
{
case "1":
$Greeter:On = 0; echo("Greeter is now Off");  break;

case "0":
$Greeter::On = 1; echo("Greeter is now On"); break;
}
}
« Last Edit: September 10, 2011, 05:27:15 PM by adam savage »


There are several things wrong with that.
Plus I believe this has already been solved.

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)
commandtoserver('messagesent',"Hey, " @ %nameToGreet);
}
}
};
activatePackage(niceToGreetYou);

Theres the real one. And it works

I've now taken to making a less abusive auto greeter.

I've now taken to making a less abusive auto greeter.
it's not abusive, it's just annoying, and nothing you can do will make it not annoying.

it's not abusive,
It is abusive because people can say "Connected." to trigger it.
it's just annoying, and nothing you can do will make it not annoying.
I tried making it just say "Hi" when a player enters with a two and a half second delay and nobody even noticed it.
« Last Edit: September 12, 2011, 11:46:39 AM by jes00 »