Is this possible?

traxtin
Posts: 7
Joined: Wed Nov 23, 2011 8:20 am

Is this possible?

Post by traxtin »

I don't know too much about LUA and tables so I thought I would just put my idea up here and see if someone can tell me if it is possible and give me an idea of how I might accomplish it.

Okay so what I have is a list of targets that I want to attack. Some of these targets can be in the same room at the same time.

Lets assume your attack line is thus: "attack target" now obviously target is whatever you are targeting.

What I want to know is if there would be a way to set it up so that when you hit your attack it checks your list of targets against what is in the room and then if there is a positive hit it launches the attack. I also want it to go through the list in a certain order so you can prioritize targets automatically.

Thoughts?

User avatar
demonnic
Posts: 886
Joined: Sat Dec 05, 2009 3:19 pm

Re: Is this possible?

Post by demonnic »

That is all quite doable, but without a bit more information it would be difficult to tell you how to proceed, really. If you get us a sampling of data we may be able to set up some skeleton code for you.

traxtin
Posts: 7
Joined: Wed Nov 23, 2011 8:20 am

Re: Is this possible?

Post by traxtin »

I am guessing this would be a multi stage of learning so lets start out with what I think should be the "easy" part...

I need to make a table/database with a list of enemies.
and an easy way to add to the list based on the target # of each target... and to prioritize them from 1-5 with 1 being high priority and 5 being low priority for targeting when they are in the room.

so I would want the command to add them to the table to be something like this:

addtarget <target#> <Priority 1-5>

Delrayne
Posts: 159
Joined: Tue Jun 07, 2011 7:07 pm
Contact:

Re: Is this possible?

Post by Delrayne »

table.insert(table,item,position) for the quick add.

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Is this possible?

Post by Oneymus »

Define this in a Script:
Code: [show] | [select all] lua
-- We're not going to pre-define our priority tables.
-- With this method, you can have as many priorities as you want.
enemy_table = enemy_table or {}
Then, in your Alias:
Code: [show] | [select all] lua
-- Pattern: ^addtarget (\w+) (\d+)$
-- The pattern could be tightened a bit to make it for exclusive, but this will work.

local enemy = matches[2]
local priority = matches[3]

-- This line says: If the priority table exists, then that's fine. If it doesn't exist, we make it.
enemy_table[priority] = enemy_table[priority] or {}

-- If the enemy doesn't exist in the table, then...
if not enemy_table[priority][enemy] then
  -- We're going to make each enemy a table itself. I'm assuming this IRE, and you'll want to grab
  -- the unique ID of each enemy to make sure you attack the right one consistently.
  enemy_table[priority][enemy] = {}
end
That's part one, I suppose. Part two is generating the list of enemies in the room using either GMCP or Info Here. Basically, you would want to add each enemy's UID to its table in the priority list with something like...
Code: [show] | [select all] lua
table.insert( enemy_table[priority][enemy], uid )
I ran out of time, but I should be able to provide more help later if you'd like.

As is often the case, I make no guarantees. I wrote this in the forum itself and did not test anything.

traxtin
Posts: 7
Joined: Wed Nov 23, 2011 8:20 am

Re: Is this possible?

Post by traxtin »

okay i understand the part about the alias...
I don't understand what the script is doing? I have it in a script though XD
I also have no clue what to do with the table.insert part??? Where do I put it? What does it do? How do I use it? :P Thanks

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Is this possible?

Post by Oneymus »

The Script part simply initializes the enemy_table that we need to store our data. It could be done anywhere, but having it in a Script means it fires when the profile starts up.

Add this to the Script:
Code: [show] | [select all] lua
current_target = ""
Now, you need to trigger on Info Here (or GMCP). Every time you move, you should send( "info here" ). This is the trigger setup:
Code: [show] | [select all] lua
-- Trigger Name: IH Gate
-- Pattern (exact match): whatever the opening line of IH is. "You see blah blah..."
-- Fire Length: 99
-- Script:
ihCapture = true

-- You can set ihGag to true somewhere if you don't want to see the spam every time you use it.
if ihGag then
  deleteLine()
end

-- Here we empty out the enemy tables so it's fresh every time we IH.
for priority, tbl in ipairs( enemy_table ) do
  for enemy in pairs( tbl ) do
    enemy = {}
  end
end

-- Trigger Name: IH Capture
-- Parent: IH Gate
-- Pattern (Lua function): return ihCapture
-- Pattern (regex): (\w+)(\d+)
-- Multiline / AND Trigger
-- Script:
-- This is where it gets tricky; you have to parse the data yourself, but I can give you the general idea.
-- The theory is that you want to identify the UID of the mob if it matches one of your targets.
-- We only care about the mob if it is one your targets.
local name = matches[2]
local id = matches[3]

-- We add the ID to enemy's table by iterating through the priority tables and seeing
-- if the enemy's name exist.
for priority, tbl in ipairs( enemy_table ) do
  if tbl[name] then
    table.insert( tbl[name], id )
  end
end

-- For example, if we added "goblin" to priority 1, and we found "goblin1234",
-- then enemy_table would look like...
--[[
enemy_table = {
  1 = {
    goblin = {
      1234
    }
  }
}
]]

-- Trigger Name: Close IH Gate
-- Pattern (Lua function): return isPrompt()
-- Script:
setTriggerStayOpen( "IH Gate", 0 )
ihCapture = nil
To walk you through it, the Gate simply says "Yes, we are now in an Info Here block." By setting Fire Length to 99, it's basically telling Mudlet to run the Script of this trigger for 99 more lines after the first one is true. It also checks all child triggers for each of those 99 lines, which is why this works.

IH Capture is the trigger that actually does the work, and I can't give this to you verbatim because I don't know what the lines look like. Basically, though, as long ihCapture is true, it will try to parse the regex line provided. This then adds the enemy's ID to the appropriate table in enemy_table.

Finally, Close IH Gate turns off IH Gate and sets ihCapture to true when it runs into the prompt.

I am making the assumption here that you're on an IRE MuD. If not, this will require heavy adapting. It will still most likely need to be adapted for your specific needs, but the principles are sound. Untested, of course.

Just to make sure it's completely clear, here are screenshots: http://imgur.com/a/udIvO#0

Now that I've done most of the work for you, I'm going to leave it as an exercise for you to figure out the attack alias.

traxtin
Posts: 7
Joined: Wed Nov 23, 2011 8:20 am

Re: Is this possible?

Post by traxtin »

I am playing Achaea... for info here there is no opening line, it just goes directly into the list of objects in the room and then at the end it says: "Number of objects: X" This is the only static part of info here... but it is at the bottom instead of the tope... maybe better to use GMCP instead of using info here then?

User avatar
Oneymus
Posts: 321
Joined: Thu Sep 17, 2009 5:24 am

Re: Is this possible?

Post by Oneymus »

Make an IH alias. Set ihCapture to true in there instead of the opening trigger.

Alternatively, you can backtrack lines, but this is far more work.

Bnkelly11110000
Posts: 2
Joined: Tue May 08, 2012 2:32 pm

Re: Is this possible?

Post by Bnkelly11110000 »

If I'm running some triggers like this and maybe I clear all of the enemies in that room before the triggers end, could I possibly stop the attacking without deactivating this?


Send ("attack "..target)
tempTimer(3.18, [[send("attack "..target)]])
tempTimer(6.36, [[send("attack "..target)]])
tempTimer(9.54, [[send("diag me")]])
tempTimer(10.24, [[send("attack "..target)]])
tempTimer(13.42, [[send("attack "..target)]])
tempTimer(16.6, [[send("attack "..target)]])
tempTimer(19.78, [[send("diag me")]])
tempTimer(20.49, [[send("attack "..target)]])
tempTimer(23.57, [[send("attack "..target)]])
tempTimer(26.75, [[send("attack "..target)]])
tempTimer(29.94, [[send("diag me")]])

Post Reply