Help - Search - Members - Calendar
Full Version: Trying to add mob selection from a fellow command
AC Tools Everything Macro > Other Scripting Tools > Skunkworks
Jscho32
I'm trying to edit my warbot script to select a mob based on the OID that another fellow member says.

Leader has the code:
CODE
var Aco = skapi.acoSelected;
Chat.Fellow("WBF: Attack Current Selected [" + Util.Hex(Aco.oid) + "] ")

example: shows up as [Fellowship] You say, "WBF: Attack Current Selected [0x34873f67]"

I then want the other fellow members extract the OID from the message and then select that OID, and attack it if it is a mob. The problem I have is I cannot find anything in the skunkworks documents that has a feature that will select a target by OID. All I could find is by ACO, which would not work when there are multiple mobs with the same name. If I can't select a OID, would the only possible way be to select every mob and compare it to the OID in fellow chat, and go to the next mob if it doesn't match, until it matches? Here's the code I have so far for selecting it(edited from code in Warbot2.15 player detection)...

CODE
if (Command == "WBF:") {
    if (flagFellowAttacking && (szMsg.match(/WBF: Attack Current Selected/))) {
            // Mob selected by leader. Select that mob.
         var Pattern1 = new RegExp("(.*[\[]|[\]].*$)", "g");        // Extract the mob's OID
         DetectedMob = szMsg.replace(Pattern1, "");
Log.OutD("Main_OnTellFellow: End, Mob [" + DetectedMob + "] selected by fellow leader [" + szSender + "]. Selecting...", true);    // DetectedMob shows the OID
  
// I need to select the OID here somehow...
} // endif


skapi.SelectAco(aco) doesn't seem to work if there is more than one mob with that name... Any ideas?
GKusnick
QUOTE(Jscho32 @ Nov 8 2007, 05:04 PM) *
All I could find is by ACO, which would not work when there are multiple mobs with the same name.

What makes you think that wouldn't work? Each selectable object has a unique ACO (just as it has a unique OID). skapi.SelectAco selects the specific ACO you pass in. The object's name doesn't enter into it.

If you're asking how to get the right ACO to pass in, see skapi.AcoFromOid.

Since this is a general question about selecting objects, I'm letting it stand in its own thread. But for questions specifically about modifying the Warbot script, please use the existing Warbot thread. Thanks.
Jscho32
The reason why I didn't think it would work doing skapi.SelectAco(aco) is because when I do skapi.acoSelected on different mobs of the same name, they all return the same result-their name. So if I go and select that aco(which returned as a name before) and there's more than one mob with that name, it wouldn't work.

CODE
if (Command == "WBF:") {
    if (flagFellowAttacking && (szMsg.match(/WBF: Attack Current Selected/))) {
            // Mob selected by leader. Attack that mob.  
         var Pattern1 = new RegExp("(.*[\[]|[\]].*$)", "g");        // Extract the mob's OID
         DetectedMob = szMsg.replace(Pattern1, "");
Log.OutD("Main_OnTellFellow: End, Mob [" + DetectedMob + "] selected by fellow leader [" + szSender + "]. Attacking...", true);      

var oid = DetectedMob;  // oid is the mob's oid
var aco = skapi.AcoFromOid(oid);  // aco is the mob's aco(from their oid)
skapi.SelectAco(aco);  // select the aco    
} // endif


Can't seem to figure out what's wrong with this.
GKusnick
QUOTE(Jscho32 @ Nov 8 2007, 07:12 PM) *
The reason why I didn't think it would work doing skapi.SelectAco(aco) is because when I do skapi.acoSelected on different mobs of the same name, they all return the same result-their name.

If you read the documentation for acoSelected, you'll see that it returns not just the selected object's name, but the object itself (the ACO) with all its methods and properties. If you try to print out the ACO without selecting one of its methods or properties, it will print the name, since that's the default property, but what you actually have in your hand is the complete object.

CODE
Log.Out(aco);           // Prints name (default property).
Log.Out(aco.szName);    // Prints name.
Log.Out(aco.cpyValue);  // Prints value.

Your problem in your example probably comes from this:

CODE
DetectedMob = szMsg.replace(Pattern1, "");  // DetectedMob is a string.
var oid = DetectedMob;                      // oid is a string.
var aco = skapi.AcoFromOid(oid);            // AcoFromOid expects a long.

The value you've assigned to DetectedMob is a text string, e.g. "0x12345678". But a valid OID isn't text, it's a number, i.e. a value of type long, and that's what skapi.AcoFromOid is expecting. So you need to convert your text string to a long before passing it in. See your JScript docs for information on how to do that.

If the whole notion of data types, strings-v.-numbers, and strings-v.-objects has you confused, read the section of the JSciprt docs on JScript Data Types. (In fact it wouldn't hurt to read through the entire JScript User's Guide if you haven't already done so.)
Jscho32
Ah ok, thanks for the clarification

Not sure if this is the correct way, but it works:
CODE
var oid = parseInt(DetectedMob);
var aco = skapi.AcoFromOid(oid);  
skapi.SelectAco(aco);


Also, is there an waitevent evid for a new mob/target being select? I read through them all but none of them seem to be used for targeting/selection.


QUOTE
[Fellowship]Joe Smith says, "WBF: Attack Current Selected: [0x34a8a6e9]"
[0x34a8a6e9] selected by [Joe Smith]. Selecting...
Chicken will be attacked shortly...
You say, "Zojak Quaguz"
You obliterate Chicken!

yay
Thanks for the help GKusnick!
GKusnick
QUOTE(Jscho32 @ Nov 9 2007, 12:23 PM) *
Also, is there an waitevent evid for a new mob/target being select? I read through them all but none of them seem to be used for targeting/selection.

Events come from the server, whereas target selection is purely a client-side UI function. The server doesn't know or care what you have selected; it cares only about which objects you actually use or attack. Hence, no selection events from the server.
Jscho32
Alright, I'll stick to a 1 second delay laugh.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.