|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
The code I have is pretty bloated and super basic, so I was hoping someone might be able to help me make it better, as it doesn't fully work. http://pastebin.com/GK2NLZB2What it is meant for is having a deck of fifteen cards. I need it to where you pull five cards at a time and it eliminates the five you've pulled from future pulls. On the third pull, obviously, it should list the remaining cards. That's where it errors out, giving me a memory stack error from the process being too bloated by then. What I am looking for is a way for it to have a list and when it hits a result it removes that possibility from the list entirely or something. I don't know how to fully explain it.. and I figure my code is barbaric and inefficient. If anyone has any suggestions...
|
|
|
|
Belhifet
|
Belhifet
|
on *:text:!draw:#:{
var %names Bulbasaur Ivysaur Venusaur Charmander Charmeleon Charizard Squirtle Wartortle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill
var %c1 $rand(1,15)
var %c2 $rand(1,15)
var %c3 $rand(1,15)
while (%c2 == %c1) { var %c2 $rand(1,15) }
while (%c3 == %c1 || %c3 == %c2) { var %c3 $rand(1,15) }
.msg $chan You drew $gettok(%names, %c1, 32) $+ , $gettok(%names, %c2, 32) $+ , and $gettok(%names, %c3, 32)
}
Uh something like this? I fail to see what the original is suppose to be doing.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
I guess something like that? The thing is, it has fifteen cards total, and you pick five at a time. I need it where either the last pull simply picks out the last five cards or states the last five remaining... but I don't need all three 'draws' done at the same time. While what you posted does help to severely simplify the coding, it doesn't seem to solve the problem. 
Last edited by Mythos; 31/12/14 11:05 PM.
|
|
|
|
Belhifet
|
Belhifet
|
I'm still not sure I follow what you want here...
on *:text:!draw:#:{
set %names Bulbasaur Ivysaur Venusaur Charmander Charmeleon Charizard Squirtle Wartortle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill
var %c1 $gettok(%names, $rand(1,15), 32)
var %c2 $gettok(%names, $rand(1,15), 32)
var %c3 $gettok(%names, $rand(1,15), 32)
var %c4 $gettok(%names, $rand(1,15), 32)
var %c5 $gettok(%names, $rand(1,15), 32)
while (%c2 == %c1) { var %c2 $gettok(%names, $rand(1,15), 32) }
while (%c3 == %c1 || %c3 == %c2) { var %c3 $gettok(%names, $rand(1,15), 32) }
while (%c4 == %c1 || %c4 == %c2 || %c4 == %c3) { var %c4 $gettok(%names, $rand(1,15), 32) }
while (%c5 == %c1 || %c5 == %c2 || %c5 == %c3 || %c5 == %c4) { var %c5 $gettok(%names, $rand(1,15), 32) }
.msg $chan You drew %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
set %names $remtok(%names, %c1, 32)
set %names $remtok(%names, %c2, 32)
set %names $remtok(%names, %c3, 32)
set %names $remtok(%names, %c4, 32)
set %names $remtok(%names, %c5, 32)
}
on *:text:!draw2:#:{
var %c1 $gettok(%names, $rand(1,10), 32)
var %c2 $gettok(%names, $rand(1,10), 32)
var %c3 $gettok(%names, $rand(1,10), 32)
var %c4 $gettok(%names, $rand(1,10), 32)
var %c5 $gettok(%names, $rand(1,10), 32)
while (%c2 == %c1) { var %c2 $gettok(%names, $rand(1,10), 32) }
while (%c3 == %c1 || %c3 == %c2) { var %c3 $gettok(%names, $rand(1,10), 32) }
while (%c4 == %c1 || %c4 == %c2 || %c4 == %c3) { var %c4 $gettok(%names, $rand(1,10), 32) }
while (%c5 == %c1 || %c5 == %c2 || %c5 == %c3 || %c5 == %c4) { var %c5 $gettok(%names, $rand(1,10), 32) }
.msg $chan You drew %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
set %names $remtok(%names, %c1, 32)
set %names $remtok(%names, %c2, 32)
set %names $remtok(%names, %c3, 32)
set %names $remtok(%names, %c4, 32)
set %names $remtok(%names, %c5, 32)
.msg $chan The remaining cards are %names
}
|
|
|
|
Belhifet
|
Belhifet
|
Ok nvm this one looks and works better on *:text:!draw:#:{
set %names. $+ $nick Bulbasaur Ivysaur Venusaur Charmander Charmeleon Charizard Squirtle Wartortle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill
var %i 1
while (%i <= 5) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$calc(16 - %i)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan You drew %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
}
on *:text:!draw2:#:{
var %i 1
while (%i <= 5) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$calc(11 - %i)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan You drew %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
.msg $chan The remaining cards are $gettok($($+(%,names.,$nick),2), 1, 32) $+ , $gettok($($+(%,names.,$nick),2), 2, 32) $+ , $gettok($($+(%,names.,$nick),2), 3, 32) $+ , $gettok($($+(%,names.,$nick),2), 4, 32) $+ , and $gettok($($+(%,names.,$nick),2), 5, 32) $+ .
}
Also you don't have pikachu in your list, This is a major flaw in your design.
Last edited by Belhifet; 01/01/15 08:19 AM.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
Sorry, Pikachu is #25 and I only collected 1-15 for names. the names are temporary, anyway. As for what I wanted, you pretty much nailed it on the head, despite being unsure.  Thank you verrah much and happy new year.
Last edited by Mythos; 01/01/15 09:26 AM.
|
|
|
|
Belhifet
|
Belhifet
|
on *:text:!draw:#:{
if ($numtok($($+(%,names.,$nick),2),32) != 10) { set %names. $+ $nick Bulbasaur Ivysaur Venusaur Charmander Charmeleon Charizard Squirtle Wartortle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill }
var %i 1
while (%i <= 5) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$numtok($($+(%,names.,$nick),2),32)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan You drew %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
if ($numtok($($+(%,names.,$nick),2),32) == 5) { .msg $chan The remaining cards are $gettok($($+(%,names.,$nick),2), 1, 32) $+ , $gettok($($+(%,names.,$nick),2), 2, 32) $+ , $gettok($($+(%,names.,$nick),2), 3, 32) $+ , $gettok($($+(%,names.,$nick),2), 4, 32) $+ , and $gettok($($+(%,names.,$nick),2), 5, 32) $+ . }
}
This has been bugging me for a couple hours now...this is probably a better version.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
I actually modified em all into one event earlier and made it where it says the cards on three draws, not two. Well, for the last one it just states what the remaining cards were and resets it. It's not as clean as your code as I'm a bit of a nublet. I also made it say "First Draw:" "Second Draw:" "Final Draw:" All of the token stuff goes way over my head in coding.
on *:text:!draw:#:{
if ($numtok($($+(%,names.,$nick),2),32) = 0) {
set %names. $+ $nick Bulbasaur Ivysaur Venusaur Charmander Charmeleon Charizard Squirtle Wartortle Blastoise Caterpie Metapod Butterfree Weedle Kakuna Beedrill
var %i 1
while (%i <= 5) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$numtok($($+(%,names.,$nick),2),32)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan 2 $+ $nick $+ 's first draw: %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
}
elseif ($numtok($($+(%,names.,$nick),2),32) == 10) {
var %i 1
while (%i <= 5) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$numtok($($+(%,names.,$nick),2),32)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan 2 $+ $nick $+ 's second draw: %c1 $+ , %c2 $+ , %c3 $+ , %c4 $+ , and %c5 $+ .
}
else {
.msg $chan 2 $+ $nick $+ 's final draw: $gettok($($+(%,names.,$nick),2), 1, 32) $+ , $gettok($($+(%,names.,$nick),2), 2, 32) $+ , $gettok($($ +(%,names.,$nick),2), 3, 32) $+ , $gettok($($+(%,names.,$nick),2), 4, 32) $+ , and $gettok($($+(%,names.,$nick),2), 5, 32) $+ .
unset %names. $+ $nick
}
}
I notice it doesn't show color code info on quotes. That's why there's a random 2 after $chan
Last edited by Mythos; 01/01/15 05:09 PM.
|
|
|
|
Belhifet
|
Belhifet
|
I'm a complete noob too \0/. But tokens are the best. Loops and tokens make everything so much easier. These things are pretty much vital for making scripts that actually do stuff beside 1 line responses.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
Is there a way to make it where it states how many items remain in the %names variable per nick?
Like if ten cards remain, it says 10 at the end?
$numtok($($+(%,names.,$nick),2),32)
Answered my own question.
Last edited by Mythos; 02/01/15 12:23 AM.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
on *:text:!draw:#:{
if ($numtok($($+(%,names.,$nick),2),32) == 0) { set %names. $+ $nick A B C D E F G H I J K L M N O P Q R S T U V W X Y Z | goto draw }
elseif ($numtok($($+(%,names.,$nick),2),32) == 1) {
.msg $chan 2 $+ $nick $+ 's last card is $gettok($($+(%,names.,$nick),2), 1, 32) $+ .
unset %names. $+ $nick
halt
}
else { goto draw }
:draw
var %i 1
while (%i <= 2) {
var % $+ $($+(c,%i),2) $gettok($($+(%,names.,$nick),2), $rand(1,$numtok($($+(%,names.,$nick),2),32)), 32)
set %names. $+ $nick $remtok($($+(%,names.,$nick),2), $($+(%,c,%i),2), 32)
inc %i
}
.msg $chan 2 $+ $nick drew %c1 and %c2 $+ . Remaining cards: $numtok($($+(%,names.,$nick),2),32)
}
Final product, pending. Made it where it draws 2 and you can change the number of 'names' in the list at any moment. If it's an odd amount, it triggers the 'last card' message. If it's evens, it just goes back to the start. Either way it lists how many cards remain at the end of each post. I also made a shuffle and shuffle all command to reset without reaching the end.
on *:text:!shuffle:#:{ unset %names. $+ $nick | .msg $chan 2 $+ $nick $+ 's deck has been shuffled. }
on *:text:!shuffleall:#:{
if ($nick isop #) { unset %names.* | .msg $chan 4Warning! All decks have been reshuffled. }
else { msg $chan 4Error! Only operators can shuffle everyone's deck. }
}
Last edited by Mythos; 02/01/15 01:04 AM.
|
|
|
|
Joined: Jan 2004
Posts: 1,330
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,330 |
Your gotos are completely redundant.
|
|
|
|
Joined: May 2010
Posts: 47
Ameglian cow
|
OP
Ameglian cow
Joined: May 2010
Posts: 47 |
The part where I said I'm a noob to coding...?
Are you suggesting I just remove them? Replace them with something else? Only have one? I'm not sure what you want me to do since all you did was point out what's wrong.
|
|
|
|
Belhifet
|
Belhifet
|
I think as a general rule you should just...never use a goto.
|
|
|
|
|