Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Composed by: Jarrod on or about the 16th of Aeguary, 688 AF.
- ---------------------------------------------------------------------
- | ENEMY REPORTING |
- ---------------------------------------------------------------------
- This will serve both as a standard layout for reporting your enemies as
- well as some examples of code that are useful in other situations. Step
- one to any coding project is laying out the goal of the code.
- 1) Keep a client-side table of your current enemies
- 2) Keep the table up to date through login/logout
- 3) Report the table in a standard format when necessary
- What is the standard format?
- (Party): Hasar says, "My enemies are Ethoas, Hirst, Jhui (3)."
- Script (Everything before the next break can go in a script file):
- ---------------------------------------------------------------------
- --Prevents the table from being reset when you view the script
- myEnemies = myEnemies or {}
- --Add names to this list for those you'll accept enemies from
- allyEnemyOk = {"Xinna", "Hasar", "Xer", "Jarrod",}
- --Loads the enemy table on login, may need modification for
- -- different operating systems
- function myEnemyLoad()
- local sep
- local homeDir = getMudletHomeDir()
- if string.char(homeDir:byte()) == "/" then
- sep = "/" else sep = "\\"
- end
- table.load(homeDir..sep.."myEnemyList.lua", myEnemies)
- end
- --Save the table
- function myEnemySave()
- local sep
- local homeDir = getMudletHomeDir()
- if string.char(homeDir:byte()) == "/" then
- sep = "/" else sep = "\\"
- end
- table.save(homeDir..sep.."myEnemyList.lua", myEnemies)
- end
- --Enemies and adds to the enemy table, then saves it
- function addEnemy(name)
- --Ensure we don't duplicate names in the table
- if not table.contains(myEnemies, name) then
- table.insert(myEnemies, name)
- end
- myEnemySave()
- end
- --Unenemies and removes from the enemy table, then saves
- function removeEnemy(name)
- if table.contains(myEnemies, name) then
- table.remove(myEnemies, table.index_of(myEnemies, name))
- end
- myEnemySave()
- end
- --Reports the enemy list to PT
- function reportEnemies()
- --Make sure when copying this is changed to a single line
- send("pt My enemies are "..table.concat(myEnemies, ", ")..
- " ("..#myEnemies..")")
- end
- ---------------------------------------------------------------------
- Additionally, you'll want to add triggers to use the above functions:
- Enemy Trigger:
- Pattern: ^(\w+) is now one of your enemies\.$
- (pattern type: perl regex)
- addEnemy(matches[2])
- Unenemy Trigger:
- Pattern: ^You declare that (\w+) will no longer be one of your
- enemies\.$
- (pattern type: perl regex)
- removeEnemy(matches[2])
- Unenemy All:
- Pattern: In a moment of forgiveness, you declare that you have no
- enemies.
- (pattern type: exact match)
- myEnemies = {}
- myEnemySave()
- Login Trigger:
- Pattern: Password correct. Welcome to Achaea.
- (mapper): We're connected to Achaea.
- [Shaman]: Settings loaded.
- (pattern type: exact match)
- myEnemyLoad()
- IMPORTANT NOTE: This Trigger must be above any chat scripts you might
- have in your trigger list
- Ally Enemy Call:
- Pattern: ^\(Party\): (\w+) says, "My enemies are (.+) \(\d+\)\."$
- (pattern type: perl regex)
- Pattern: Light red : Black
- (pattern type: color trigger)
- ^ ensure the colors here match your PT color pre-chat scripts
- Check Box: multiline /AND Trigger
- Line delta: 0
- if table.contains(allyEnemyOk, multimatches[1][2]) then
- local enemyList = string.split(multimatches[1][3], ", ")
- send("unenemy all")
- for i,v in ipairs(enemyList) do
- send("enemy "..v)
- end
- end
- If you have a way to do this better, please let me know. Questions as
- well if something is unclear.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement