This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Help....my dice dosnt work exactly. Anybody help me plz! ;)

Old posts that have not been replied to for several years.
Locked
-
-{DFW}-DER_Wolle!

Help....my dice dosnt work exactly. Anybody help me plz! ;)

Post by -{DFW}-DER_Wolle! »

Hey everybody!
I have a little prob!
I´ve written a little neat Dice-addon, but it dont work on my idea! (my english sux, i know :oops: )
Here the code:

Code: Select all

bind pub - !w ?pub_wuerfel

proc ?pub_wuerfel {nick userhost hand chan target} {
  set num [rand 7]
	  if {$num > 0 && $target == ""} {
	   putchan $chan "--> $nick hat eine $num gewürfelt!" ;return 0}
	   if {$num > 0 && $target != ""} {
	   putchan $chan "--> $nick hat eine $num gewürfelt! (von $target Seiten)" ;return 0}
	   else {
		  putchan $chan "--> $nick ! Nur positive  Zahlen eingeben! (z.B.: !w 78)" ;return 0}
}
When a user type only !w, the answer is [/color]"NICK hat eine "RANDOM Number" gewürfelt." Where a default dice only have 6 sides! [it means it cant display numbers higher then 6 or a 0]

But is he typing !w 666, it must display the same above, but with the attachment "(Von 666 Seiten)" in end of this line. (will means, the dice now has 666 sides)

last but not least:
Is he typing !w 0 or !w abc an error must displayed!

Well i hope any Germans are present here to understand my problem.

Greetz:

-{DFW}-DER_Wolle!

Notice: Falls jemand deutsch spricht und mir helfen kann, #dfw im Quarknet! ;) Einfach Querie oder frag nach mir!
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

If you want a random value based on the number supplied by the user you better use that number when randomizing :P

Keep in mind that 'rand' returns a random number between 0 and the (positive) integer you feed it -1, so you better add 1 to the result, not to the number randomized if you want values from 1 to 6 returned.

To check if the input is valid you can do

Code: Select all

if {[string is int $input] && $input>0} {..}
or

Code: Select all

if {[regexp {^[0-9]+$} $input] && $input>0} {..}
if you're coding for some old version that doesn't have that string command.

Here's a way to do the randomizing and adding in one operation:

Code: Select all

 [expr {int(rand()*$input)+1}]
Good luck :)
Have you ever read "The Manual"?
-
-{DFW}-DER_Wolle!

Post by -{DFW}-DER_Wolle! »

Sorry, but can u specify that?
Im a n00b in this and i have to learn.... :oops: :cry:
I also have read any tuts, but my english is very bad and mostly i cant understand anything... =(
*angry*
Thx for ur understandment...
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

Code: Select all

bind pub - !w ?pub_wuerfel 

proc ?pub_wuerfel {nick userhost hand chan input} { 
  if {[regexp {^[0-9]+$} $input] && $input>0} {
    if {$input != ""} {
      set num [expr [rand $input] + 1]
    } else {
      set num [expr [rand 6] + 1]
    }
    if {$input == ""} {
      putchan $chan "--> $nick hat eine $num gewürfelt!";
    } else {
      putchan $chan "--> $nick hat eine $num gewürfelt! (von $input Seiten)"
    }
  } else {
    putchan $chan "--> $nick ! Nur positive Zahlen eingeben! (z.B.: !w 78)"
  } 
}
that's how i'd code it. untested. i guess user's way is better, however, i don't understand it *g*
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
-
-{DFW}-DER_Wolle!

Post by -{DFW}-DER_Wolle! »

It dont work! :(
If i type only !w he prints out the Errormsg! (Nur positiv...bla)
User avatar
arcane
Master
Posts: 280
Joined: Thu Jan 30, 2003 9:18 am
Location: Germany
Contact:

Post by arcane »

Code: Select all

bind pub - !w ?pub_wuerfel 

proc ?pub_wuerfel {nick userhost hand chan {input "6"}} { 
  if {[regexp {^[0-9]+$} $input] && $input>0} { 
      set num [expr [rand $input] + 1] 
    if {$input == "6"} { 
      putchan $chan "--> $nick hat eine $num gewürfelt!"; 
    } else { 
      putchan $chan "--> $nick hat eine $num gewürfelt! (von $input Seiten)" 
    } 
  } else { 
    putchan $chan "--> $nick ! Nur positive Zahlen eingeben! (z.B.: !w 78)" 
  } 
} 
try this. hope this {input "6"} syntax is correct, but you will see...
aVote page back online!
Check out the most popular voting script for eggdrop bots.

Join the metal tavern!
-
-{DFW}-DER_Wolle!

Post by -{DFW}-DER_Wolle! »

No! This is incorrect.
If i only type !w, my bot says the errormessage! (e.G. sorry, only positive letters (>0)) :(


Anybody here with an idea where the error is in my script! Plz help! :cry:
-
-{DFW}-DER_Wolle!

Post by -{DFW}-DER_Wolle! »

Nobody with an idea here?? Hmm..., i think i give up!
Locked