Advertisement
Guest User

Untitled

a guest
May 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. Composed by: Jarrod on or about the 16th of Aeguary, 688 AF.
  2.  
  3. ---------------------------------------------------------------------
  4. | ENEMY REPORTING |
  5. ---------------------------------------------------------------------
  6.  
  7. This will serve both as a standard layout for reporting your enemies as
  8. well as some examples of code that are useful in other situations. Step
  9. one to any coding project is laying out the goal of the code.
  10.  
  11. 1) Keep a client-side table of your current enemies
  12. 2) Keep the table up to date through login/logout
  13. 3) Report the table in a standard format when necessary
  14.  
  15. What is the standard format?
  16.  
  17. (Party): Hasar says, "My enemies are Ethoas, Hirst, Jhui (3)."
  18.  
  19. Script (Everything before the next break can go in a script file):
  20. ---------------------------------------------------------------------
  21.  
  22. --Prevents the table from being reset when you view the script
  23. myEnemies = myEnemies or {}
  24. --Add names to this list for those you'll accept enemies from
  25. allyEnemyOk = {"Xinna", "Hasar", "Xer", "Jarrod",}
  26.  
  27. --Loads the enemy table on login, may need modification for
  28. -- different operating systems
  29. function myEnemyLoad()
  30. local sep
  31. local homeDir = getMudletHomeDir()
  32. if string.char(homeDir:byte()) == "/" then
  33. sep = "/" else sep = "\\"
  34. end
  35. table.load(homeDir..sep.."myEnemyList.lua", myEnemies)
  36. end
  37.  
  38. --Save the table
  39. function myEnemySave()
  40. local sep
  41. local homeDir = getMudletHomeDir()
  42. if string.char(homeDir:byte()) == "/" then
  43. sep = "/" else sep = "\\"
  44. end
  45. table.save(homeDir..sep.."myEnemyList.lua", myEnemies)
  46. end
  47.  
  48. --Enemies and adds to the enemy table, then saves it
  49. function addEnemy(name)
  50. --Ensure we don't duplicate names in the table
  51. if not table.contains(myEnemies, name) then
  52. table.insert(myEnemies, name)
  53. end
  54. myEnemySave()
  55. end
  56.  
  57. --Unenemies and removes from the enemy table, then saves
  58. function removeEnemy(name)
  59. if table.contains(myEnemies, name) then
  60. table.remove(myEnemies, table.index_of(myEnemies, name))
  61. end
  62. myEnemySave()
  63. end
  64.  
  65. --Reports the enemy list to PT
  66. function reportEnemies()
  67. --Make sure when copying this is changed to a single line
  68. send("pt My enemies are "..table.concat(myEnemies, ", ")..
  69. " ("..#myEnemies..")")
  70. end
  71.  
  72. ---------------------------------------------------------------------
  73.  
  74. Additionally, you'll want to add triggers to use the above functions:
  75.  
  76. Enemy Trigger:
  77. Pattern: ^(\w+) is now one of your enemies\.$
  78. (pattern type: perl regex)
  79.  
  80. addEnemy(matches[2])
  81.  
  82.  
  83. Unenemy Trigger:
  84. Pattern: ^You declare that (\w+) will no longer be one of your
  85. enemies\.$
  86. (pattern type: perl regex)
  87.  
  88. removeEnemy(matches[2])
  89.  
  90.  
  91. Unenemy All:
  92. Pattern: In a moment of forgiveness, you declare that you have no
  93. enemies.
  94. (pattern type: exact match)
  95.  
  96. myEnemies = {}
  97. myEnemySave()
  98.  
  99.  
  100. Login Trigger:
  101. Pattern: Password correct. Welcome to Achaea.
  102. (mapper): We're connected to Achaea.
  103.  
  104. [Shaman]: Settings loaded.
  105. (pattern type: exact match)
  106.  
  107. myEnemyLoad()
  108.  
  109.  
  110. IMPORTANT NOTE: This Trigger must be above any chat scripts you might
  111. have in your trigger list
  112. Ally Enemy Call:
  113. Pattern: ^\(Party\): (\w+) says, "My enemies are (.+) \(\d+\)\."$
  114. (pattern type: perl regex)
  115. Pattern: Light red : Black
  116. (pattern type: color trigger)
  117. ^ ensure the colors here match your PT color pre-chat scripts
  118. Check Box: multiline /AND Trigger
  119. Line delta: 0
  120.  
  121. if table.contains(allyEnemyOk, multimatches[1][2]) then
  122. local enemyList = string.split(multimatches[1][3], ", ")
  123. send("unenemy all")
  124. for i,v in ipairs(enemyList) do
  125. send("enemy "..v)
  126. end
  127. end
  128.  
  129. If you have a way to do this better, please let me know. Questions as
  130. well if something is unclear.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement