StealthBot.net: Resolved: Need some help finishing my script - StealthBot.net

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Resolved: Need some help finishing my script

#1 User is offline   Magnitoo Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 18
  • Joined: November-12 09

Posted July 07, 2010 - 01:28 PM

Hello again,

Well I've followed the beginner and the intermediate tutorials on scripting and I have to say they're great, hands up for Ninja.

Anyways, I wanted to make a new script for my bot, this script is based on one of Ping Gnomes old functions which is when you say gnome, the bot replies with something random. Now what I want to do is make it so when somebody types random (without the bots trigger), it takes a text from an array (meaning I can actually control what it says) and prints it out for the user. However I want the person to only be able to use this every 40 seconds.

This is what I have come up with so far (Since I'm totally new to VB [I have worked in C++ and Delphi before] I have used most of other scripts to make my script hehe)
Script("Name") = "Random"
Script("Author") = "Magnitoo"
Script("Major") = 1
Script("Minor") = 0
Script("Revision") = 0
Script("Description") = "Makes a random reply when someone types random"

Private randomLastUse

Private Const randomAntiSpam = 30

Sub Event_Load()
    gnomeLastUse = Now-1
End Sub
	
Sub Event_UserTalk(Username, Flags, Message, Ping)

'// This is where I want it to pick a random text from. I'm not sure if this is how you do it but yeah..
Replies = Array("Well I don't belive it!", "If you add 2+2 and then subtract two divided by two plus two and subtract one you get zero.", "You  got served!")
	
	If DateDiff("s", randomLastUse, Now) < randomAntiSpam Then Exit Sub
    End if
	If Message = "random" Then
'// Ok now I'm lost, I want it to pick a random reply from the Replies Array and print it out. After that I want to make it leave the channel but I know how to do that.


That's basically it, any help is appreciated and any advice for me on how to do this in the future as always nice and appreciated.
Best regards.

This post has been edited by Magnitoo: July 07, 2010 - 01:29 PM

The sexiest member around.

Deal with it.

#2 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted July 07, 2010 - 02:21 PM

  • You should make the gnomeLastUSe private as well so it can be used in all other subs, otherwise, once the Event_Load sub is over, that gnomeLastUse variable is over as well.
  • Adding Randomize to the Event_Load will make it so that your random numbers are truly random
  • If you use " If ... Then Exit Sub ", you don't need an End If
  • The RandNum function I got from the Useful Things thread in the Tutorials section and I tried to break down how I was getting the max and min numbers.


Script("Name") = "Random"
Script("Author") = "Magnitoo"
Script("Major") = 1
Script("Minor") = 0
Script("Revision") = 0
Script("Description") = "Makes a random reply when someone types random"

Private randomLastUse, gnomeLastUse

Private Const randomAntiSpam = 30

Sub Event_Load()

   gnomeLastUse = Now-1
   Randomize
End Sub
        
        
Sub Event_UserTalk(Username, Flags, Message, Ping)

   '// This is where I want it to pick a random text from. I'm not sure if this is how you do it but yeah..
   Replies = Array("Well I don't belive it!", "If you add 2+2 and then subtract two divided by two plus two and subtract one you get zero.", "You  got served!")
   
   If DateDiff("s", randomLastUse, Now) < randomAntiSpam Then Exit Sub
 
   If Message = "random" Then
      '// Ok now I'm lost, I want it to pick a random reply from the Replies Array and print it out. After that I want to make it leave the channel but I know how to do that.
      high = UBound(Replies)
      low = LBound(Replies)      
      RanNum = Int(((high + 1) - (low)) * Rnd + (low))
      
      gnomeLastUse = Now
      AddQ Replies(RanNum)
      AddQ "/j Night Elf Tree of Life"
   End If
End Sub

This post has been edited by The-Black-Ninja: July 07, 2010 - 03:19 PM


#3 User is offline   Magnitoo Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 18
  • Joined: November-12 09

Posted July 07, 2010 - 02:55 PM

Thanks thanks.

I'm starting to like this place :)
The sexiest member around.

Deal with it.

#4 User is offline   The-Black-Ninja Icon

  • The Sex
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 2,526
  • Joined: August-01 09

Posted July 07, 2010 - 03:18 PM

Oh I also forgot, you're going to have to set the gnomeLastUse to the current time and date when someone uses the command so your anti-spam can work. My post is updated to reflect this.

#5 User is offline   AwaKening Icon

  • how do ya like me now
  • PipPipPipPipPip
  • Group: Members
  • Posts: 977
  • Joined: August-20 09

Posted July 07, 2010 - 03:45 PM

Try keeping things as efficient as possible. Don't run unnecessary code before you exit a sub unless you need to. Don't set your replies Array until you've checked the antispam and the message. It would probably be a better idea to just make it a global variable so it's only set when the bot loads. If you really want to get picky, you should be checking for antispam after you check the message rather than the other way around. It could save you 1 if check everytime a usertalks.

It appears to me also that gnomeLastUse and randomAntiSpam were supposed to be the same variable, but you changed your mind in naming them but didn't fix them all. If I'm wrong, then you need to fix something, because as you have it right now, nothing is happening with them.

Here's how I would do it:

'// Get used to declaring all your variables and using Option Explicit
'// This way you'll catch an error on Load if you have a typo in the variable names
'// It's good practice and will save you headaches later ;) 

Option Explicit

Script("Name") = "Random"
Script("Author") = "Magnitoo"
Script("Major") = 1
Script("Minor") = 0
Script("Revision") = 0
Script("Description") = "Makes a random reply when someone types random"

Private randomLastUse
Private Replies(2)

Private Const randomAntiSpam = 30

Sub Event_Load()

   Replies(0) = "Well I don't believe it!"
   Replies(1) = "If you add 2+2 and then subtract two divided by two plus two and subtract one you get zero."
   Replies(2) = "You got served!"

   randomLastUse = Now-1
   Randomize
End Sub
        
        
Sub Event_UserTalk(Username, Flags, Message, Ping)

   '// Good idea to use LCase or UCase when checking the message
   If NOT(LCase(Message) = "random") Then Exit Sub

   Dim high, low, RanNum

   '// Just a note on the Abs() Function (Absolute)
   '// I like to use it with DateDiff just in case you forget which Time goes first in the function
   If Abs(DateDiff("s", randomLastUse, Now)) < randomAntiSpam Then Exit Sub

   randomLastUse = Now

   high = UBound(Replies)
   low = LBound(Replies)      
   RanNum = Int(((high + 1) - (low)) * Rnd + (low))
      
   AddQ Replies(RanNum)
   AddQ "/j Night Elf Tree of Life"
End Sub


#6 User is offline   Magnitoo Icon

  • Junior Member
  • PipPip
  • Group: Members
  • Posts: 18
  • Joined: November-12 09

Posted July 07, 2010 - 06:46 PM

Yeah I didn't change it fully when I posted. I fixed it all up and it works now.

The previous code Ninja made worked fine, tho I do guess if I wanna make more complex things this is gonna be of use.
The sexiest member around.

Deal with it.

#7 User is offline   AwaKening Icon

  • how do ya like me now
  • PipPipPipPipPip
  • Group: Members
  • Posts: 977
  • Joined: August-20 09

Posted July 07, 2010 - 07:41 PM

I have marked this topic as resolved. If you did not receive a satisfactory response please reply and provide as much relevant information as possible.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users