[QUESTION] Pass units selected from PA to UI

Discussion in 'Mod Discussions' started by Corang, January 23, 2014.

  1. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    So I am currently working on a mod, and I need to know if there is a way to "pull" what units are selected from PA. For instance if i am in-game and i have 3 adv vehicle fabbers and 20 bot fabbers is there any way for me to pull that those units are selected from PA to use in a UI mod? Again I would need to know what units are selected and how many of each unit is selected.
  2. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    Take a look at SelectionViewModel in live_game.js (line 370). You can get the current selection details from there.
  3. elitedanzel

    elitedanzel Active Member

    Messages:
    151
    Likes Received:
    137
  4. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    God, hate my limited knowledge of js i am trying to learn as I go and I don't understand the code in live_game.js or in the build power mod, if it wouldn't be too much trouble could someone write me a code snippet to pass what units are selected to js?
  5. DeathByDenim

    DeathByDenim Post Master General

    Messages:
    4,328
    Likes Received:
    2,125
    I haven't tested it, but the link elitedanzel sent to his mod has what you want. From his GitHub, it seems you need to take over the function handler.selection. So something like this (in less convoluted JavaScript :) ) :
    Code:
    var oldselectionhandler = handler.selection; // Save the original
    handler.selection = function (payload) {
      oldselectionhandler(payload); // Apply the original first
      // Do your stuff with payload here!
      console.log(payload);
    };
    You can use the Debugger to inspect the contents of payload to take what you want. You can also look at the function self.parseSelection on line 1410 in live_game.js to see how PA handles the payload.

    Hope that helps!
  6. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    I will look into it when I get home but right now I have School so I won't be back until 3 pm est, I will let you guys know what I have figured out.

Share This Page