|
Joined: Dec 2013
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2013
Posts: 6 |
He Guys ! i am currently writing a chat bot for my twitch channel, up to now i could add all features i want to add and they work good but then... i got an idea... and i cant get it to work... so maybe one of you can help me out here comes my problem: (at the end of this post there is a shortened version of my problem) I have Several timers run on my bot, 1 of them adds 5 points every 5 minutes for a gambling function. another one adds 1 point every second saves it in seconds and converts and shows it in HH:nn:ss for total time viewed in my channel per command... so far so good ! yesterday i came up with the idea of adding ranks for "X" time viewed... so i did and it works fine... then i thought... ok... lets get higher ranks more gambling points per time period so lets say... ppl who watched 20 hours (or 72000 seconds) get 1 bonus point per 5 minutes... but when someone with this rank joins my channel he gets 5+1 Point RIGHT in the moment the bot starts the timer, but after this the viewer is getting 5 points every intervall not the 5+1 points he should get. so does someone got any idea how to tell the timer to add the bonus when a certain point of viewtime is reached? my code looks like this atm: alias gamblePunkte {
var %viewsec $readini(Viewtime.ini,$+(#,.,$nick),viewtime)
if (%viewsec < 72000 ) {
writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +6)
return
}
elseif (%viewsec < 144000 ) {
writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +7)
return
}
elseif (%viewsec < 216000 ) {
writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +12)
return
}
elseif (%viewsec < 288000 ) {
writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +13)
return
}
elseif (%viewsec < 360000 ) {
writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +18)
return
}
else writeini -n Punkte.ini $1 Kronkorken $calc($readini(Punkte.ini,$1,Kronkorken) +5)
return
}
;#### ViewTimer ####
alias viewTime {
writeini -n Viewtime.ini $1 Viewtime $calc($readini(Viewtime.ini,$1,Viewtime) +1)
}
;#### Punkte timer und Willkommen Nachricht ####
on !*:join:#:{
$+(timergamble,#,.,$nick) 0 300 gamblePunkte $+(#,.,$nick)
gamblePunkte $+(#,.,$nick)
$+(timerview,#,.,$nick) 0 1 viewTime $+(#,.,$nick)
viewTime $+(#,.,$nick)
if ((%joinspam) || ($($+(%,joinspam.,$nick),2))) { return }
set -u10 %joinspam On
set -u30 %joinspam. $+ $nick On
msg $chan Wilkommen $nick , viel spaß im Stream =)
}
;#### Timer OFF #### (wenn channel leave)
on *:part:#:{
$+(timergamble,#,.,$nick) off
$+(timerview,#,.,$nick) off short version: - timerview: adds 1 point every second, meant to be viewtime - timergamble: adds 5 points every 5 minutes, for gamble - viewers with "X" time in viewtime.ini should get bonus points on timergamble - viewer gets the bonus a SINGLE time, timergamble goes back to 5 points per 5 minutes - dun know how to fix - PLS HELP :P Thank you very much for reading my post and maybe helping me out, if you wonder about my bad english: sorry i am from germany
|
|
|
|
Joined: Jan 2004
Posts: 1,358
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,358 |
When you call gamblePunkte from a timer, # and $nick do not resolve because they aren't valid in the current context (the timer is not associated with a channel or nick).
But you've passed the correct value to the timer already: $+(#,.,$nick). You need to use $1 instead of $+(#,.,$nick) (as you are doing correctly in the rest of the alias)
var %viewsec $readini(Viewtime.ini,$1,viewtime)
As a side note, you may want to look into working from hash tables instead of ini files. Hash tables reside in memory so they are faster and do not use the disk as much as ini files (hundreds of reads and writes per second is a lot imo).
|
|
|
|
Joined: Dec 2013
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2013
Posts: 6 |
hey ! thank you for answering ! ill give it a try right now and will see its working to hash tables: as far as i know i have to save them manually everytime i restart the bot, is that correct? and if it is correct, any way to automate this? thanks in advance !
|
|
|
|
Joined: Jan 2004
Posts: 1,358
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,358 |
Of course; you may also want to save it to disk every 10 minutes or so, so that if mIRC crashes you don't lose the data from the entire session. on *:start:{
hmake #chan.viewtime
hload -i #chan.viewtime viewtime.ini #chan
}
on *:exit:{
hsave -i #chan.viewtime viewtime.ini #chan
}
on me:*:join:#:{
$+(.timer,#,.viewtime.save) 0 600 viewtime.save #
}
on me:*:part:#:{
$+(.timer,#,.viewtime.save) off
}
alias viewtime.save {
var %chan = $1
hsave -i $+(%chan,.viewtime) viewtime.ini %chan
}
|
|
|
|
Joined: Dec 2013
Posts: 6
Nutrimatic drinks dispenser
|
OP
Nutrimatic drinks dispenser
Joined: Dec 2013
Posts: 6 |
hey ! got it working now ! Thank you very much, i would never got this since im still a newb with only 7 days of experience =) would you mind to explain where the $1 comes from? as far as i understood up to now: $1 is the first section of a command/action eg: on $*:text:/!bonus (plus|minus) "!bonus" would be $1... so whenthe FAT part doenst count in: gamblePunkte $+(#,.,$nick)where does $1 in var %viewsec $readini(Viewtime.ini, $1,viewtime) comes from and i will look into the hash table thing, but since i am new to this theme ill see if i can get it by myself =) Thank you for helping me up to now ! have a good night ! (1 am here ^^ )
Last edited by Stoned4Ever; 10/12/13 11:55 PM.
|
|
|
|
Joined: Jan 2004
Posts: 1,358
Hoopy frood
|
Hoopy frood
Joined: Jan 2004
Posts: 1,358 |
In a text event $1- is the text that was sent.
Likewise, in an alias $1 and $2... refer to text you send to the alias.
In your join event you have the following line: $+(timergamble,#,.,$nick) 0 300 gamblePunkte $+(#,.,$nick)
Since this line is in a join event, you have access to both # and to $nick, and so $+(#,.,$nick) is resolved appropriately. You're starting a timer timergamble#chan.nick that calls gamblePunkte #chan.nick
#chan.nick is the first word you're sending to gamblePunkte, so within the alias you access it by $1.
If you call /test a b c, you will see that $1 $2 $3 are replaced by a b c. alias test { echo -ag $1 $2 $3 }
|
|
|
|
|