Advertisement
ilde

broken MajorTimer

Apr 29th, 2013
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 49.68 KB | None | 0 0
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <!DOCTYPE muclient>
  3. <!-- Original by Garrion  -->
  4. <!-- Version 3.0 by Ilde, built upon version 2.1 -->
  5. <!-- MuClient version 4.40 -->
  6. <!--
  7.  
  8. This plugin keeps track of how much Major Shield you have.  "help majortimer" will display a helpfile with available commands.  It's fine to make your own version of this plugin or use parts of it.
  9.  
  10. -->
  11.  
  12. <muclient>
  13. <plugin
  14.  name="MajorTimer"
  15.  author="Ilde"
  16.  id="f6685da86910795e76a1884b"
  17.  language="Lua"
  18.  purpose="Shows time remaining on Major shield"
  19.  save_state="y"
  20.  date_written="2013-04-28 10:45:35"
  21.  requires="4.40"
  22.  version="3.0"
  23.  >
  24. <description trim="y">
  25. <![CDATA[
  26. Shows the time remaining on your major shield.
  27. ]]>
  28. </description>
  29. </plugin>
  30.  
  31.  
  32.  
  33. <!--  Triggers  -->
  34. <triggers>
  35.   <trigger
  36.   enabled="y"
  37.   match="You are protected by the power of *."
  38.   name="major_up"
  39.   script="Add_Timer"
  40.   send_to="12"
  41.   sequence="100"
  42. >
  43.   </trigger>
  44.  
  45.   <trigger
  46.   enabled="y"
  47.   ignore_case="y"
  48.   match="^your (divine protection|protective aura) has been (strengthened|extended|weakened)\.$"
  49.   name="major_extend"
  50.   script="Add_Timer"
  51.   regexp="y"
  52.   sequence="100"
  53. >
  54.   </trigger>
  55.  
  56.   <!-- These next two signal that you failed the ritual, OR the ritual was on someone else.  In either case the ritual modifiers become irrelevant. -->
  57.   <trigger
  58.   enabled="y"
  59.   ignore_case="y"
  60.   match="^((.*) loses interest in your ritual\.|You sense (.*)'s attention is elsewhere.).$"
  61.   name="major_fail"
  62.   script="Canceled"
  63.   regexp="y"
  64.   sequence="100"
  65. >
  66.   </trigger>
  67.  
  68.   <trigger
  69.   enabled="y"
  70.   ignore_case="y"
  71.   match="^((.*) is protected by the power of (.*)|(Its|His|Her) divine protection has been (extended|strengthened|weakened)\.)$"
  72.   name="major_on_another"
  73.   script="Canceled"
  74.   regexp="y"
  75.   sequence="100"
  76. >
  77.   </trigger>
  78.  
  79.   <trigger
  80.   enabled="y"
  81.   ignore_case="y"
  82.   match="^ ?\* You are ((barely |really |perfectly )?protected by the power of|shielded by the protective armour of) (.*)\.  You will be protected for (.*)\.$"
  83.   name="shield_check"
  84.   script="Adjust_Timer"
  85.   regexp="y"
  86.   sequence="100"
  87. >
  88.   </trigger>
  89.  
  90.   <trigger
  91.   enabled="y"
  92.   match="Your divine protection expires."
  93.   name="major_down"
  94.   script="Clear_Timer"
  95.   sequence="100"
  96. >
  97.   </trigger>
  98.  
  99.  
  100.   <trigger
  101.   enabled="y"
  102.   match="You do not have any arcane protection."
  103.   name="no_major"
  104.   script="Clear_Timer"
  105.   sequence="100"
  106. >
  107.   </trigger>
  108.  
  109.   <!-- Message for the various ritual bonuses and penalties. -->
  110.   <trigger
  111.   enabled="y"
  112.   ignore_case="y"
  113.   match="^(It seems|You are finding it|You find it) (.*) to perform major shield because (.*)\.$"
  114.   name="modifier_check"
  115.   script="adjust_bonus"
  116.   regexp="y"
  117.   sequence="100"
  118. >
  119.   </trigger>
  120.  
  121.  
  122.   <!-- Message when you've just logged in.-->
  123.   <trigger
  124.   enabled="y"
  125.   ignore_case="y"
  126.   match="You last logged in from * and are currently logged in from *."
  127.   name="logged_on"
  128.   script="Unpause_Timer"
  129.   sequence="100"
  130. >
  131.   </trigger>
  132.  
  133.   <!-- Message for logging in after disconnecting but not quitting or idling out -->
  134.   <trigger
  135.   enabled="y"
  136.   ignore_case="y"
  137.   match="You are already playing."
  138.   name="logged_on_already_playing"
  139.   script="Already_Playing"
  140.   sequence="100"
  141. >
  142.   </trigger>
  143.  
  144.   <!-- Message indicating the next thing you enter will be your character name.-->
  145.   <trigger
  146.   enabled="y"
  147.   ignore_case="y"
  148.   match="Or, enter your current character's name"
  149.   name="about_to_log_in"
  150.   script="Enter_Name"
  151.   sequence="100"
  152. >
  153.   </trigger>
  154.  
  155.   <!-- Message indicating the next thing you enter will be your password.  Makes the alias to capture stuff turn OFF.-->
  156.   <trigger
  157.   enabled="y"
  158.   ignore_case="y"
  159.   match="                     Where all your dreams can't come true."
  160.   name="about_to_enter_pass"
  161.   script="Enter_Password"
  162.   sequence="100"
  163. >
  164.   </trigger>
  165.  
  166.    
  167.    <!-- shouldn't need this anymore  -->
  168.   <trigger
  169.   enabled="n"
  170.   ignore_case="y"
  171.   match="^You are (Miss |Mr |Mrs |Ms |Lonely |Mournful |Scary |Spooky |Wandering |Cheating |Cowardly |Brother |Sister |Mostly Reverend |Reverend |Blessed |Blessed father |Blessed mother |Blessed brother |Blessed sister |Venerable |Venerable brother |Venerable sister |Venerable father |Venerable mother |Holy |Holy brother |Holy sister |Beatus |Saint |Butterfingers |Crafty |Crooked |Dastardly |Dishonest |Dodgy |Elusive |Evasive |Fingers |Furtive |Greased |Honest |Latent |Light-fingered |Quick-fingered |Quiet |Shady |Shifty |Silent |Slick |Sly |Tricky |Aunty |Biddy |Black |Gammer |Goodie |Goody |Gramma |Granny |Mama |Mistress |Mother |Mss |Nanna |Nanny |Old |Sister |Wee |Wicked |Young |Fat |Stuffed |Over-fed |Gimlet-eyed |Robust |Bearded |Burly |Plump |Rotund |Thin |Tiny |Mystic |Obscure |Complex |Learned |Potent |Wise |Grumpy |Cryptic |Dark |Scholarly |Grey-haired |Greybeard |Master |Mistress |Adroit |Dire |Maven |Quantum |Savant |Unseen |Archmaster |mistress |Archmage |Dame |Sir |the Amazing |the Civic-Minded |the Elegant |the Eloquent |the Helpful |the Helpful Citizen |the Stylish |the Upstanding Citizen |the Utterly Fluffy |the Wonderful |appallingly filthy |corpse looter |dull |feebleminded |i got punished |i got punished and all i got was this lousy title |i promise i won't do it again |insignificant |lying |malingering |naughty spawn |necrokleptomaniac |offensive |pillock |pointless |repentant |reprobate |shopkeeper murderer |silly spammy git |sitting in the corner |smelly |tantrum thrower |too stupid to live |vagrant |very sorry |very very sorry |waste of space |whinging |Sultan |Sultana |Shai |Sitt al-khasa |Shai |Sitt al-ri'asa |Shai |Sitt ishquaraya |Shai |Sitt a'daha |Nawab |Qasar |Mazrat |Effendi |Ya'uq |Mutasharid |Ishqaraya |Naughty Spawn |Kill Stealer |Feebleminded |Idiotic |Offensive |Corpse Looter |Cat Hating |Heathen |Foreign Dog |Infidel |Shopkeeper Murderer |Destitute |Parasitic |Hated |Cowardly |Criminal |Felon |M |Mlle |Mme |Contender |Venomous |Ancient |Exterminator |Rouge |Axe-master |Champion |Centurion |Flatulent |Competent |Cultured |Healer |Cutthroat |Knifey |Archaic |Lethal |Elementalist |Energetic |Festive |Gifted |Chef |Impaler |Templar |Paranoid |Saintly |Crusher |Mysterious |Arcana |Duelist |Perverse |Masterful |Fingers |Medical |Destined |Unburiable |Nasty |Nimble |Nurse |Murse |Obsolete |Old Woman |Old Man |Old |Crimewave |Antiquated |Fossilized |Mythical |Unlucky |Pious |Staffmistress |Staffmaster |Prehistoric |Rock-hard |Bruiser |Pulveriser |Literate |Wealthy |Senile |Shieldmistress |Shieldmaster |Filthy |Erratic Mechanic |Legendary |Swordmistress |Swordmaster |Terrible |Ruinous |Decrepit |Player Of Games |Headmistress |Headmaster |Multilingual |Golden |Unexpected |Unstoppable |Versatile |Virtuoso |Venerable |Opulent )?([a-z]+) ([a-z]+ )?the (.*)\.$"
  172.   name="whoami"
  173.   script="Set_Character_From_Whoami"
  174.   regexp="y"
  175.   sequence="100"
  176. >
  177.   </trigger>
  178.  
  179.  
  180.   <!-- Messages you get when you quit, shout 8, or idle out.-->
  181.   <trigger
  182.   enabled="y"
  183.   ignore_case="y"
  184.   match="^(Do come again!|Thanks for playing.  See you next time.|You idled out, sorry.)$"
  185.   name="logged_off"
  186.   script="Pause_Timer"
  187.   regexp="y"
  188.   sequence="100"
  189. >
  190.   </trigger>
  191.  
  192.   <!-- Skills output.  Used to set bonus.-->
  193.   <trigger
  194.   enabled="n"
  195.   ignore_case="y"
  196.   match="faith.rituals.defensive.self    *   *"
  197.   name="skills"
  198.   script="Set_Bonus_From_Skills"
  199.   sequence="100"
  200. >
  201.   </trigger>
  202.  
  203.  
  204. </triggers>
  205.  
  206. <!--  Aliases  -->
  207. <aliases>
  208.   <alias
  209.   match="mtreset"
  210.   enabled="y"
  211.   send_to="12"
  212.   script="Force_Reset_Timer"
  213.   name="force_reset"
  214.   sequence="100"
  215. >
  216.   </alias>
  217.  
  218.   <alias
  219.   match="mtset *"
  220.   enabled="y"
  221.   send_to="12"
  222.   script="set_bonus"
  223.   name="set_length"
  224.   sequence="100"
  225. >
  226.   </alias>
  227.  
  228.   <alias
  229.   match="mtadd *"
  230.   enabled="y"
  231.   send_to="12"
  232.   script="Man_Add_Timer"
  233.   name="force_add"
  234.   sequence="100"
  235. >
  236.   </alias>
  237.  
  238.   <alias
  239.   match="mtminus *"
  240.   enabled="y"
  241.   send_to="12"
  242.   script="Man_Minus_Timer"
  243.   name="force_minus"
  244.   sequence="100"
  245. >
  246.   </alias>
  247.  
  248.   <alias
  249.   match="mtchar *"
  250.   enabled="y"
  251.   send_to="12"
  252.   script="Man_Set_Character"
  253.   name="set_char"
  254.   sequence="100"
  255. >
  256.   </alias>
  257.  
  258.   <alias
  259.   enabled="y"
  260.   ignore_case="y"
  261.   match="help majortimer"
  262.   name="helpmajor"
  263.   send_to="12"
  264.   sequence="100">
  265.     <send>print_help()</send>
  266.   </alias>
  267.  
  268.  
  269.   <alias
  270.   match="su *"
  271.   enabled="y"
  272.   send_to="12"
  273.   script="Switch_User"
  274.   name="su"
  275.   sequence="100"
  276. >
  277.   </alias>
  278.  
  279.   <!-- Commands to, respectively, turn the whoami alias on and off. -->
  280.   <alias
  281.   match="mtwhoami on"
  282.   enabled="y"
  283.   send_to="12"
  284.   script="Whoami_On"
  285.   name="whoamion"
  286.   sequence="100"
  287. >
  288.   </alias>
  289.  
  290.   <alias
  291.   match="mtwhoami off"
  292.   enabled="y"
  293.   send_to="12"
  294.   script="Whoami_Off"
  295.   name="whoamioff"
  296.   sequence="100"
  297. >
  298.   </alias>
  299.  
  300.   <!-- Commands to, respectively, turn the skills alias on and off. -->
  301.   <alias
  302.   match="mtskills on"
  303.   enabled="y"
  304.   send_to="12"
  305.   script="Skills_On"
  306.   name="skillson"
  307.   sequence="100"
  308. >
  309.   </alias>
  310.  
  311.   <alias
  312.   match="mtskills off"
  313.   enabled="y"
  314.   send_to="12"
  315.   script="Skills_Off"
  316.   name="skillsoff"
  317.   sequence="100"
  318. >
  319.   </alias>
  320.  
  321.   <!-- Commands to, respectively, turn verbose mode on and off. -->
  322.   <alias
  323.   match="mtverbose on"
  324.   enabled="y"
  325.   send_to="12"
  326.   script="Verbose_On"
  327.   name="verboseon"
  328.   sequence="100"
  329. >
  330.   </alias>
  331.  
  332.   <alias
  333.   match="mtverbose off"
  334.   enabled="y"
  335.   send_to="12"
  336.   script="Verbose_Off"
  337.   name="verboseoff"
  338.   sequence="100"
  339. >
  340.   </alias>
  341.  
  342.   <alias
  343.   match="mtverbose debug"
  344.   enabled="y"
  345.   send_to="12"
  346.   script="Verbose_Debug"
  347.   name="verbosedebug"
  348.   sequence="100"
  349. >
  350.   </alias>
  351.  
  352.   <!-- Command to add one performance's worth of shielding to the timer. -->
  353.   <alias
  354.   match="mtaddone"
  355.   enabled="y"
  356.   send_to="12"
  357.   script="Add_Timer"
  358.   name="mtaddone"
  359.   sequence="100"
  360. >
  361.   </alias>
  362.  
  363.   <!-- Command to reset the timer to zero. -->
  364.   <alias
  365.   match="mtclear"
  366.   enabled="y"
  367.   send_to="12"
  368.   script="Clear_Timer"
  369.   name="mtclear"
  370.   sequence="100"
  371. >
  372.   </alias>
  373.  
  374.   <!-- This is ONLY turned on when it sees the text indicating the next thing you enter will be your username. -->
  375.   <alias
  376.   match="*"
  377.   enabled="n"
  378.   send_to="12"
  379.   script="Login"
  380.   name="login_name"
  381.   sequence="100"
  382. >
  383.   </alias>
  384. </aliases>
  385.  
  386. <!--  Timers  -->
  387. <timers>
  388.   <timer
  389.   script="show_time"
  390.   enabled="y"
  391.   second="1.00"
  392.   >
  393.   </timer>
  394. </timers>
  395.  
  396. <!--  Script  -->
  397. <script>
  398. <![CDATA[
  399.  
  400. require "serialize"
  401.  
  402. active = ""
  403.  
  404.  
  405. --function to set your bonus manually, triggered by the mtset alias
  406. function set_bonus (name, line, wildcards)
  407. bonus = wildcards[1]
  408. Save_Setting ("bonus", bonus)
  409. if verbose == "on" or verbose == "debug" then
  410.   Note("Bonus set to ", bonus, ", which gives you a base duration of ", bonus_to_duration(bonus), " seconds.")
  411. end --if
  412. --SetChanged (true)  -- world has changed... this doesn't seem necessary after all?
  413. end -- set_bonus
  414.  
  415. --function to set your bonus from skills output
  416. function Set_Bonus_From_Skills (name, line, wildcards)
  417. bonus = wildcards[2]
  418. Save_Setting ("bonus", bonus)
  419. if verbose == "on" or verbose == "debug" then
  420.   Note("Bonus set from skills output to ", bonus, ", which gives you a base duration of ", bonus_to_duration(bonus), ".")
  421. end --if
  422. end --Set_Bonus_From_Skills
  423.  
  424. --function to calculate the duration (seconds) to add from the bonus specified
  425. function bonus_to_duration (current_bonus)
  426. return 2 * math.floor(((400 * (math.log(current_bonus + 75)) - 2082.5) / 2) + .5)
  427. end -- bonus_to_duration
  428.  
  429.  
  430. --function to add more time to the timer when it sees the extended/protected messages
  431. function Add_Timer ()
  432. active = "yes"
  433. Save_Setting("active", active)
  434.  
  435. --These next two: need to make sure that when it tries to do math on effective bonus, it actually EXISTS.  If not, set both to the default.
  436. if bonus then
  437. --do nothing
  438. else
  439.   bonus = 307
  440. end --if
  441. if effective_bonus then
  442. --do nothing
  443. else
  444.   effective_bonus = bonus
  445. end --if
  446.  
  447.  
  448. --calculate actual seconds to be added
  449. time_to_add = bonus_to_duration(effective_bonus)
  450.  
  451. --if the finish time already exists we can just add the time to it.  Otherwise, create it as the os time plus the time to add.
  452. if finish_time and finish_time ~= "" then
  453.   finish_time = finish_time + time_to_add
  454. else
  455.   finish_time = os.time () + time_to_add
  456. end -- if
  457.  
  458. if verbose == "debug" then
  459.   Note(time_to_add, " seconds added.")
  460. end --if
  461.  
  462. --finally, save the finish time for pause/unpause purposes, reset the effective bonus to the base, and do the window
  463. Save_Setting ("finish_time", finish_time)
  464. effective_bonus = bonus
  465. show_time ()
  466. end -- Add_Timer
  467.  
  468.  
  469. --function to reset the timer to one performance's worth
  470. function Force_Reset_Timer ()
  471.   finish_time = os.time ()
  472.   Add_Timer ()
  473. end -- Force_Reset_Timer
  474.  
  475.  
  476. --function to manually add a specified number of minutes, triggered by the mtadd alias
  477. function Man_Add_Timer (name, line, wildcards)
  478. if finish_time and finish_time ~= "" then
  479.   finish_time = finish_time + (wildcards[1]*60)
  480.   show_time ()
  481. else
  482.   active = "yes"
  483.   Save_Setting ("active", active)
  484.   finish_time = os.time () + (wildcards[1]*60)
  485.   show_time ()
  486. end -- if
  487. Note(wildcards[1] .. "mins added to your timer.")
  488. Save_Setting ("finish_time", finish_time)
  489. end -- Man_Add_Timer
  490.  
  491.  
  492. --function to manually subtract a specified number of minutes, triggered by the mtminus alias
  493. function Man_Minus_Timer (name, line, wildcards)
  494. if finish_time and finish_time ~= "" then
  495.   finish_time = finish_time - (wildcards[1]*60)
  496.   show_time ()
  497. else
  498.   active = ""
  499.   Save_Setting ("active", active)
  500.   finish_time = ""
  501.   show_time ()
  502. end -- if
  503. Note(wildcards[1] .. "mins removed from your timer.")
  504. Save_Setting ("finish_time", finish_time)
  505. end -- Man_Minus_Timer
  506.  
  507. --function to reset the duration, triggered by failure message, stopping the ritual, performing on someone ELSE, or target leaving.
  508. function Canceled ()
  509. --reset the effective bonus because any ritual modifier message you may have gotten is now irrelevant
  510. effective_bonus = bonus
  511. end -- Canceled
  512.  
  513.  
  514. --a function to check what visible ritual modifiers you have and adjust the duration accordingly.
  515. function adjust_bonus (name, line, wildcards)
  516. effective_bonus = bonus
  517. modifiers = wildcards[3]
  518. text_difficulty = wildcards[2]
  519. ritual_bonuses = 0
  520. ritual_penalties = 0
  521. bonuses_text = "Ritual bonuses detected: "
  522. penalties_text = "Ritual penalties detected: "
  523.  
  524. --messages common to all
  525.   --prayed recently
  526.   if string.find(modifiers, "you have been actively worshipping") then
  527.       effective_bonus = effective_bonus + 7
  528.       ritual_bonuses = ritual_bonuses + 7
  529.       bonuses_text = bonuses_text .. "prayed or ritburied, "
  530.   end -- if
  531.   --deity pool settings
  532.   if string.find(modifiers, "the hand of") then
  533.       --It's 3 points for 1%.  This is very rarely used, however, because it drains the pool so quickly, and so it will probably be at 1% if it's on at all.  The highest setting, "10%", actually drains 1 dp per gp spent, so even the "1%" setting probably actually drains 10% of gp spent.  Really can't see anybody ever setting it higher.
  534.       effective_bonus = effective_bonus + 3
  535.       ritual_bonuses = ritual_bonuses + 3
  536.       bonuses_text = bonuses_text .. "deity pool settings (presumed 1%), "
  537.   end -- if
  538.   --other high altar OR high altar... the "other high altar" message is confusable with the "at high altar" message, so do this.
  539.   if string.find(modifiers, "you are in an area consecrated to another God") then
  540.       effective_bonus = effective_bonus - 45
  541.       ritual_penalties = ritual_penalties - 45
  542.       penalties_text = penalties_text .. "at wrong high altar, "
  543.   elseif string.find(modifiers, "you are in a") then
  544.       effective_bonus = effective_bonus + 12
  545.       ritual_bonuses = ritual_bonuses + 12
  546.       bonuses_text = bonuses_text .. "at high altar, "
  547.   end -- if
  548.   --near high altar, this varies
  549.   if string.find(modifiers, "you are near") then
  550.       --This bonus actually ranges from +3 (just barely inside the zone where you get a bonus at all) to +9(right outside an altar).  I've arbitrarily put it at +6 since most of the time when you're getting this, you'll be in the same city as an altar but probably not right outside.  So, a middling value seems appropriate.
  551.       effective_bonus = effective_bonus + 6
  552.       ritual_bonuses = ritual_bonuses + 6
  553.       bonuses_text = bonuses_text .. "near high altar, "
  554.   end -- if
  555.   --witch/wizard property
  556.   if string.find(modifiers, "you sense that the gods have averted their eyes from this place") then
  557.       effective_bonus = effective_bonus - 45
  558.       ritual_penalties = ritual_penalties - 45
  559.       penalties_text = penalties_text .. "on witch or wizard property, "
  560.   end -- if
  561.   --minions
  562.   if string.find(modifiers, "you are concentrating on") then
  563.       penalties_text = penalties_text .. "minions ("
  564.       num_minions = 0
  565.      
  566.       --it's POSSIBLE that there could be multiple of the same type of whirlwind ("controlling two gigantic whirlwinds of dust") or spectre.  Also, in darkness, there can be "controlling two things".  Look for number words and count them.
  567.       if string.find(modifiers, " two ") then
  568.           modifiers, num_identicals = string.gsub(modifiers, " two ", "")
  569.           num_minions = num_minions + (num_identicals * 2)
  570.           penalties_text = penalties_text .. num_identicals .. " set(s) of two identical-looking minions. "
  571.       end --if
  572.       if string.find(modifiers, " three ") then
  573.           modifiers, num_identicals = string.gsub(modifiers, " three ", "")
  574.           num_minions = num_minions + (num_identicals * 3)
  575.           penalties_text = penalties_text .. num_identicals .. " set(s) of three identical-looking minions, "
  576.       end --if
  577.       if string.find(modifiers, " four ") then
  578.           modifiers, num_identicals = string.gsub(modifiers, " four ", "")
  579.           num_minions = num_minions + (num_identicals * 4)
  580.           penalties_text = penalties_text .. num_identicals .. " set(s) of four identical-looking minions. "
  581.       end --if
  582.       if string.find(modifiers, " five ") then
  583.           modifiers, num_identicals = string.gsub(modifiers, " five ", "")
  584.           num_minions = num_minions + (num_identicals * 5)
  585.           penalties_text = penalties_text .. num_identicals .. " set(s) of five identical-looking minions. "
  586.       end --if
  587.       if string.find(modifiers, " six ") then
  588.           modifiers, num_identicals = string.gsub(modifiers, " six ", "")
  589.           num_minions = num_minions + (num_identicals * 6)
  590.           penalties_text = penalties_text .. num_identicals .. " set(s) of six identical-looking minions. "
  591.       end --if
  592.       if string.find(modifiers, " seven ") then
  593.           modifiers, num_identicals = string.gsub(modifiers, " seven ", "")
  594.           num_minions = num_minions + (num_identicals * 7)
  595.           penalties_text = penalties_text .. num_identicals .. " set(s) of seven identical-looking minions. "
  596.       end --if
  597.       if string.find(modifiers, " eight ") then
  598.           modifiers, num_identicals = string.gsub(modifiers, " eight ", "")
  599.           num_minions = num_minions + (num_identicals * 8)
  600.           penalties_text = penalties_text .. num_identicals .. " set(s) of eight identical-looking minions. "
  601.       end --if
  602.       if string.find(modifiers, " nine ") then
  603.           modifiers, num_identicals = string.gsub(modifiers, " nine ", "")
  604.           num_minions = num_minions + (num_identicals * 9)
  605.           penalties_text = penalties_text .. num_identicals .. " set(s) of nine identical-looking minions. "
  606.       end --if
  607.       if string.find(modifiers, " ten ") then
  608.           modifiers, num_identicals = string.gsub(modifiers, " ten ", "")
  609.           num_minions = num_minions + (num_identicals * 10)
  610.           penalties_text = penalties_text .. num_identicals .. " set(s) of ten identical-looking minions. "
  611.       end --if
  612.      
  613.       --count any unique devils
  614.       if string.find(modifiers, " whirlwind of ") then
  615.           modifiers, num_devils = string.gsub(modifiers, " whirlwind of ", "")
  616.           num_minions = num_minions + num_devils
  617.           penalties_text = penalties_text .. num_devils .. " unique dust devils. "
  618.       end --if
  619.      
  620.       --unidentified minion in the dark (multiples will be "[number] things" and thus counted above)
  621.       if string.find(modifiers, " something") then
  622.           num_minions = num_minions + 1
  623.           penalties_text = penalties_text .. "Unidentified minion in the dark (something). "
  624.       end --if
  625.      
  626.       --unidentified minion in the dark
  627.       if string.find(modifiers, " someone") then
  628.           modifiers, num_others = string.gsub(modifiers, " someone", "")
  629.           num_minions = num_minions + num_others
  630.           penalties_text = penalties_text .. "Unidentified minion in the dark (someone)."
  631.       end --if
  632.      
  633.       --then see if there's a totem
  634.       if string.find(modifiers, "misty woman") or string.find(modifiers, "dust bunny") or string.find(modifiers, "tall robed man") or string.find(modifiers, "rocky creature") or string.find(modifiers, "lung fish") or string.find(modifiers, "large vulture") or string.find(modifiers, "large salamander") then
  635.           num_minions = num_minions + 1
  636.           penalties_text = penalties_text .. "Totem. "
  637.       end --if
  638.      
  639.      
  640.       --then see if there's a creeping doom
  641.       if string.find(modifiers, " black cloud") then
  642.           num_minions = num_minions + 1
  643.           penalties_text = penalties_text .. "Doom. "
  644.       end --if
  645.      
  646.       --then see if there are unique spectres (but only ONE since multiple ones will be counted above)
  647.       if string.find(modifiers, "spectre ") or string.find(modifiers, "spectre\.") or string.find(modifiers, "spectre\, ") then
  648.           modifiers, _ = string.gsub(modifiers, "spectres", "")
  649.           modifiers, num_spectres = string.gsub(modifiers, " spectre", "")
  650.           num_minions = num_minions + num_spectres
  651.           penalties_text = penalties_text .. num_spectres .. " unique spectres."
  652.       end --if
  653.      
  654.       effective_bonus = effective_bonus - (num_minions * 4)
  655.       ritual_penalties = ritual_penalties - (num_minions * 4)
  656.       if num_minions > 2 then
  657.           effective_bonus = effective_bonus - 1
  658.           ritual_penalties = ritual_penalties - 1
  659.       end --if
  660.      
  661.       penalties_text = penalties_text .. num_minions .. " minion(s) total.), "
  662.   end -- if
  663.   --alignment
  664.   if string.find(modifiers, "you can barely feel the presence of") then
  665.       effective_bonus = effective_bonus - 5
  666.       ritual_penalties = ritual_penalties - 5
  667.       penalties_text = penalties_text .. "getting out of align, "
  668.   end -- if
  669.   --far from a high altar
  670.   if string.find(modifiers, "you are far from") then
  671.       --This penalty actually ranges from -2 (just barely in the zone where you get the penalty) to -8 (as far as you can even get from an altar--although you actually get this a lot sooner).  I've set it at -8 since that's what you get in Genua (if not a Gappic or Hattite) or the Ramtops (if not Pishite, Sekkite, or Gufnorkian).  I think most of the time, if you're getting this one at all, you're probably getting the maximum penalty.  There's a bigger "zone" that's at -8 than for anything else, I think.
  672.       effective_bonus = effective_bonus - 8
  673.       ritual_penalties = ritual_penalties - 8
  674.       penalties_text = penalties_text .. "far from an altar, "
  675.   end -- if
  676.   --drunk
  677.   if string.find(modifiers, "Hat approves of your inebriated state") then
  678.       --no modifier because they cancel out
  679.       penalties_text = penalties_text .. "drunk (but Hat likes drunkenness, so no overall penalty), "
  680.   elseif string.find(modifiers, "you are drunk") then
  681.       effective_bonus = effective_bonus - 33
  682.       ritual_penalties = ritual_penalties - 33
  683.       penalties_text = penalties_text .. "drunk, "
  684.   end -- if
  685.   --poisoned
  686.   if string.find(modifiers, "poisoned") then
  687.       effective_bonus = effective_bonus - 33
  688.       ritual_penalties = ritual_penalties - 33
  689.       penalties_text = penalties_text .. "poisoned, "
  690.   end -- if
  691.   --using baton.  This doesn't work properly, because the actual penalty varies, but it needed to be set to SOMEthing.
  692.   if string.find(modifiers, "as an external focus") then
  693.       effective_bonus = effective_bonus - 56
  694.       ritual_penalties = ritual_penalties - 56
  695.       penalties_text = penalties_text .. "using a baton, "
  696.   end -- if
  697.   --not a regular shield, not sure if this even exists anymore
  698.   if string.find(modifiers, "???") then
  699.       bonuses_text = bonuses_text .. "using a fake shield, "
  700.   end -- if
  701.  
  702.  
  703. --Pishite rain/snow/sleet bonus
  704.   if string.find(modifiers, "you feel uplifted by the ") then
  705.       effective_bonus = effective_bonus + 7
  706.       ritual_bonuses = ritual_bonuses + 7
  707.       bonuses_text = bonuses_text .. "rain, snow, or sleet, "
  708.   end -- if
  709.  
  710. --Gufnorkian
  711.   if string.find(modifiers, "you are uplifted by the fluff you carry") then
  712.       effective_bonus = effective_bonus + 7
  713.       ritual_bonuses = ritual_bonuses + 7
  714.       bonuses_text = bonuses_text .. "fluff in inventory, "
  715.   end -- if
  716.  
  717.   if string.find(modifiers, "you feel at home in the fluffy surroundings") then
  718.       effective_bonus = effective_bonus + 3
  719.       ritual_bonuses = ritual_bonuses + 3
  720.       bonuses_text = bonuses_text .. "somewhere fluffy, "
  721.   end -- if
  722.  
  723. --Gappic
  724.   if string.find(modifiers, "you feel comfortable in your stylish clothes") then
  725.       effective_bonus = effective_bonus + 4
  726.       ritual_bonuses = ritual_bonuses + 4
  727.       bonuses_text = bonuses_text .. "stylish clothes, "
  728.   end -- if
  729.  
  730.   if string.find(modifiers, "you feel comfortable in your stylish surroundings") then
  731.       effective_bonus = effective_bonus + 3
  732.       ritual_bonuses = ritual_bonuses + 3
  733.       bonuses_text = bonuses_text .. "stylish place, "
  734.   end -- if
  735.  
  736. --Sandelfonian
  737.   if string.find(modifiers, "you feel more comfortable praying indoors") then
  738.       effective_bonus = effective_bonus + 7
  739.       ritual_bonuses = ritual_bonuses + 7
  740.       bonuses_text = bonuses_text .. "indoors, "
  741.   end -- if
  742.  
  743. --Fishite
  744.   if string.find(modifiers, "you are underwater") then
  745.       effective_bonus = effective_bonus + 14
  746.       ritual_bonuses = ritual_bonuses + 14
  747.       bonuses_text = bonuses_text .. "underwater, "
  748.   end -- if
  749.  
  750.   if string.find(modifiers, "you are floating in the water") then
  751.       effective_bonus = effective_bonus + 7
  752.       ritual_bonuses = ritual_bonuses + 7
  753.       bonuses_text = bonuses_text .. "water surface, "
  754.   end -- if
  755.  
  756.  
  757. --Hattite
  758.   if string.find(modifiers, "Hat approves of your trespass onto the holy ground") then
  759.       effective_bonus = effective_bonus + 9
  760.       ritual_bonuses = ritual_bonuses + 9
  761.       bonuses_text = bonuses_text .. "trespasser"
  762.   end -- if
  763.  
  764.   if string.find(modifiers, "Hat approves of your company") then
  765.       effective_bonus = effective_bonus + 16
  766.       ritual_bonuses = ritual_bonuses + 16
  767.       bonuses_text = bonuses_text .. "with other priests, "
  768.   end -- if
  769.  
  770. --Sekkite
  771.   if string.find(modifiers, "you feel more confident as you battle your foes") then
  772.       effective_bonus = effective_bonus + 5
  773.       ritual_bonuses = ritual_bonuses + 5
  774.       bonuses_text = bonuses_text .. "in combat, "
  775.   end -- if
  776.  
  777.   --do some stuff here to make sure the numeric modifiers are within the ranges indicated by various difficulty messages (much harder, much easier, etc.)
  778.  
  779.  
  780.   if ritual_bonuses == 0 then
  781.       bonuses_text = "No ritual bonuses."
  782.   else
  783.       bonuses_text = bonuses_text .. "for a total of +" .. ritual_bonuses .. " to your bonus."
  784.   end --if
  785.   if ritual_penalties == 0 then
  786.       penalties_text = "No ritual penalties."
  787.   else
  788.       penalties_text = penalties_text .. "for a total of " .. ritual_penalties .. " to your bonus."
  789.   end --if
  790.  
  791.   if verbose == "on" or verbose == "debug" then
  792.       Note(bonuses_text, "  ", penalties_text, "  Your bonus is ", bonus, " and your effective bonus is ", effective_bonus, ".")
  793.   end -- if
  794.  
  795. end -- adjust_bonus
  796.  
  797.  
  798.  
  799. function Parse_Numbers (duration_part)
  800.   num_days = 0 --start it at 0
  801.   text_days = string.sub(duration_part, 11, -6)  --will look like "more than three days" so everything after "more than " up until " days"
  802.   --if it's over a hundred
  803.   if string.find(text_days, "hundred") then
  804.       hundred_start, hundred_end, _ = string.find(text_days, " hundred") --find where "hundred" starts
  805.       num_hundreds_end = hundred_start - 1
  806.       num_hundreds = string.sub (text_days, 1, num_hundreds_end)  --grab the thing right before "hundred"
  807.       num_days = num_days + (Parse_One_Through_Nineteen(num_hundreds) * 100)
  808.      
  809.       remaining_text_start = hundred_end + 2
  810.        text_days = string.sub(text_days, remaining_text_start) --we've added the n hundred days in, so now take that bit out of the text
  811.       --if it was evenly divisible by a hundred there should be no "and ", but if it wasn't, we want to get rid of the "and "
  812.       if string.sub(text_days, 1, 4) == "and " then
  813.           text_days = string.sub(text_days, 5)
  814.       end -- if
  815.   end -- if
  816.   --next, find any parts that indicate twenty, thirty, etc.
  817.   if string.find(text_days, "ty") then
  818.       _, tens_end, _ = string.find(text_days, "ty")
  819.       num_tens = string.sub(text_days, 1, tens_end) --grab the thing that ends in "ty"
  820.        num_tens = Parse_Tens(num_tens) --and figure out which one it is, then add it in
  821.       num_days = num_days + num_tens
  822.       remaining_text_start = tens_end + 2
  823.        text_days = string.sub(text_days, remaining_text_start) --we've added the n ten days in, so now take that bit out of the text
  824.      
  825.       --it doesn't actually matter whether there's a dash ("forty eight" vs "forty-eight") because we're skipping that character either way.
  826.  
  827.   end -- if
  828.   --after all this the only thing even POSSIBLY left should be one, two ... nineteen.
  829.   if text_days == "" then
  830.       return num_days
  831.   else
  832.       num_days = num_days + Parse_One_Through_Nineteen(text_days)
  833.   end -- if
  834.  
  835.  
  836.   return num_days
  837. end -- Parse_Numbers
  838.  
  839. function Parse_One_Through_Nineteen (text_number)
  840.   if text_number == "one" then
  841.       return 1
  842.   elseif text_number == "two" then
  843.       return 2
  844.   elseif text_number == "three" then
  845.       return 3
  846.   elseif text_number == "four" then
  847.       return 4
  848.   elseif text_number == "five" then
  849.       return 5
  850.   elseif text_number == "six" then
  851.       return 6
  852.   elseif text_number == "seven" then
  853.       return 7
  854.   elseif text_number == "eight" then
  855.       return 8
  856.   elseif text_number == "nine" then
  857.       return 9
  858.   elseif text_number == "ten" then
  859.       return 10
  860.   elseif text_number == "eleven" then
  861.       return 11
  862.   elseif text_number == "twelve" then
  863.       return 12
  864.   elseif text_number == "thirteen" then
  865.       return 13
  866.   elseif text_number == "fourteen" then
  867.       return 14
  868.   elseif text_number == "fifteen" then
  869.       return 15
  870.   elseif text_number == "sixteen" then
  871.       return 16
  872.   elseif text_number == "seventeen" then
  873.       return 17
  874.   elseif text_number == "eighteen" then
  875.       return 18
  876.   elseif text_number == "nineteen" then
  877.       return 19
  878.  
  879.   else  --this should NOT happen, however, if it does...
  880.       return 0
  881.   end --if
  882. end --Parse_One_Through_Nineteen
  883.  
  884.  
  885. function Parse_Tens (text_number)
  886.   if text_number == "twenty" then
  887.       return 20
  888.   elseif text_number == "thirty" then
  889.       return 30
  890.   elseif text_number == "forty" then
  891.       return 40
  892.   elseif text_number == "fifty" then
  893.       return 50
  894.   elseif text_number == "sixty" then
  895.       return 60
  896.   elseif text_number == "seventy" then
  897.       return 70
  898.   elseif text_number == "eighty" then
  899.       return 80
  900.   elseif text_number == "ninety" then
  901.       return 90
  902.   else  --this should NOT happen, however, if it does...
  903.       return 0
  904.   end --if
  905. end --Parse_Tens
  906.  
  907.  
  908. function Adjust_Timer (name, line, wildcards)
  909. duration_part = wildcards[4] -- grab the part of the line that is the textual duration and translate into seconds
  910.  
  911. if duration_part == "less than five minutes" then
  912.   min_duration = 1
  913.   max_duration = 299
  914. elseif duration_part == "at least five minutes" then
  915.   min_duration = 300
  916.   max_duration = 899
  917. elseif duration_part == "at least a quarter of an hour" then
  918.   min_duration = 900
  919.   max_duration = 1799
  920. elseif duration_part == "at least half an hour" then
  921.   min_duration = 1800
  922.   max_duration = 3599
  923. elseif duration_part == "at least an hour" then
  924.   min_duration = 3600
  925.   max_duration = 7199
  926. elseif duration_part == "at least a couple of hours" then
  927.   min_duration = 7200
  928.   max_duration = 21599
  929. elseif duration_part == "more than a quarter of a day" then
  930.   min_duration = 21600
  931.   max_duration = 43199
  932. elseif duration_part == "more than half a day" then
  933.   min_duration = 43200
  934.   max_duration = 86399
  935. elseif duration_part == "more than a day" then
  936.   min_duration = 86400
  937.   max_duration = 172799
  938. else --for values over a day, they should all follow the "more than n days" pattern, parse this
  939.   num_days = Parse_Numbers (duration_part)
  940.   --convert days to seconds
  941.   min_duration = num_days * 24 * 60 * 60
  942.   max_duration = ((num_days + 1) * 24 * 60 * 60) - 1
  943. end -- if
  944.  
  945.  
  946. if finish_time and finish_time ~= "" then -- figure out time the plugin thinks is left
  947.   time_left = finish_time - os.time ()
  948. else
  949.   time_left = 0
  950. end -- if
  951.  
  952. if time_left < min_duration then   -- see if the alleged time left is within what shields says
  953.   time_left = min_duration
  954. elseif time_left > max_duration then
  955.   time_left = max_duration
  956. else
  957.   -- do nothing
  958. end -- if
  959.  
  960. active = "yes"  -- set things up for the show_time function
  961. Save_Setting ("active", active)
  962. finish_time = os.time () + time_left
  963. Save_Setting ("finish_time", finish_time)
  964. show_time ()
  965. end -- Adjust_Timer
  966.  
  967.  
  968. function Clear_Timer (name, line, wildcards)
  969. time_left = 0
  970. active = ""
  971. finish_time = ""
  972. previous_time_left = ""
  973. Save_Setting ("finish_time", finish_time)
  974. Save_Setting ("active", active)
  975. Save_Setting ("previous_time_left", previous_time_left)
  976.  
  977. end -- Clear_Timer
  978.  
  979.  
  980. --Called when you log out etc.  Saves the remaining time on the timer for this character.
  981. function Pause_Timer (name, line, wildcards)
  982. if active == "yes" then
  983.        log_off_time = os.time ()
  984.   previous_time_left = finish_time - log_off_time
  985.   Note ("Paused major timer.")
  986. end -- if
  987. Save_Saveable_Variables ()
  988. end -- pause_timer
  989.  
  990.  
  991. function Already_Playing ()
  992. already_playing = true
  993. end -- Already_Playing
  994.  
  995.  
  996. --Called when you login etc.  Grabs the remaining time for that character, if any, and starts the timer up where it left off from last time.
  997. function Unpause_Timer ()
  998. active = Retrieve_Setting("active")
  999. bonus = Retrieve_Setting("bonus")
  1000. if bonus == "" then
  1001.   bonus = 307
  1002. end -- if
  1003. effective_bonus = bonus
  1004. previous_time_left = Retrieve_Setting("previous_time_left")
  1005. if already_playing then
  1006.   finish_time = Retrieve_Setting("finish_time")
  1007.   already_playing = nil
  1008. elseif previous_time_left ~= "" then
  1009.   finish_time = os.time () + previous_time_left
  1010.   active = "yes"
  1011.   Note ("Unpaused major timer.")
  1012.   Save_Setting ("finish_time", finish_time)
  1013. end -- if
  1014. end -- unpause_timer
  1015.  
  1016.  
  1017. function Switch_User (name, line, wildcards)
  1018. --send whatever you entered, unaltered, on to the MUD
  1019. Send(line)
  1020. --save whichever character you su'ed from
  1021.      log_off_time = os.time ()
  1022. Save_Saveable_Variables ()
  1023. previous_character = current_character
  1024. --grab the name of the character you're suing to
  1025. current_character = wildcards[1]
  1026. end -- Switch_User
  1027.  
  1028.  
  1029. --turns the whoami alias on.  Triggered by mtwhoami on
  1030. function Whoami_On ()
  1031. world.EnableTrigger("whoami", true)
  1032. SetVariable("whoami", "on")
  1033. end --Whoami_On
  1034.  
  1035. --turns the whoami alias off.  Triggered by mtwhoami off
  1036. function Whoami_Off ()
  1037. world.EnableTrigger("whoami", false)
  1038. SetVariable("whoami", "")
  1039. end --Whoami_Off
  1040.  
  1041.  
  1042. --turns the skills alias on.  Triggered by mtskills on
  1043. function Skills_On ()
  1044. world.EnableTrigger("skills", true)
  1045. SetVariable("skills", "on")
  1046. end --Skills_On
  1047.  
  1048. --turns the skills alias off.  Triggered by mtskills off
  1049. function Skills_Off ()
  1050. world.EnableTrigger("skills", false)
  1051. SetVariable("skills", "")
  1052. end --Skills_Off
  1053.  
  1054.  
  1055. --turns verbose mode on.  Triggered by mtverbose on.  This is global, not per character.  Verbose mode causes extra messages in some places.  (Extra messages: saying how your bonus is affected by whatever ritual modifiers it sees; saying what bonus you've set it (manually or via skills output) to and what base duration that gives you; telling you when it detects which character you're using.)
  1056. function Verbose_On ()
  1057. verbose = "on"
  1058. SetVariable("verbose", "on")
  1059. end --Verbose_On
  1060.  
  1061. --debug mode, even more messages.  (Tells you when it saves a character-specific setting, tells you how much time has been added.)
  1062. function Verbose_Debug ()
  1063. verbose = "debug"
  1064. SetVariable("verbose", "debug")
  1065. end --Verbose_Debug
  1066.  
  1067. --turns verbose mode off.  
  1068. function Verbose_Off ()
  1069. verbose = ""
  1070. SetVariable("verbose", "")
  1071. end --Verbose_Off
  1072.  
  1073.  
  1074. --Triggered by the text, "Or, enter your current character's name".  When that shows up the next thing entered might be your login, so enable the alias to grab whatever you enter.
  1075. function Enter_Name ()
  1076. world.EnableAlias("login_name", true)
  1077. end -- Enter_Name
  1078.  
  1079. --Triggered by the text, "                     Where all your dreams can't come true.", which is part of the thing you get AFTER you enter your name.  Hopefully this will stop it grabbing your password if you enter your name too quickly.
  1080. function Enter_Password ()
  1081. world.EnableAlias("login_name", false)
  1082. end -- Enter_Password
  1083.  
  1084. function Login (name, line, wildcards)
  1085. --send whatever you entered, unaltered, on to the MUD
  1086. Send(line)
  1087. --save whatever you entered as your current character
  1088. --but make sure it's not a *command* instead of a character name.  Not that it hurts per se, but it can clutter up the save file.
  1089. if line ~= "q" and line ~= "m" and line ~= "d" and line ~= "r" and line ~= "u" and line ~= "l" and line ~= "p" and line ~= "f" and line ~= "n" and line ~= "g" then
  1090.   current_character = line
  1091.   if verbose == "on" or verbose == "debug" then
  1092.       Note("[Major Timer] Character detected: ", current_character)
  1093.   end -- if
  1094. end -- if
  1095. --turn the alias off again.
  1096. world.EnableAlias("login_name", false)
  1097. end -- Login
  1098.  
  1099.  
  1100. function Set_Character_From_Whoami (name, line, wildcards)
  1101. potential_character = wildcards[2]
  1102. if potential_character == "not" or potential_character == "already" or potential_character == "remembering" or potential_character == "keeping" or potential_character == "unsure" or potential_character == "crouching" or potential_character == "kneeling" or potential_character == "lying" or potential_character == "lounging" or potential_character == "meditating" or potential_character == "sitting" or potential_character == "squatting" or potential_character == "standing" then  
  1103. --do nothing, this stops it from setting itself from "you are not holding", "you are already wearing the", position stuff, etc.
  1104. else
  1105.   current_character = potential_character
  1106.   if verbose == "on" or verbose == "debug" then
  1107.       Note("[Major Timer] Character detected: ", current_character)
  1108.   end -- if
  1109. end -- if
  1110. end -- Set_Character_From_Whoami
  1111.  
  1112.  
  1113. --manually set the character with mtchar
  1114. function Man_Set_Character (name, line, wildcards)
  1115. current_character = wildcards[1]
  1116. if verbose == "on" or verbose == "debug" then
  1117.   Note("Character set: ", current_character)
  1118. end -- if
  1119. Unpause_Timer ()
  1120. end -- Man_Set_Character
  1121.  
  1122.  
  1123. --actually makes the window showing the remaining time.
  1124. function show_time (name, line, wildcards)
  1125. if active == "yes" and finish_time ~= "" then
  1126.   time_left = finish_time - os.time ()
  1127.  
  1128.   if time_left <= 0 then
  1129.     --These next two lines are so that there will not be a finish_time that's in the past.  Otherwise, if it thought it should have dropped five minutes ago and you added four minutes of shielding, it would think it should have dropped one minute ago, when it should actually think it's now due to drop in four minutes.
  1130.     time_left = 0
  1131.     finish_time = os.time ()
  1132.     text = "Shield due to drop!"
  1133.   elseif time_left < 60 then
  1134.     text = string.format ("Major shield expires in: " .. time_left .. " seconds.")
  1135.   elseif time_left >= 60 and time_left < 3600 then
  1136.     mins_left = string.format ("%3.1f", (time_left / 60))
  1137.     text = string.format ("Major shield expires in: " .. mins_left .. " minutes.")
  1138.   elseif time_left >= 3600 and time_left < 86400 then
  1139.     hrs_left = string.format ("%3.1f", ((time_left / 60)/60))
  1140.     text = string.format ("Major shield expires in: " .. hrs_left .. " hours.")
  1141.   elseif time_left >= 86400 then
  1142.     days_left = string.format ("%i", (((time_left / 60)/60))/24)
  1143.     hrs_left = string.format ("%3.1f", (((time_left - (days_left*60*60*24))/60)/60))
  1144.     text = string.format ("Major shield expires in: " .. days_left .. " days and " .. hrs_left .. " hours.")
  1145.   end -- if
  1146.  
  1147.   max_width = (WindowTextWidth (win, "fn", text)) + 10
  1148.  
  1149.   if time_left < 60 then
  1150.     TEXT_COLOUR = ColourNameToRGB ("red")
  1151.   else
  1152.     TEXT_COLOUR = ColourNameToRGB ("black")
  1153.   end -- if
  1154.  
  1155.   -- recreate the window the correct size
  1156.   WindowCreate (win,
  1157.                0, 0,   -- left, top (auto-positions)
  1158.                max_width,     -- width
  1159.                font_height + 10,  -- height
  1160.                5,       -- auto-position: top middle
  1161.                0,  -- flags
  1162.                ColourNameToRGB ("lightgoldenrodyellow"))
  1163.  
  1164.   WindowText (win, "fn",
  1165.                 text,                       -- text
  1166.                 5, 5, 0, 0,                 -- rectangle
  1167.                 TEXT_COLOUR,                -- colour
  1168.                 false)                      -- not Unicode
  1169.   WindowShow (win, true)
  1170. else
  1171.   WindowShow (win, false)  
  1172. end -- if active
  1173. end -- show_time
  1174.  
  1175.  
  1176. function OnPluginInstall ()
  1177. win = GetPluginID ()
  1178. font_id = "fn"
  1179. font_name = "Comic Sans MS"    -- the actual font
  1180.  
  1181. -- make win so I can grab the font info
  1182. WindowCreate (win,
  1183.                0, 0, 1, 1,  -- 1 x 1 pixel
  1184.                1,   -- position - irrelevant
  1185.                0,   -- flags
  1186.                0)   -- background colour
  1187.              
  1188. check (WindowFont (win, font_id, font_name, 8))  -- normal
  1189. font_height = WindowFontInfo (win, font_id, 1)  -- height
  1190.  
  1191. --load settings for this character
  1192. current_character = GetVariable("current_character") or "default"
  1193.  
  1194. active = Retrieve_Setting("active") or ""
  1195. finish_time = Retrieve_Setting("finish_time") or ""
  1196. previous_time_left = Retrieve_Setting("previous_time_left") or ""
  1197. --if we have no bonus set for this character, use this arbitrary default bonus (guildmax and all 13s)
  1198. bonus = Retrieve_Setting("bonus") or 307
  1199.  
  1200. --and get these global settings
  1201. verbose = GetVariable("verbose") or ""
  1202. whoami = GetVariable("whoami") or ""
  1203. skills = GetVariable("skills") or ""
  1204. if whoami == "on" then
  1205.   world.EnableTrigger("whoami", true)
  1206. else
  1207.   world.EnableTrigger("whoami", false)
  1208. end -- if
  1209. if skills == "on" then
  1210.   world.EnableTrigger("skills", true)
  1211. else
  1212.   world.EnableTrigger("skills", false)
  1213. end -- if
  1214.  
  1215. end -- OnPluginInstall
  1216.  
  1217. function OnPluginDisable ()
  1218. WindowShow (win, false)
  1219. end -- OnPluginDisable
  1220.  
  1221.  
  1222.  
  1223. -------------------------------------------------------------------------------------------
  1224. -- on saving state, convert Lua table back into string variable save_simple is for simple
  1225. -- tables that do not have cycles (self-reference) or refer to other tables
  1226. -------------------------------------------------------------------------------------------
  1227. -------------------------------------------------------------------------------------------
  1228. -- Before, it was using serialize.save_simple.  However, that seemed to be adding a bunch
  1229. -- of backslashes and quotes to the file every time, so that the variables it saved got
  1230. -- increasingly longer.  THIS seems to work fine, though.
  1231. -------------------------------------------------------------------------------------------
  1232.  
  1233. --use this by feeding them a setting NAME, as TEXT, and then the setting itself; e.g. Save_Setting("bonus", bonus)
  1234. function Save_Setting (setting_name, setting)
  1235. variable_name = string.format (current_character .. "_" .. setting_name)
  1236. if setting then
  1237.   SetVariable (variable_name, setting)
  1238.   if verbose == "debug" then
  1239.       Note("Saved: ", variable_name, " as ", setting)
  1240.   end--if
  1241. else --but, it should not be nil.  This is just in case.
  1242.   SetVariable (variable_name, "")
  1243.   if verbose == "debug" then
  1244.       Note("Saved: ", variable_name, " as empty string")
  1245.   end --if
  1246. end -- if
  1247. end -- Save_Setting
  1248.  
  1249. --This one however only needs the name (again, as TEXT); it will return the value to set as the setting itself.  E.g. bonus = Retrieve_Setting ("bonus")
  1250. function Retrieve_Setting (setting_name)
  1251. variable_name = string.format (current_character .. "_" .. setting_name)
  1252. setting = GetVariable(variable_name) or ""
  1253. return setting
  1254. end -- Retrieve_Setting
  1255.  
  1256.  
  1257. function Save_Saveable_Variables ()
  1258. SetVariable ("current_character", current_character)
  1259. if active == "yes" and finish_time ~= "" then
  1260.   Save_Setting ("finish_time", finish_time)
  1261.   previous_time_left = finish_time - log_off_time
  1262.   Save_Setting ("previous_time_left", previous_time_left)
  1263.   Save_Setting ("active", "yes")
  1264. else
  1265.   Save_Setting ("finish_time", "")
  1266.   Save_Setting ("previous_time_left", "")
  1267.   Save_Setting ("active", "")
  1268. end -- if
  1269. if bonus then
  1270.   Save_Setting ("bonus", bonus)
  1271. end -- if
  1272. end -- function Save_Saveable_Variables
  1273.  
  1274. function OnPluginSaveState ()
  1275.   Save_Saveable_Variables ()
  1276. end -- function OnPluginSaveState
  1277.  
  1278. function OnWorldSave ()
  1279.   Save_Saveable_Variables ()
  1280. end -- function
  1281.  
  1282. function print_help()
  1283. Note([[Plugin Help:Major Timer
  1284.  
  1285. This plugin produces a small window showing the time remaining on your faith shield.  This currently only works for Major Shield.  Minor Shield, although it stacks with Major Shield, has a different duration formula.  It does, however, have exactly the same success message, so using Minor Shield will confuse the plugin.  It also doesn't work well for having other people perform Major Shield on you: it will use *your* bonus to determine the duration.
  1286.  
  1287. It can set itself either from actually performing Major Shield (if you've used mtset to set your bonus), or (roughly) from the output of the "shields" command.
  1288.  
  1289. It can remember bonus information and time remaining on a shield on a per-character basis.  Therefore, you can log off with a shield running without it counting the time spent logged off.  It should detect which character you're logging in as when you log in or su (although if you have an alias for su that's something other than "su", this part will not work).
  1290.  
  1291. It can detect ritual bonuses and penalties (for example, being at a high altar) and will adjust your effective bonus--and therefore duration--accordingly.  As the bonuses and penalties for being near or far from a high altar vary somewhat depending on exact distance, it may still be off by a few seconds.
  1292.  
  1293. The following commands are recognized:
  1294.  
  1295.   * help majortimer   Displays this help file.
  1296.  
  1297.   * mtset <number>      Set your fa.ri.de.se bonus, from which durations
  1298.                           are derived.
  1299.                           Eg. A 300 bonus should be entered as 'mtset 300'.
  1300.   * mtadd <number>      Manually add time in minutes to your shield timer.
  1301.                           Eg. 'mtadd 2' will add 2 minutes to the timer.
  1302.   * mtminus <number>    Manually minus time in minutes from your shield timer.
  1303.                           Eg. 'mtminus 2' will take 2 minutes from the timer.
  1304.   * mtreset             Sets the timer back to 1 shield's duration in length.
  1305.   * mtaddone            Manually adds one performance's worth of shielding,
  1306.                           using the most recent value for effective bonus.
  1307.   * mtclear             Clears the timer.
  1308.   * mtchar <name>       Manually sets the current character and loads any
  1309.                           previous settings for that character.
  1310.   * mtwhoami [on|off]   Turns the trigger for whoami output on or off.  "On"
  1311.                           lets the plugin detect the output of the MUD's
  1312.                           "whoami" command, and set your current character
  1313.                           accordingly.  "Off" is the default, as the trigger
  1314.                           can easily be triggered incorrectly (for example by
  1315.                           whoami output in finger info, or by unrelated
  1316.                           messages with a similar format).
  1317.   * mtskills [on|off]   Turns the trigger for skills output on or off.  When
  1318.                           on, it can detect the line for f.r.d.s, but only if
  1319.                           the output is in list format.  Off by default.
  1320.   * mtverbose [on|off]  Turns verbose mode on or off.  In verbose mode: extra
  1321.                           messages are displayed when: you set your bonus (or
  1322.                           it's set from skills output), you perform MS with
  1323.                           ritual modifiers, and when you set your character
  1324.                           (manually or through whoami).  Off by default.
  1325. ]])
  1326. end
  1327.  
  1328. ]]></script>
  1329. </muclient>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement