Someone knows how to usetrigger trUnitHighlight in .xs functionality? Is there any documentation?

Hi everyone,

Does someone know how to highlight a unit from a .xs script? I have found this function in the documentation, but it says “Does something to highlight the units selected”. Unfortunately, it does nothing… I don’t see any highlighting.

Here is my .xs code:

xsSetContextPlayer(1);
kbLookAtAllUnitsOnMap();
int unitQueryId = kbUnitQueryCreate(“query1”);
kbUnitQuerySetPlayerRelation(unitQueryId, cPlayerRelationSelf);
kbUnitQuerySetState(unitQueryId, cUnitStateAlive);
kbUnitQuerySetUnitType(unitQueryId, ############ );
kbUnitQueryExecute(unitQueryId);
int queryCount = kbUnitQueryNumberResults(unitQueryId);

for (i = 0; < queryCount) {
int unitId = kbUnitQueryGetResult(unitQueryId, i);
trUnitSelectByID(unitId);
trUnitHighlight(2);
trUnitHighlight(2, true);
trUnitHighlight(2, false);
}

Maybe someone knows how to highlight a unit, any flash or adding some color? I saw in some tutorial missions, that there is a yellow circle around the explorer.

Well, the tutorial missions, and campaigns are all fully build in the scenario editor, except the AI Scripts s:

Doesn’t trUnitHighlight only accept one parameter?

Yes, by the doc, but I found some examples with using the 2nd bool param, but not sure what is it for

Can you send chat of the different variables?
Chat queryCount would be great

  1. Use a static variable to store the query, or destroy the query after use.
  2. I recommend clearing selection.
  3. Also, maybe try to reset the context?

I don’t think any of these will solve your issue but I wanted to reply anyway :person_shrugging:

Thanks guys.
I have solved the issue, there wasn’t need to add a second bool param and 1st param accepts float type. This function flashes the unit, it uses the same visual mechanism as when a unit tries to garrison to a building or a villager right-click on a resource.
Honestly not sure what exactly was changed, I just have tried many things. Now it works as expected… :slight_smile:

2 more points to discuss if someone is interested.

  1. Is it possible to change the flash color from white to some other one, with RGB selection for example?
  2. The explorer unit has a specific yellow circle around it, is it possible to apply this to another unit? Added screenshot.
    Screenshot 2023-10-21 232631

Thanks!

  1. What is more performant in case of complexity?
    I think static variables are better if the script is being used during the whole game, right?
    So we don’t need to destroy the query if it is being stored in a static variable, right? Just reset the result after each execute, right?
  2. Thanks, added this.
  3. Yes, added this too.

Sorry, I didn’t understand.
Do you mean to use chat as a logger and send query results there?
Well, I have used trOverlayText() to see the query result and list of found unit IDs, it searches units correctly.

int queryCount = kbUnitQueryNumberResults(unitQueryId);
sendChatToPlayer(int player,queryCount+"");
but given that you already solved it, I suppose it doesn’t matter. Besides, you already used trOverlayText() for that effect.

Thanks.
Also, do you know if it is possible to draw text not on the menu, but on the world by vector position? We can get the unit’s position vector object (x,y,z) and theoretically draw a text near this position, for example unit’s name.

You’d need to get the position of the camera center and if the unit is in camera. I haven’t found triggers that do that, but if there are, then it’s just vector algebra

Yes, static variables are better for rules that use queries often. Personally, I prefer to reset before executing (similarly to clearing unit selection). But either way is fine as long as you don’t forget ^.^

PS: I’m glad you got it to work! About the explorer, I’m 99% sure it’s just an animated selection box in the explorer’s anim file.

Thanks, that makes sense!

Do you know how to transform world coordinates to coordinates on miniMap and draw some lines/rectangles/circles on the miniMap by position?

Thanks!

And what about color for the highlight effect? Is it possible to change?

2 more things to ask:

  1. trOverlayText works poorly, it clears previous text on the screen so it is impossible to keep more than one text instance on the screen at once. Is it possible to show many texts on the screen maybe by any other command?
  2. Is it possible to draw an icon on the screen? The icon is being shown correctly if we send this string to chat by trChatSend() - <icon=“(40)(resources\images\icons\techs\gang_saw\gang_saw_64x64.png)”>. But is it possible to show it without chat, just an image on the screen by position?

Could you please remember the commands to find the current camera location? I haven’t found them… I have found only cameraDump(), but it returns void and not sure how to get the result

I searched and haven’t found anything similar

The position of an unit in camera should be cameraWorldPosition - unitWorldPosition
or the other way around.
But again, dor that you need to gt caremaeWorldPosition and I don’t remember if there exist a trigger like that

Edit: you can also multiquote in the same message. There’s no need to write a message per quote