mIRC Homepage
Posted By: Deerayn Point system lag - 27/12/15 10:37 PM
Hi, so I have problem with point system, everytime I want to check my points my Mirc lags (don't respond for 10sec~). Maybe points.ini file size is too big? idk smirk

Code:
on *:text:!gold:#:{
  PRIVMSG $nick Tu turi $readini(Points.ini,$+(#,.,$nick),Points) tasku.
}
on !*:join:#:{
  $+(.timerpoints.,#,.,$nick) 0 1800 add.pts $+(#,.,$nick)
  add.pts $+(#,.,$nick)
}
on !*:part:#:$+(.timerpoints.,#,.,$nick) off
alias -l add.pts {
  writeini -n Points.ini $1 Points $calc($readini(Points.ini,$1,Points) + 1)
}
Posted By: westor Re: Point system lag - 28/12/15 03:27 AM
How long is the points.ini database file?
Posted By: nanito Re: Point system lag - 28/12/15 10:24 AM
try to make a echo with your event in the status windows.

these are the steps: (change the *nameofyourchannel* and *yournick* to yours)
1.- Go to the status windows in your mirc
2.- type this:
Code:
//echo -a $readini(Points.ini,$+(*nameofyourchannel*,.,*yournick*),Points)


this will give you your points.

Tell us if your mirc lag with this method.

Nanito
Posted By: Deerayn Re: Point system lag - 28/12/15 01:14 PM
So I noticed that everything related to Points.ini file is lagging, for example if someone buys something with points, Mirc freezes and take some time to respond.

Points.ini
Posted By: Loki12583 Re: Point system lag - 28/12/15 04:50 PM
You're incurring such latency because of the structure of your file. Instead of giving each user their own topic make all the entries items of a single [Points] topic, or at least a topic per channel. You can gain even more speed moving everything into hash tables.

You can use this alias to import your existing file:
Code:
alias points.import {
  if (!$exists(Points.ini)) return

  rename Points.ini Points.old.ini
  filter -k Points.old.ini points.filter *
  unset %prev
}

alias points.filter {
  var %line = $1-
  if (%line == $null) return

  if ($regex(%line,^Points=(\d+))) {
    var %points = $regml(1)

    if ($regex(%prev,/^\[(#.+?)\.(.+?)\]/)) {
      var %chan = $regml(1)
      var %nick = $regml(2)

      add.pts %chan %nick %points
    }
  }

  %prev = %line
}



This is the improved set of code implemented with hash tables. I've removed the line where you immediately gave people points for joining, I know in the past people have exploited this to gain points. There's a 5 second debounce on saving after points have been added, this can be changed to suit your needs or can be removed entirely to rely on the file being saved on exit.
Code:
on *:text:!gold:#:{
  PRIVMSG $nick Tu turi $get.pts(#,$nick) tasku.
}

on !*:join:#:$+(.timerpoints.,#,.,$nick) 0 1800 add.pts # $nick

on !*:part:#:$+(.timerpoints.,#,.,$nick) off

on *:exit:save.pts

alias -l add.pts {
  var %chan = $$1, %nick = $$2, %points = $3, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  hinc %table %nick %points

  .timeradd.pts. $+ %chan 1 5 hsave -i %table %file %chan
}

alias -l get.pts {
  var %chan = $$1, %nick = $$2, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  return $hget(%table,%nick)
}

alias -l load.pts {
  var %table = $1, %file = $2, %topic = $3

  if (!$hget(%table)) {
    hmake %table
    hadd -m points.meta %table %topic
    hsave -i points.meta %file meta

    if ($ini(%file,%topic)) hload -i %table %file %topic
  }
}

alias -l save.pts {
  var %file = Points.ini, %i = 1

  while ($hget(points.meta,%i).item) {
    var %table = $v1, %topic = $hget(points.meta,%table)

    hsave -i %table %file %topic

    inc %i
  }
}
Posted By: Deerayn Re: Point system lag - 28/12/15 06:06 PM
Second script is working, but what I need to do with first one? It doesn't transfer old points to new file. Maybe I do something wrong.

New points saved in old file http://prntscr.com/9jizbb
Posted By: Loki12583 Re: Point system lag - 28/12/15 06:48 PM
All the scripts need to be in the same file (because of the local switch), then call /points.import from the command line. Make sure to call this only on the original Points.ini or edit the file path it's reading from.
Posted By: Deerayn Re: Point system lag - 28/12/15 07:18 PM
Everything works, all commands works without lag, Thanks a lot. But I have last question, is there they to delete all people who is inactive, for example people who have 1 point some period of time.

And I think I need to redo this script to spend points cause Points.ini file was changed.

Code:
on *:text:!permit:#:{
  if ((%floodpermitas) || ($($+(%,floodpermitas.,$nick),2))) { return }
  set -u1 %floodpermitas On
  set -u3 %floodpermitas. $+ $nick On
  var %topic = $+(#,.,$nick)
  if ($readini(Points.ini,%topic,Points) >= 20) {
    var %a = $v1 - 20
    writeini Points.ini %topic Points %a
    hadd -m $+(taskai.,#) $nick 1
    msg $chan !permit $nick
  }

  else msg #  Sry $nick , tu neturi pakankamai tasku. Tau reikia 20 tasku.
}
Posted By: Loki12583 Re: Point system lag - 28/12/15 10:15 PM
Adding a cleanup function required storing last-seen times which required a whole mess of things. I try to keep it as accurate as possible by tracking join, part, disconnect, and exit events. Right now it's set to delete anyone that hasn't been seen in 5 days time.

In general to get points you use $get.pts(#,$nick) and to set use /add.pts # $nick %points. It's a bit of a misnomer but there is already support for negative points, so you can /add.pts somechan somenick -20.

And if you take nothing else, note I've made a correction to the load.pts alias.

Code:
on !*:join:#:{
  $+(.timerpoints.,#,.,$nick) 0 1800 add.pts # $nick

  set.login # $nick
}

on !*:part:#:{
  $+(.timerpoints.,#,.,$nick) off

  set.login # $nick
}

on me:*:join:#:{
  noop $hash.load(login. $+ #,Login.ini,#)
  noop $load.pts(points. $+ #,Points.ini,#)
}

on me:*:part:#:{
  set.login.channel #
}

on *:disconnect:{
  var %i = 1
  while ($chan(%i)) {
    var %chan = $v1, %table = points. $+ %chan

    if ($hget(%table) != $null) {
      set.login.channel %chan
    }
    inc %i
  }
}

on *:exit:{
  save.pts
}

alias clean.pts {
  var %chan = $$1, %login.table = login. $+ %chan, %points.table = points. $+ %chan
  var %login.file = Login.ini, %points.file = Points.ini
  var %limit = 432000, %i = 1
  var %threshold = $ctime - %limit

  noop $hash.load(%login.table,%login.file,%chan)
  noop $load.pts(%points.table,%points.file,%chan)

  while ($hget(%points.table,%i).item) {
    var %nick = $v1, %login = $hget(%login.table,%nick)

    if (%nick ison %chan) || (%login == $null) {
      set.login %chan %nick $ctime
    }
    elseif (%login < %threshold) {
      hdel %login.table %nick
      hdel %points.table %nick
    }

    inc %i
  }

  hsave -i %login.table %login.file %chan
  hsave -i %points.table %points.file %chan
}

alias -l set.login {
  var %chan = $$1, %nick = $$2, %time = $iif($3,$3,$ctime), %table = login. $+ %chan, %file = Login.ini

  if (!$get.pts(%chan,%nick)) return

  noop $hash.load(%table,%file,%chan)

  hadd -m %table %nick %time

  .timerset.login $+ %chan 1 5 hsave -i %table %file %chan
}

alias -l set.login.channel {
  var %chan = $1, %table = login. $+ %chan, %file = Login.ini, %i = 1
  while ($nick(%chan,%i)) {
    set.login %chan $v1 $ctime
    inc %i
  }

  hsave -i %table %file %chan
}

alias -l hash.load {
  var %table = $1, %file = $2, %topic = $3

  if (!$hget(%table)) {
    hmake %table
    if ($ini(%file,%topic)) hload -i %table %file %topic
  }
}

alias -l add.pts {
  var %chan = $$1, %nick = $$2, %points = $3, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  hinc %table %nick %points

  .timeradd.pts. $+ %chan 1 5 hsave -i %table %file %chan
}

alias -l get.pts {
  var %chan = $$1, %nick = $$2, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  return $hget(%table,%nick)
}

alias -l load.pts {
  var %table = $1, %file = $2, %topic = $3

  if (!$hget(%table)) {
    hmake %table
    hadd -m points.meta %table %topic
    hsave -i points.meta %file meta

    if ($ini(%file,%topic)) hload -i %table %file %topic
  }
}

alias -l save.pts {
  var %file = Points.ini, %i = 1

  while ($hget(points.meta,%i).item) {
    var %table = $v1, %topic = $hget(points.meta,%table)

    hsave -i %table %file %topic

    inc %i
  }
}
Posted By: Deerayn Re: Point system lag - 29/12/15 07:34 PM
So I used this
Code:
on *:text:!permitxxx:#:{
  if (%floodpermitas || $($+(%, floodpermitas., $nick), 2)) {
    return
  }
  set -u1 %floodpermitas On
  set -u3 %floodpermitas. $+ $nick On

  if ($readini(points.ini, #, $nick) >= 20) {
    writeini Points.ini # $nick $calc($v1 - 20)
    hadd -m $+(taskai., #) $nick 1
    msg # !permit $nick 
  }

  else {
    msg # Sry $nick $+ , tu neturi pakankamai tasku. Tau reikia 20 tasku.
  }
}

So its little bit weird, and hard to explain, from start I was thinking everything is working, but I noticed that, then I check points with "!taskai" command its say same thing, I don't lose 20 points for using command, and points doesn't grow any more

update: So I noticed that, I have 5 points, I use command "!permitxxx" (cost 5), it works, I looked up "Points.ini" file its says I have 0, and then I gain 1 point for being in chat and its says I have 6 points.
Posted By: Loki12583 Re: Point system lag - 29/12/15 08:34 PM
Do not access the ini file directly, use the hash table functions I have provided.
Posted By: Deerayn Re: Point system lag - 30/12/15 12:42 PM
Thanks a lot to Loki12583

And this is working script if someone will have similar problem.

Code:
alias points.import {
  if (!$exists(Points.ini)) return

  rename Points.ini Points.old.ini
  filter -k Points.old.ini points.filter *
  unset %prev
}

alias points.filter {
  var %line = $1-
  if (%line == $null) return

  if ($regex(%line,^Points=(\d+))) {
    var %points = $regml(1)

    if ($regex(%prev,/^\[(#.+?)\.(.+?)\]/)) {
      var %chan = $regml(1)
      var %nick = $regml(2)

      add.pts %chan %nick %points
    }
  }

  %prev = %line
}
on *:text:!taskai:#:{
  if (%floodtaskai || $($+(%, floodtaskai., $nick), 2)) {
    return
  }
  set -u3 %floodtaskai On
  set -u45 %floodtaskai. $+ $nick On

  PRIVMSG $nick Tu turi $get.pts(#,$nick) tasku.
}
on !*:join:#:{
  $+(.timerpoints.,#,.,$nick) 0 1800 add.pts # $nick

  set.login # $nick
}

on !*:part:#:{
  $+(.timerpoints.,#,.,$nick) off

  set.login # $nick
}

on me:*:join:#:{
  noop $hash.load(login. $+ #,Login.ini,#)
  noop $load.pts(points. $+ #,Points.ini,#)
}

on me:*:part:#:{
  set.login.channel #
}

on *:disconnect:{
  var %i = 1
  while ($chan(%i)) {
    var %chan = $v1, %table = points. $+ %chan

    if ($hget(%table) != $null) {
      set.login.channel %chan
    }
    inc %i
  }
}

on *:exit:{
  save.pts
}

alias clean.pts {
  var %chan = $$1, %login.table = login. $+ %chan, %points.table = points. $+ %chan
  var %login.file = Login.ini, %points.file = Points.ini
  var %limit = 432000, %i = 1
  var %threshold = $ctime - %limit

  noop $hash.load(%login.table,%login.file,%chan)
  noop $load.pts(%points.table,%points.file,%chan)

  while ($hget(%points.table,%i).item) {
    var %nick = $v1, %login = $hget(%login.table,%nick)

    if (%nick ison %chan) || (%login == $null) {
      set.login %chan %nick $ctime
    }
    elseif (%login < %threshold) {
      hdel %login.table %nick
      hdel %points.table %nick
    }

    inc %i
  }

  hsave -i %login.table %login.file %chan
  hsave -i %points.table %points.file %chan
}

alias -l set.login {
  var %chan = $$1, %nick = $$2, %time = $iif($3,$3,$ctime), %table = login. $+ %chan, %file = Login.ini

  if (!$get.pts(%chan,%nick)) return

  noop $hash.load(%table,%file,%chan)

  hadd -m %table %nick %time

  .timerset.login $+ %chan 1 5 hsave -i %table %file %chan
}

alias -l set.login.channel {
  var %chan = $1, %table = login. $+ %chan, %file = Login.ini, %i = 1
  while ($nick(%chan,%i)) {
    set.login %chan $v1 $ctime
    inc %i
  }

  hsave -i %table %file %chan
}

alias -l hash.load {
  var %table = $1, %file = $2, %topic = $3

  if (!$hget(%table)) {
    hmake %table
    if ($ini(%file,%topic)) hload -i %table %file %topic
  }
}

alias -l add.pts {
  var %chan = $$1, %nick = $$2, %points = $3, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  hinc %table %nick %points

  .timeradd.pts. $+ %chan 1 5 hsave -i %table %file %chan
}

alias -l get.pts {
  var %chan = $$1, %nick = $$2, %table = points. $+ %chan, %file = Points.ini

  noop $load.pts(%table,%file,%chan)

  return $hget(%table,%nick)
}

alias -l load.pts {
  var %table = $1, %file = $2, %topic = $3

  if (!$hget(%table)) {
    hmake %table
    hadd -m points.meta %table %topic
    hsave -i points.meta %file meta

    if ($ini(%file,%topic)) hload -i %table %file %topic
  }
}

alias -l save.pts {
  var %file = Points.ini, %i = 1

  while ($hget(points.meta,%i).item) {
    var %table = $v1, %topic = $hget(points.meta,%table)

    hsave -i %table %file %topic

    inc %i
  }
}

on *:text:!permit:#:{
  if (%floodpermitas || $($+(%, floodpermitas., $nick), 2)) {
    return
  }
  set -u10 %floodpermitas On
  set -u45 %floodpermitas. $+ $nick On

  if ($get.pts(#,$nick) >= 20) {
    add.pts # $nick -20)
    hadd -m $+(taskai., #) $nick 1
    msg # !permit $nick
  }

  else {
    msg # Sry $nick $+ , tu neturi pakankamai tasku. Tau reikia 20 tasku.
  }
}
on *:text:!pirkti permit:#:{
  if (%floodpermitas2 || $($+(%, floodpermitas2., $nick), 2)) {
    return
  }
  set -u10 %floodpermitas2 On
  set -u45 %floodpermitas2. $+ $nick On

  if ($get.pts(#,$nick) >= 20) {
    add.pts # $nick -20)
    hadd -m $+(taskai., #) $nick 1
    msg # !permit $nick
  }

  else {
    msg # Sry $nick $+ , tu neturi pakankamai tasku. Tau reikia 20 tasku.
  }
}
© mIRC Discussion Forums