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:
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:
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:
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