Personally, I'd prefer to store the data in a single, physical file, in a chart format. As long as you're going to calculate one user a time, there's no noticeable performance gain with hash tables.
Even for batch calculation, sorting of lists etc you could load the file into memory as required, or use other fast means like the /filter command.
But if you prefer the two hash tables - fine with me. smile

However, I would'nt store the gift rules in your current way ("categories" with one or more gifts assigned each). Adding/changing/removing rules would mean to update multiple lines and could become tricky if your set of rules grows. Again, I'd prefer a more basic form: a chart.

As each gift has to meet some criteria (rating, ranking, (age), (...)), and as long as the general idea is "you have to match ALL critera of a gift to get it" and a user has to have AT LEAST xxx to match a criterion, why not create a file like:
Originally Posted By: giftrules.ini

[rules]
1=0 0
2=5 50
3=5 100
4=6 20
5=6 500
6=6 1000
The item name is the gift number, the data part contains all threshold values: the first column the required rating, the second column the required ranking. You can add more columns for more criteria as you like in the future, and the chart is easy to maintain.

A script could now while-loop over all rules with $readini. But as you like to work with hash tables, you can load this ini file into a table with
Code:
alias loadrules {
  if ($hget(gift.rules)) { hfree gift.rules }
  hmake gift.rules
  hload -i gift.rules giftrules.ini rules
}


Now the main part. Below's a basic commented outline for the check-alias. I hope you get the idea - feel free to ask though smile
You could also add some general checks to it:
- Tables "gift.rules", "rating" and "ranking" loaded?
- Parameter (user) given at all?
- User listed at all?
Code:
alias check {
  ; set an empty variable to store matching gifts, set rule-No counter to 1
  var %gifts, %ruleNo = 1

  ; loop all rules
  while ($hget(gift.rules,%ruleNo) != $null) {

    ; $gettok($v1,1,32) = required rating to get this gift, $gettok($v1,2,32) = required ranking 
    ; (if you create more columns, create variables accordingly)
    var %rule.rating = $gettok($v1,1,32), %rule.ranking = $gettok($v1,2,32)

    ; compare user's values to required values:
    ; "if <rating of name> is bigger than <required rating> AND <ranking of name> is bigger than <required ranking>"
    ; (if you create more columns, add conditions accordingly)
    if ($hget(rating,$1) > %rule.rating) && ($hget(ranking,$1) > %rule.ranking) {

      ; all conditions met: add the current gift to the string of matching gifts
      var %gifts = $addtok(%gifts,gift_ $+ %ruleNo,59)
    }

    ; continue with next rule
    inc %ruleNo
  }

  ; all rules processed: output result
  ECHO -a $1 will be given : %gifts
}


For testing, I created some users with your /addname command:
Code:
/addname Name1 5.2 153
/addname Name2 6.5 70
/addname Name3 8 300
/addname Name4 0.8 1000
/addname Name5 9 25

And my /check results are:
Quote:
Name1 will be given : gift_1;gift_2;gift_3
Name2 will be given : gift_1;gift_2;gift_4
Name3 will be given : gift_1;gift_2;gift_3;gift_4
Name4 will be given : gift_1
Name5 will be given : gift_1;gift_4

Last edited by Horstl; 14/01/11 12:42 AM.