mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2015
Posts: 5
Hey all of you,

i recently began to write a script for a friend of mine. He streams gameplay and would like to have a bot in his twitch irc.
I already got a point system set up. Here is the script in it's current version:

Quote:

alias -l addPoints {
if ($1 !isnum) { echo 2 -st $1 is not a number. It needs to be a number. | halt }
var %topic $+($chan,.,$nick)
var %points $calc($readini(Points.ini,%topic,Points) + $1)
writeini -n Points.ini %topic Points %points
return %points
}

alias -l lookUpPoints {
var %topic $+($chan,.,$nick)
var %points $readini(Points.ini,%topic,Points)
return %points
}
alias doaddpoints {
if ($3 !isnum) { echo 2 -st $3 is not a number. It needs to be a number. | halt }
var %topic $+($1,.,$2)
var %points $calc($readini(Points.ini,%topic,Points) + $3)
writeini -n Points.ini %topic Points %points
echo -a Added points for %topic
}

alias dorempoints {
var %topic $+($1,.,$2)
remini -n Points.ini %topic Points
echo -a Removed points for %topic
}

on *:text:!points:#:{
if ((%floodpoints) || ($($+(%,floodpoints.,$nick),2))) { return }
set -u10 %floodpoints On
set -u30 %floodpoints. $+ $nick On
msg # $nick has $readini(Points.ini,$+(#,.,$nick),Points) total points.
}

on $*:text:/!points (add|remove)/Si:#:{
if ($nick isop #) {
if ($0 < 3) { msg # Insufficient parameters: Use !points <add|remove> <user> [number] | return }
writeini -n Points.ini $+(#,.,$3) Points $calc($readini(Points.ini,$+(#,.,$3),Points) $iif($2 == add,+,-) $iif($4 isnum,$4,1))
{ msg $chan $3 now has $readini(Points.ini,$+(#,.,$3),Points) total points. }
}
else { msg $chan This command is only available to moderators. }
}


As you can see, i can already add and remove points to users. This functionality works.
But now the tricky part. I need 2 more commands:

I want to have a "!StartNewRound" command, which allows every user to place a guess (Number between 0 and 100). After 5 Minutes the Round should be locked.
Also, i need a "!EndRound xx" command in which xx is the number which was correct. After executing the command, all users with the right guess should be rewarded with 10 points.

I have no clue how i could do that. Maybe with introducint another variable for every user that placed a guess and checking all of those guesses afterwards? Is there something like a "for each X"?

I appreciate every help.

Best regards

Squirrelthroat

Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
You can use my betting/points system if you want.

I made this so that points carry over bewtween channels, and every user starts with 2500 points, so the .ini file structure is different from the one you're using. If you want your idle points system to work with it you'll need to address that (or just remove your current points system.)

Commands:

"!match" (starts betting timer and gives instructions)
"!w <points>" or "!l <points>" (place a bet on the match)
"!win", "!loss" or "!void" (report result of match)
"!points" and "!top5" (commands to display points)

http://pastebin.com/i4YCvfWa

Joined: Apr 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2015
Posts: 5
Originally Posted By: Sakana
You can use my betting/points system if you want.


wow, that's an awesome script. It teaches me alot.
I need a system that accepts a guess without placing any points.
!guess 5 - to place your guess.

I got to thank you tho. I will try to build my own system in the next weeks.

If anybody knows a system that is able to do what i search, i will appreciate every hint.

I will update this thread with my progress smile starting to work on it on 09.05.15

best regards

/edit 1

Well, i just started laugh

Can anyone read over this and point out any errors i made? Also i'd appreciate if you got tips whether this could work in the way i intend to do it or not.

Code:
on $*:text:/!start:#:{
  if ($nick isop #) {
	msg $chan A new round of guessing has started. You now got 5 minutes to guess how often VITALIC will die in this Game.
	startbetting
	msg $chan You can use the command !guess <number of death> to place your guess.
	/timer 1 300 endbetting 
  }
  else { msg $chan Only moderators can start a new round. }
}

on $*:text:/!guess:#:{
	if ($0 < 1) { msg # Wrong use, you need to place a guess with: !guess <putyourguessnumberhere> | return }
	if ($0 > 1) { msg # Wrong use, you need to place a guess with: !guess <putyourguessnumberhere> | return }
	if ( $readini(Lock.ini, n, Lock, GuessingLock) = 0){
		writeini -n Guesses.ini Guesses $nick $1
	}
	else { msg $chan Guessing is currently disabled. }
  
}

on $*:text:/!result:#:{
	;i need to place a foreach here, which executes addpoints for every user that was right ($1 = readini - userguess)
	
	/remini Guesses.ini Guesses
	
	;i need a msg chan which announces the winners
}


alias -l startbetting {
  writeini -n Lock.ini Lock GuessingLock 0
}

alias -l endbetting {
   writeini -n Lock.ini Lock GuessingLock 1
   msg $chan The guessing Phase is now locked. 
}


I'm still working on it and will test it when i arrive at home.
I would appreciate any comments tho.

Have a great day

Squirrelthroat

/edit 2
-> changed code block with newer version

/edit 3
I need to read all entries of the "Guesses" section in the Guesses.ini file. There is no command i can use, that does that directly.
My plan is:
I introduce a variable, that counts how many guesses are placed. Also, i setup a ini file that correlates a guess number to a user like:
1 - Username1
2 - Username2

After that, i'll do a wile (computedGuesses != placedGuesses) and do a lookup of the username and guess, and compute whether the guess was correct or not.

Is there an easier way?

Also, is there any way to check my codes syntax? i'm new to this and programming without IDE is quite hard.

Last edited by Squirrelthroat; 27/04/15 09:44 AM.
Joined: Apr 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2015
Posts: 5
Okay, i reached a new step which offers too many questions.

Here they go:
- After declaring a alias, i can use it by using its name like this:
var %totalNumberOfGuesses = lookUpNbrOfGuesses (lookUpNbrOfGuesses is an alias)
Is this correct or do i have to use $lookUp...?

- All read and writeini commands need a $ in front, correct?

- This: "/timer 1 300 endbetting " will start a timer, which executes the "endbetting" alias after 300 seconds, correct?

- This code will return Number saved as currentCount in the section Guesscounter in the file Guesses.ini:
Code:
alias -l lookUpNbrOfGuesses {
  return $readini(Guesses.ini, Guesscounter, currentCount)
}


- There is no debugger or any comparable help with writing those scripts, right? Not even a Syntax Checker.



Those were my main questions. In addition, if there's anyone who got 5-15 minutes of time, i would appreciate any help, because it seems like my code is filled with mistakes.
If you want to point out errors to me, here it is in it's full glory:
Full Guessing Script

best regards
Squirrelthroat

Joined: Sep 2014
Posts: 259
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259

"
- After declaring a alias, i can use it by using its name like this:
var %totalNumberOfGuesses = lookUpNbrOfGuesses (lookUpNbrOfGuesses is an alias)
Is this correct or do i have to use $lookUp...?
"

use $lookUp(input)

"
- All read and writeini commands need a $ in front, correct?
"

Use "writeini". $ is used when a function (alias) returns some value and you want that value.

"
- This: "/timer 1 300 endbetting " will start a timer, which executes the "endbetting" alias after 300 seconds, correct?
"

Yes

"
- This code will return Number saved as currentCount in the section Guesscounter in the file Guesses.ini:
Code:

alias -l lookUpNbrOfGuesses {
return $readini(Guesses.ini, Guesscounter, currentCount)
}
"

Yes

"
- There is no debugger or any comparable help with writing those scripts, right? Not even a Syntax Checker.
"

There's only something called mSlDev, but I never tried it. It's relatively easy to catch mistakes when you test your stuff before moving forwards.

Joined: Apr 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2015
Posts: 5
mSLDev is extremely helpful. it showed me most of my mistakes.

i finished the first properly working version today. i already tested it and cant find any mistakes. you can find that version here:
http://www.mpaste.com/p/bUg5MT

i will always check in the newest version into my github which you can find here:
https://github.com/MaikMaier/Guessing-System-for-mIRC

thanks to all those who helped me on my way.

best regards

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
2nd line, you're checking for %floodyoutube.$nick and you're setting %floodmmr.$nick

Also, isn't it annoying to have to update that all the time in the remote editor? You should use something more dynamic.
Example:
Code:
on *:text:!mmr*:#: {
if ($2 == solo) set %solo $3 
elseif ($2 == party) set %party $3
else msg # Solo: %solo Party: %party
}
While this may not be anything relevant to what you're doing right now. Optimizing code is always an ongoing thing and if you keep at it, you will most likely look back at your code and wonder why on earth you did as you did.


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Apr 2015
Posts: 5
S
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
S
Joined: Apr 2015
Posts: 5
Originally Posted By: Nillen
You should use something more dynamic:...


Great tip. I was introduced to globals earlier that day, so i had not thought about that earlier. Switched to your suggestion now.

Thanks alot!

Also, current version can always be found here.

best regards


Link Copied to Clipboard