Author Topic: Dice  (Read 7975 times)

pheonix

  • Newbie
  • *
  • Posts: 5
Dice
« on: April 20, 2007, 03:31:54 PM »
Is there a way to script dice rolling into icechat.  I found a script, however I think the keyboard nut is loose and the script is not running.  ?Tips (assume I do not know the scripting language properly)?

If there is a script already in place link could help as well.

John

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #1 on: April 20, 2007, 03:44:55 PM »
Well, you should have pasted the script, because I really have no idea what your doing then.
The IceChat God

pheonix

  • Newbie
  • *
  • Posts: 5
Re: Dice
« Reply #2 on: April 20, 2007, 11:10:55 PM »
Here is the script I want to use.

on $*:TEXT:/^!dice (10|[1-9]) (\d+[0-9]|[1-9])$/:#: var %i = 0, %limit = $iif($2 > 10, 10, $2) | while %i < %limit { inc %i | .timer 1 $calc(%i * 2) msg $chan $nick rolled $3 $+ -sided die number %i of $2 $+ : Result $rand(1,$3) }

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #3 on: April 21, 2007, 01:04:08 AM »
Ok, that looks like a total copy from mirc.
While basic mirc scripts do work in IceChat, some will not copy over so easily, and some things just were never added ($iif/$calc/inc).

The best thing to do in this case, is convert the script in VB Script.
I will see if I can make any sense of the script, and convert it to VB Script, so you can use that instead.
The IceChat God

pheonix

  • Newbie
  • *
  • Posts: 5
Re: Dice
« Reply #4 on: April 21, 2007, 01:20:09 AM »
Thanks in advance for your assistance.  Can you include a link on how to start scripts in your reply (or a link to the information).  The only problem is I might have it right, starting it I mean, and not have the script for it so I will patiently wait for your reply.

Thanks
John M

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #5 on: April 21, 2007, 01:30:53 AM »
Open the IceChat Editor, click on the Scripts Tab, and paste in your script.
If its mirc style, you save it with the default file extension (*.ICS).
If its VB Script Style, you need to use File Save As, initially, and change the file type to IceChat 5 Scripts (*.ICE).
The IceChat God

pheonix

  • Newbie
  • *
  • Posts: 5
Re: Dice
« Reply #6 on: April 21, 2007, 10:51:46 PM »
So do I assume that the quoted script will work, or do I be patient.  Either was is fine.  I may need to check what extension the script is under.

John

pheonix

  • Newbie
  • *
  • Posts: 5
Re: Dice
« Reply #7 on: April 22, 2007, 02:06:52 AM »
Kind of a post-script I was unable to get the listed script to work so...

John
I got the program to say it was loading however no reaction from the machine on the !dice command.


Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #8 on: April 22, 2007, 09:41:04 AM »
I already told you, the script you posted will not work.
The IceChat God

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #9 on: April 24, 2007, 05:05:57 PM »
Ok, so you open the Script Editor, and go to the Scripts tabe and paste in the code.
Click on Save and Exit, and change the File Type to 'IceChat 5 Script' and give it a file name.
Thats it.

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
words = split(Message," ")
if words(0) = "!dice" and ubound(words) = 2 then
    if IsNumeric(words(1)) and IsNumeric(words(2)) then
        'words(1) - how many times dice is rolled
        'words(2) - how many sides to the dice
        '!dice 3 6 <- rolls a 6-sided die 3 times

        'check that no more then 10 rolls is asked, and limit to 10
        if words(1) > 10 then words(1) = 10
        Randomize
        for i = 1 to words(1)
            'get the random value here
            dieValue=int(rnd * words(2)) + 1
            SendCommand "/msg " & Channel & " " & NickName & " rolled " & words(2) & "-sided die number " & i & " of " & words(1) & " : "  & dieValue, ServerNumber
        next
    end if
end if
End Sub

To activate it, a person types "!dice #rolls #sides -- so "!dice 3 6" rolls a 6 sided die 3 times.
It will not work for yourself, someone else has to type it. Thats just how the ONTEXT event works for IceChat 5 Scripting.

If you want it to also work when you type the command, copy the code below, adding it to the script above.

Code: [Select]
Function OUTTEXT(OutgoingText)
words=split(OutGoingText)
if words(0) = "!dice" and ubound(words) = 2 then
    'check if in a channel
    if GetIdentifier("$activetype") = 2 then
        if IsNumeric(words(1)) and IsNumeric(words(2)) then
            'words(1) - how many times dice is rolled
            'words(2) - how many sides to the dice
            '!dice 3 6 <- rolls a 6-sided die 3 times

            'check that no more then 10 rolls is asked, and limit to 10
            if words(1) > 10 then words(1) = 10
            Randomize
            for i = 1 to words(1)
                'get the random value here
                dieValue=int(rnd * words(2)) + 1
                SendCommand "/msg $active $me rolled " & words(2) & "-sided die number " & i & " of " & words(1) & " : "  & dieValue
            next
        end if
    end if
end if
OutText = OutGoingText
End Function
« Last Edit: April 24, 2007, 08:39:04 PM by Snerf »
The IceChat God

Dunny

  • Newbie
  • *
  • Posts: 4
Re: Dice
« Reply #10 on: July 02, 2007, 03:11:56 PM »
Snerf your code works perfectly. I am working on converting my bot to VB script (from mIRC script) and since I am no expert and scripted that one from trial and error, I figure that it will be a while before I actually script my bot over :) but the dice thing works exactly as it should.

I will catch up with you in your IRC whatever sometime I would like to offer up a donation for all this... there is no way this program or all the coding you (and your team of coders/testers) should go unrewarded.

Dunny

Omni_Bowser

  • Newbie
  • *
  • Posts: 13
Re: Dice
« Reply #11 on: February 15, 2008, 09:04:11 PM »
Is there a way to make this so it only works in a certain channel?

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #12 on: February 15, 2008, 10:02:47 PM »
In the ONTEXT, make it check the channel in an if statement.
The IceChat God

Omni_Bowser

  • Newbie
  • *
  • Posts: 13
Re: Dice
« Reply #13 on: February 15, 2008, 10:21:23 PM »
I'm very sorry... But I'm not quite sure where you mean as to where to put it...

Snerf

  • Administrator
  • Hero Member
  • *****
  • Posts: 1968
    • IceChat IRC Client
Re: Dice
« Reply #14 on: February 15, 2008, 10:37:02 PM »
Current, the ONTEXT sub starts like this.
Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
words = split(Message," ")

Change it this this.

Code: [Select]
Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
if Channel <> "#mychannel" then Exit Sub
words = split(Message," ")

Just change #mychannel to your channel name.
This wont change for your own typing, but I am sure you can at least solve that problem, by not using it in other channels.  :mrgreen:
The IceChat God