mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#241759 26/05/13 04:21 AM
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
i havent scripted in years and wanna be able to do this
Basically its like a raffle with multiple tickets.

when i turn script on i want it to start adding tokens to each user in channel on variable x set intervals

when i run contest i wanna be able to have only people with say 4 tokens qualify .

with an option to say someone leaves channel for x minutes then it deletes that persons tokens they have.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just run a timer that calls an alias every X amount of time. When the timer triggers, loop through the users in the channel using $nick($chan,N) and /inc their variable or hash table data or however you choose to store their tokens. At the same time, you can delete anyone in the list who isn't on the channel anymore. If you want to allow them to be off the channel for more than just one timer interval, then store the $ctime when you last incremented their token. Once that's stored, you can subtract it from the current $ctime and if it's greater than your limit, you delete them.


Invision Support
#Invision on irc.irchighway.net
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
tyvm i will work on coding that and see how it turns out will reply with what i come up haven`t coded in years but i can do this im sure maybe might need help tiding up code later which people will usually do which is awsome of them but anyhow i will repost when i complete it tyvm again for a response.

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
im stuck on one part

if ($did == 10) {
did -r $dname 13
var %nicks = $nick($active,0)
while (%nicks > 0) {
did -a $dname 13 $nick($active,%nicks)
dec %nicks
}
did -ra $dname 15 $nick($active,0)
}

i am having trouble gettin code to only add users to list box that have say %usergiveawaytokenDaRkCaSTLe- 5
only wanna add people to list that have
%usergiveawaytoken* = to 4 or more
can someone pls help with this tyvm in advance

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Code:
if ($($+(%,usergiveawaytoken,$nick),2) >= 4) { }


Basically, this will evaluate the variable %usergiveawaytokennick and if it's >= 4, then you'll do something with it, such as add it to your list. The "nick" on the variable is whatever $nick returns.

That being said, if you're storing tokens for many people, you'll probably be better off using a hash table. Then you won't have a lot of variables. A hash table is usually better than variables any time you need to store a lot of data of the same type and want easy access to it. In this case, you're storing the same type of data (tokens) for many users and want to quickly access how many tokens each user has, so it is a good option for you. It's also very easy to add and remove users as needed and you can easily store their $ctime if you want it to remove after X amount of time.

If you're interested in hash tables, check into the following and see where you get from there.

/help hash tables

A hash table has items and data. For example, item1=data1 and item2=data2. If you store your tokens like this: nick=#tokens, then using the data is as easy as:

Code:
// Check if it's $nick has >= 4 tokens
if ($hget(tablename,$nick) >= 4) { }

// Increment the tokens for $nick
hinc tablename $nick

// Remove the nick
hdel tablename $nick


Just remember that hash tables are not automatically saved to disk. If you close mIRC, any data in a hash table will be lost. If you want the data to be persistent, you'll need to save the data yourself using /hsave. You can do this every time you add/update the data, or on a timer.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Riamus2
You can do this every time you add/update the data, or on a timer.
Hash table merely needs to be saved upon exit. It gets lost when mIRC closes. I don't see the point in saving the data per entry added, nor with a timer. Correct me if I'm mistaken.

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
if ($did == 8) {
did -r $dname 11
var %tempTwitchTV = $hfind(TwitchChannelUsers,*)
while (%tempTwitchTV >= 4) {
did -a $dname 11 %tempTwitchTV
}
}

cant get this to work but in hash table data is the way i need it like for example

DaRkCaSTLe = 1
TestPerson = 6
TestPerson2 = 8

i wanna scan hash table TwitchChannelUsers for all users that have a number 4 or higher and add just those users to listbox 11 on the dialog when i [ress button 8

it would even be ok if they get to list in this manner

TestPerson = 6
TestPerson2 = 8

then would like to be able send the total users that have 4 or more to text box 12

Last edited by DaRkCaSTLe1974; 28/05/13 10:56 AM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
@Tomao: I usually recommend saving regularly for any hash table that gets updated on a regular basis. mIRC or the computer itself can crash for a variety of reasons. When this happens, you don't trigger the QUIT or EXIT events and you'll lose everything since the last save. If the data is very important and updates often, saving on each update is a good option. If the data isn't as important and it's okay if you were to lose and hour or a couple of hours or even a day or more, you can use a timer either exclusively or in addition to a QUIT or EXIT event. Just set the timer to whatever level is acceptable for a worst-case loss scenario. For something like scores or points, saving often is usually a good idea. Also, if the bot isn't rebooted often, you can risk losing days, weeks, or even months worth of data if you only use a QUIT or EXIT event.

@DarkCastle: Here's one option. This just loops through the entire table. If the table isn't large, this should be fine.

Code:
var %count = $hget(tablename,0).item
while (%count) {
  if ($hget(tablename,%count) >= 4) { do something }
  dec %count
}


If the table gets really big, you may want to consider other options to filter the results. One common option is to save the table to a temp file and use /filter on it to sort the results from high to low. Then you can loop through until the value is < 4 and stop the loop at that point. That may be a little more work, but it cuts down on the number of loops you have to go through. For larger data sets, that's going to be a lot faster. For small data sets like I think yours will be, it really isn't going to matter.


Invision Support
#Invision on irc.irchighway.net
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
don`t wanna seem like a pain and i apreciate ur help very much
but i tried this
if ($did == 8) {
did -r $dname 11
var %count = $hget(TwitchChannelUsers,0).item
while (%count) {
if ($hget(TwitchChannelUsers,%count) >= 4) { did -a $dname 11 $hget(TwitchChannelUsers,%count).item }
dec %count
}
}

and it it isnt loading anything in listbox 11 and in the table there is multiple names that = >4 example

Grim = 5
Reaper = 7
Test = 1
Test2 = 1

is that coded wrong do i need to do soemthing special to get all that = 4 or more into list box 11
if ($hget(TwitchChannelUsers,%count) >= 4) { did -a $dname 11 $hget(TwitchChannelUsers,%count) } ??

Last edited by DaRkCaSTLe1974; 29/05/13 05:23 AM.
Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
Try to use the code tags when posting code - click on the hash symbol (#) immediately above the editbox on the posting form.

Code:
  if ($did == 8) {
    did -r $dname 11
    var %i = 1
    while ($hget(TwitchChannelUsers,%i).data) {
      if ($v1 >= 4) { did -a $dname 11 $hget(TwitchChannelUsers,%i).item }
      inc %i
    }
  }

Deega #241801 29/05/13 07:41 AM
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
i will do that from now on sorry been along time since i scripted and that worked tyvm that also helps get me back to conceptual usage smile
TY both VM

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry, it looks like I forgot .data on my IF. Putting .data on the end of the $hget in the IF statement should also work, just so you can see both ways of looping.

Code:
if ($hget(tablename,%count) >= 4) { do something }


Invision Support
#Invision on irc.irchighway.net
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
need help wrapping results i want this to show like
sample
Qualified User:Name1 has 5 tokens.,Name2 has 5 tokens.,Name3 has 5 tokens.,Name4 has 5 tokens.,End List.
instead of
Qualified User:Name1 has 5 Tokens.
Qualified User:Name2 has 8 Tokens.
Qualified User:Name3 has 9 Tokens.
Qualified User:Name4 has 5 Tokens.

Code:
[/code]

on *:input:*:{
  if (%busywithinput == yes) { halt }
  if ($1 == !tokens) { set %busywithinput yes
    var %i = 1
    while ($hget(TwitchChannelUsers,%i).data) {
      if ($v1 >= 4) { .timer 1 2 msg $active Qualified Users: $+ $hget(TwitchChannelUsers,%i).item has $hget(TwitchChannelUsers,%i).data Tokens. }
      inc %i
    }
    .timer 1 6 .set %busywithinput no
  }
}

[code]

Last edited by DaRkCaSTLe1974; 29/05/13 10:28 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Just add each to a variable. You can append them to a variable (var %variable = %variable newdata), or you can add the data as a token to a variable (var %variable = $addtok(%variable,newdata,tokenchr)). Once you've added everything to the variable (i.e. after the while loop finishes), you msg the variable. Just keep in mind that there is a limit to how much data can be in a variable and how much can be displayed in most locations of mIRC. So unless you know you are going to be under the character limit, you may have to only allow a set number of items per line instead of trying to fit them all into one line. Note: If you limit the number of items per line, you'll need to msg the variable in the while loop whenever it has that number of items, then clear the variable and repeat. At the end (after the loop ends), if anything is remaining in the variable, then you have to msg it there as well.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
Code:
on *:input:*:{
  if ($1 == !tokens) {
    var %i = 1, %a
    while ($hget(TwitchChannelUsers,%i).data) {
      if ($v1 >= 4) { %a =  $addtok(%a,$hget(TwitchChannelUsers,%i).item has $v1 Tokens.,44) }
      inc %i
    }
    if (%a) { msg $active 04Qualified Users: %a :End List. } 
  }
}

Deega #241821 30/05/13 12:15 AM
Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
works like a charm tyvm ^5s

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
ok now i wanna go a bit deeper with what im doing so im wondering how i would for say when i click dialog button it picks random person from hash table whos data = 4 or more like
DaRkCaSTLe = 6
Test1 = 4
Test2 = 3
Test3 = 5

have a pick a random person from DaRkCaSTLe,Test1,Test3
and have it send picked person to dialog edit box

Code:
[/code]


  if ($did == 30) { 
    echo -a Rolling for a Winner!!!!
    timerPickRandomWinnerFromList 1 5 PickRandomWinnerFromList
  }
}

alias PickRandomWinnerFromList {
  pickrandom person from $hget(TwitchChannelUsers,o).item that has 4or more $hget(TwitchChannelUsers,o).data
  set %currentgiveawaywinneris
  did -ra GiveawayTokenController 33 %currentgiveawaywinneris
}

[code]

or what would simply be for picking random from $hget(Tablename,wildcard).item thas 4 or more of $hget(Tablename,wildcard).data

just wanna pick a random from the qualified people and not have it pick same one like a bad loop or something hope i my explanation makes it easy to understand what im lookin for basically a simple random picker from hash table named people whos data is 4 or higher

Last edited by DaRkCaSTLe1974; 30/05/13 03:43 AM.
Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
Just another loop to find the users with 4+ tokens, then grab a random token from the result...
Code:
  var %i = 1, %a
  while ($hget(TwitchChannelUsers,%i).data) {
    if ($v1 >= 4) { %a = %a $hget(TwitchChannelUsers,%i).item }
    inc %i
  }
  if ($numtok(%a,32)) { did -ra GiveawayTokenController 33 $gettok(%a,$rand(1,$v1),32) }

You shouldn't need to set %currentgiveawaywinneris as that info will be in $did(GiveawayTokenController,33)

Joined: May 2013
Posts: 26
D
Ameglian cow
OP Offline
Ameglian cow
D
Joined: May 2013
Posts: 26
i need to know how i would do this

alias AddTokensToDoubleUsers {
var %Dubl = 1
and a while loop that searches all in $chan for people are
$hget(DoubleTokens,$nick) = Double

then hinc CurrentTokenHolders by 1 like if it was
DaRkCaSTLe = 1 in the table increas to DaRkCaSTLe = 2
and search for all in the table Double Tokens only increasing
$hget(CurrentTokenHolders,*) by 1 and only if $hget(DoubleTokens,$nick) = Double

would greatly aprec a loop for such i have tried many diff ways and most of them crash the script ;/

Joined: Oct 2012
Posts: 164
D
Vogon poet
Offline
Vogon poet
D
Joined: Oct 2012
Posts: 164
Code:
alias AddTokensToDoubleUsers {
  var %i = 1, %a
  while ($nick(#,%i)) {
    %a = $v1
    if ($hget(DoubleTokens,%a) == double) { hinc CurrentTokenHolders %a }
    inc %i
  }
}

Page 1 of 2 1 2

Link Copied to Clipboard