'hunt' alias

Post Reply
User avatar
ulysses
Posts: 52
Joined: Fri Jan 05, 2018 7:43 pm

'hunt' alias

Post by ulysses »

Hi,

Just getting started with this, so forgive me if this is standard stuff. I'm trying to write an alias that will hunt for a target. It looks like this;

Code: Select all

moves = {"s", "s", "se", ... }
m = moves
for i,move in ipairs(moves) do
        send(move)
        if traderHere then
                send("kill trader") 
                break 
        else
                traderHere = false
        end
end
I have a trigger set up which sets traderHere = true if the room contains a trader. The issue is that the alias just blats all the moves into the buffer and doesn't wait for the screen to refresh. How do I make it wait to refresh? Pehaps there is a more elegant way to achieve this kind of search and do something pattern?

Thanks,
Ulysses.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Jor'Mox
Posts: 1146
Joined: Wed Apr 03, 2013 2:19 am

Re: 'hunt' alias

Post by Jor'Mox »

I find it to be a fairly common misconception that the code will wait at appropriate points on input from the game, which it absolutely will not do. What you want to do, namely walk along a designated path, stop in each room, check for your desired target, attack that target if present, then continue along the path until reaching the end, is something that will require an organized effort of multiple triggers and a few variables to keep track of relevant information, not just crammed into a single alias.

Here is a breakdown of essentially what you need to do:
First, an alias to kick things off, which will define a table of movements to use, and enable relevant triggers (via use of enableTrigger("Trigger Name") commands). Presumably, the alias will also take the very first move, like this: send(table.remove(moves,1))

Next, you need a trigger to detect when you have actually moved into a new room, and track that fact in a variable, like this:
Code: [show] | [select all] lua
newRoom = true
I like to use lines commonly found at the end of room descriptions listing the exits from a room as my indicator that I have entered a new room, as they are fairly distinctive.

Then, of course, you have your trigger to find your desired target, which you have already created.

Next, you need a trigger off of something that will come after the text indicating a new room, and the text indicating the presence of your target. A prompt trigger makes the most sense here, and in it you look at the two tracking variables to determine your next step. If you are in a new room, then look to see if there is a target. If there is a target attack it, if there isn't move to the next room. Like this:
Code: [show] | [select all] lua
if newRoom then
    newRoom = false
    if traderHere then
        traderHere = false
        send("kill trader")
    elseif not table.is_empty(moves) then
        send(table.remove(moves,1))
    else
        disableTrigger("Trigger Name") -- the path is finished, turn off your triggers here
    end
end
And then finally, you need a trigger to detect when you have finished killing a target, so that you can resume walking along the path looking for more, and it should have code something like this:
Code: [show] | [select all] lua
if not table.is_empty(moves) then
    send(table.remove(moves,1))
else
    disableTrigger("Trigger Name") -- the path is finished, turn off your triggers here
end

User avatar
ulysses
Posts: 52
Joined: Fri Jan 05, 2018 7:43 pm

Re: 'hunt' alias

Post by ulysses »

Hey Jor'Mox,

Thanks very much - I think I can now see how to put all this together. I'll report back when it's all working!

Best wishes,
Ulysses.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

User avatar
ulysses
Posts: 52
Joined: Fri Jan 05, 2018 7:43 pm

Re: 'hunt' alias

Post by ulysses »

Got it all working - thanks again! Disabled the trigger after starting the fight since I want to handle the fight manually. To resume I just type the starting alias again. For this reason I have another init alias which defines the moves separately to the one which sets the whole thing going. With time I can define a static move array and have an intelligent pointer into the array based on the room description (i.e. it will know where it is within those moves). Also have another pointer indicating if I'm travelling backwards or forwards through the moves. A rainy-day project!

Thanks again for your wonderful help, Jor'Mox.
Wod :mrgreen:
CthulhuMUD
www.cthulhumud.com
A hugely entertaining MUD based on the horror writings of HP Lovecraft.

Post Reply