[HTML5] Targeting of Multiple Mobs (for Stormhammer)

I'm wondering if there's any simple way to set up an alias in the HTML5 client that checks a room for mobs, takes the top 3 (or 2 or 1) off the list, and assigns their IDs to variables. The reason I want to be able to do this is so that I can set up a binding for stormhammer that attacks those three targets. I would use IH to check, but it lists objects as well as mobs, and I only want mobs. Is there a way to only display denizen IDs?

Any help would be greatly appreciated.

Best Answers

Answers

  • How exactly would I go about filtering a list with that attribute? Is it something you append onto the INFO HERE command?
  • I was hoping to be able to set up a trigger to check for multiple types of creatures so that I could hit them all if necessary. That's probably my best solution for now, though.
  • An exception list would probably be your best bet then.  You would need to make a table containing everything you don't want to target(I am sure you can find one if you search for Stormhammer targetting scripts for different clients) and then add all the variables off IH to a separate table UNLESS they are in the first table.  You would run into a few obvious problems from just copying an older script, the main one being all the new minipets and custom pets people have bought over the years, but it could be doable.  You could also check GMCP to ensure you aren't in a city, so you don't have to add all the specific denizens for each city you could possibly visit and risk accidentally enabling your script.  

    Alternately, you could make the first table a list of things you only want to be able to stormhammer target in this manner, and only add things to the second table if they first table contains them.  I have no clue how to HTML5, so someone else would have to expand on the table functions for you. 
  • edited December 2014
    You want to use GMCP for this - that's where the attribute @Klendathu is talking about lives. Parsing IH is a much bigger pain than parsing GMCP in almost all cases.

    This details the relevant GMCP messages: https://github.com/keneanung/GMCPAdditions/#charitems

    You need to add something to your onGMCP function to capture the entities in the room. So you're going to test on every gmcp message received (this is what putting code in onGMCP does) if it's a Char.Items.List message by checking to see if args.gmcp_method == "Char.Items.List". Then you need to know if args.gmcp_args.location == "room".

    If both of those are true, save the items array with something like roomArray = args.gmcp_args.items. (You should declare roomArray and all other variables in onLoad before using them.)

    Once you have that, you want to filter out everything that isn't a mob - luckily, JavaScript arrays have a filter method built in. So all you need to do is call roomArray.filter(FUNCTION) where FUNCTION is a function that gets passed each element of the array and then the filter method call returns only the elements of the array for which FUNCTION returns true. I just used an anonymous function here since you're probably not going to be reusing it.

    For your FUNCTION, you want to see if the attrib string for each item contains 'm'. JavaScript has a slightly weird way of testing to see if a letter is in a string, which is what we need to do here - if a letter isn't in a string, its index is -1, so we want all of the items that DON'T return a -1 index for 'm' (i.e., all of them that have 'm' in them).

    So you end up with something like:

    if (args.gmcp_method == "Char.Items.List" && args.gmcp_args.location == "room") {
       roomArray = args.gmcp.items;
       filteredArray = roomArray.filter(function (item) {
          return item.attrib.indexOf('m') != -1;
       }
    }

    That'll get you a list of mobs. Then just have your stormhammer alias use the first three (or a random three, or whatever) elements of that array like filteredArray[1].id, which will get you the id number of the first thing in your list of mobs.

    You can also filter out a list of exceptions similarly if you want to define them later for some reason.

    Caveats: I haven't actually tested this, it may require a little bit of tweaking. I can't remember if corpses have the 'm' attribute too, but if they do, you need to make the test for 'm' AND NOT 'd'. I also can't remember if Char.Items.Add or Char.Items.Remove need to be coded too or if they always come with a Char.Items.List message, but that should be pretty straightforward if they do need to be (for remove, check to see if the id is in your list of mobs, if it is, remove it from your mob array; for add, check to see if it has attribute 'm', if it does append it to your mob array).
  • Tael said:
     I also can't remember if Char.Items.Add or Char.Items.Remove need to be coded too or if they always come with a Char.Items.List message
    I can answer that. The full list is only sent wen entering a room or doing a look. Everything that enters after you or leaves while you are in the room gets changed via Add and Remove.
  • Keneanung said:
    Tael said:
     I also can't remember if Char.Items.Add or Char.Items.Remove need to be coded too or if they always come with a Char.Items.List message
    I can answer that. The full list is only sent wen entering a room or doing a look. Everything that enters after you or leaves while you are in the room gets changed via Add and Remove.
    Yeah - you want to make and maintain a list, clear and rebuild on list, add/remove on those two, otherwise changes don't get updated.
    Current scripts: GoldTracker 1.2, mData 1.1
    Site: https://github.com/trevize-achaea/scripts/releases
    Thread: http://forums.achaea.com/discussion/4064/trevizes-scripts
    Latest update: 9/26/2015 better character name handling in GoldTracker, separation of script and settings, addition of gold report and gold distribute aliases.
Sign In or Register to comment.