Page 1 of 1

/random sorter

Posted: Fri Jun 11, 2004 1:18 am
by Caladine
This macro reads and sorts randoms based on the final value of the random, but the range is also stored. It ignores multiple randoms from the same individual, and you can choose to specify a range of randoms to accept also.

Code: Select all

|****************************************************************************|
| rand.mac                                                                   |
| sort those annoying randoms messages!                                      |
|****************************************************************************|
|
| /echo start - to start reading randoms
| /echo list - to list the current set of randoms, sorted
| /echo clear - clear the list of randoms
| /echo stop - stop reading randoms
|
| syntax:
| /macro rand low_value high_value
|   Will only record randoms that fit the range if they match
|   the supplied range. if a range is not supplied it'll take
|   any range random

#event start "[MQ2] start"
#event list "[MQ2] list"
#event stop "[MQ2] stop"
#event clear "[MQ2] clear"
#event name "**A magic die is rolled by #1#."
#event number "**It could have been any number from #1# to #2#, but this time it turned up a #3#."

sub Main(int low_value, int high_value)
  /declare lname string outer UNDEFINED
  /declare randoms[100,4] int outer -1
  /declare start bool outer FALSE
  /declare nset bool outer FALSE
  /declare nptr int outer 1
  /declare lval int outer
  /declare hval int outer
  
  /if((${low_value}==NULL) || (${high_value}==NULL)) /varset set TRUE
  :loopforever
    /doevents start
    /doevents list
    /doevents clear
    /if (${start}) /doevents
  /goto :loopforever
/return

sub EVENT_start
  /echo Starting reading randoms.
  /varset start TRUE
  /doevents flush
/return

sub EVENT_stop
  /echo Stopping reading randoms.
  /varset start FALSE
/return

sub EVENT_clear
  /declare i int local
  /echo Clearing random list.
  /for i 1 to 100
    /varset randoms[${i},1] -1
    /varset randoms[${i},2] -1
    /varset randoms[${i},3] -1
    /varset randoms[${i},4] -1
  /next i
  /varset nptr 1
/return

sub EVENT_list
  /declare lptr int local -1
  /declare act int local -1
  /declare disp[100] int local -1
  /declare i int local 1
  /declare j int local 1
  
  /echo Listing randoms:
  /for i 1 to 100
    /varset act -1
    /varset lptr -1
    /for j 1 to 100
      /if (${disp[${j}]}==-1) /if (${randoms[${j},2]}>${act}) /multiline ; /varset lptr ${j} ; /varset act ${randoms[${j},2]}
    /next j
    /if (${lptr}==-1) /goto :DoneList
    /echo ${Spawn[${randoms[${lptr},1]}]}: ${randoms[${lptr},2]} on ${randoms[${lptr},3]} to ${randoms[${lptr},4]}
    /varset disp[${lptr}] 0
  /next i
  :DoneList
/return

sub EVENT_name(string line, string name)
  /varset lname ${name}
/return

sub EVENT_number(string line, int low, int high, int actual)
  /declare spawnid int local
  /declare i int local
  /varset spawnid ${Spawn[pc ${lname}].ID}
  /echo ${lname} - ${low} to ${high}: ${actual}
  
  /if (${nset}) /goto :CheckName
  /if ((${low}!=${lval}) && (${high}!=${hval})) /return

  :CheckName
  /for i 1 to 100
    /if (${randoms[${i},1]}==-1) /goto :Add
    /if (${randoms[${i},1]}==${spawnid}) /return
  /next i
  
  :Add
  /varset randoms[${nptr},1] ${spawnid}
  /varset randoms[${nptr},2] ${actual}
  /varset randoms[${nptr},3] ${low}
  /varset randoms[${nptr},4] ${high}
  /varcalc nptr ${nptr}+1
/return

Posted: Fri Jun 11, 2004 2:47 am
by Teh_ish
Very groovy for us casinomen. MIght I suggest moving the commands to /(command) instead of the echos? :)

Posted: Sun Jun 13, 2004 12:05 am
by Caladine
The only way for me to move it to a /command would be to make a plugin out of this, which I wouldn't be adverse to doing... if enough people wanted that.

Posted: Sun Jun 13, 2004 11:06 pm
by puterbot
i would love to see this as a plugin

Posted: Mon Jun 14, 2004 5:53 am
by Pheph
Teh_ish wrote:Very groovy for us casinomen. MIght I suggest moving the commands to /(command) instead of the echos? :)
Don't tell me you're one of those retards, please...

Posted: Tue Jun 15, 2004 6:29 am
by Caladine
The only retards are the ones that play the "casinos".

Note: I don't run one, but I find it handy when half the raid is /randoming on a GoD rune. :wink: