Spawn auto have my commander already selected so that I don't have to click on it at the start.

Discussion in 'Mod Discussions' started by tatsujb, March 2, 2014.

  1. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    Okay so I have an idea but I don't feel like writing the code right now as I am at school, I will do some of what I call paraphrase coding, you should get the idea:
    Code:
    $("whatever the id of the start button is").append("onclick='startSelectLoop()'")
    
    function startSelectLoop() {
    loop  comSelect api.select.commander();
    if ("commander").is("selected") {
    end comSelect
    }
    else {
    "keep doing loop"
    }
    }
    something like that, no idea how to actually code that and my syntax is fu***ng horrible, but you should get the idea.

    EDIT: If you do use this in the mod and make it before I do mention me as author please, also if I make it before you I will mention you as author also
  2. tatsujb

    tatsujb Post Master General

    Messages:
    12,902
    Likes Received:
    5,385
    oh relax, if ever this comes out it's everyone's, @raevn participated, @wondible , me and you.
    cptconundrum likes this.
  3. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    If it is possible to write this does it seem like it would work?
  4. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Just wait until the game has started then select the commander? PAStats says hijack handlers.server_state to know when we're playing:
    Code:
    	var oldServerState = handlers.server_state;
    	handlers.server_state = function(m) {
    		oldServerState(m);
    		if (m.state !== 'game_over' && m.url && m.url !== window.location.href) {
    			paStatsGlobal.unlockGame();
    		}
    		switch(m.state) {
    			case 'landing':
    				pasHadReconnect = false;
    				break;
    			case 'game_over':
    				gameIsOverOrPlayerIsDead = true;
    				paStatsGlobal.unlockGame();
    				break;
    			case 'playing':
    				updatePlayStartTime();
    				maySetupReportInterval();
    				break;
    		}
    	};
    
  5. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    Hey I know that code!
    Yeah I'd try to add the call in that handler.

    EDIT:
    You know what is funny?
    Calling the old handler before my code is actually a dangerous thing because the old handler has a path that ends in setting the current location to some other page, I am not sure if that call returns in that case.
    hmm
    proeleert likes this.
  6. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    showLanding is set from server_state. Immediate, setTimeout(0) and I think setTimeout(100) didn't work.
  7. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I tried a few hooks that all trigger "around the start of a game" in PA Stats and none worked.
  8. trialq

    trialq Post Master General

    Messages:
    1,295
    Likes Received:
    917
    Code:
       var oldServerState = handlers.server_state;
       handlers.server_state = function(m) {
         if ( not_noticed_we_are_playing_yet ) {
           if (m.state === 'playing') {
             //we have noticed we're playing now
             api.select.commander();
             //stop selection of commander everytime handlers.server_state gets called
             not_noticed_we_are_playing_yet = false;
           }
         }
    
         //moved to end because of Cola's reply
         oldServerState(m);
       };
    Haven't tried it, but something like that is all you need?
  9. tatsujb

    tatsujb Post Master General

    Messages:
    12,902
    Likes Received:
    5,385
    this is the most communal mod yet, is it not?
    Last edited: March 3, 2014
  10. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    I did just that. Like I pasted it into my PA Stats code while doing other tests.
  11. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    did it work?
  12. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    See my post above.
  13. Corang

    Corang Well-Known Member

    Messages:
    772
    Likes Received:
    313
    ah sorry, didn't see that before
  14. tatsujb

    tatsujb Post Master General

    Messages:
    12,902
    Likes Received:
    5,385
  15. Raevn

    Raevn Moderator Alumni

    Messages:
    4,226
    Likes Received:
    4,324
    A bit of a hacky way to do it:

    Add it to the handlers.army function in live_game/live_game_econ.

    This works (just tested), but you'll need to add some filtering to prevent it selecting your commander at times other than the start (eg., when pressing F5, and possibly others - not sure exactly when this function is called).
  16. pownie

    pownie Active Member

    Messages:
    80
    Likes Received:
    131
    Quite the demand of recognition for butchering the syntax of a simple
    Code:
    while (condition) { do(); }
    ;)
    I actually tried
    Code:
    while (model.selection() === null) { api.select.commander(); }
    and... you really shouldn't. As effective as an endless loop of calling the api command. Had to kill the PA process.

    This in the server_state handler though works fine for me
    Code:
    function selectComWhenNothingSelected() { if (model.selection() === null && model.armySize() < 2) { api.select.commander(); setTimeout(function() { selectComWhenNothingSelected(); }, 50) ; } }
    selectComWhenNothingSelected();
    
    Edit: Okay, it does trigger again after F5 so I added the armySize check. Also I increased the timeout a bit. Because sadly selecting the commander via api command (even when unsuccesful) also plays a sound and calling that very rapidly (only happened to me once in a few games) sounds really bad.

    Edit: Thinking about it more, this might fail when you're in a game where you're annihilated or only spectating, it would get stuck trying to endlessly select a non-existing commander. armySize == 1 might not be good enough. I don't know in which order game state and armyCount are updated. I'll test this later. I also tried to turn it into a stand alone mod (that I'd just attach here, for anyone to grab) but got stuck with Coherent complaining to be unable to find my script. And after an hour of no progress, despite the seemingly same attempt working for my other mod, I got too frustrated to reduce my remaining sleep time below 3h30m...
    Last edited: March 5, 2014
    tatsujb likes this.
  17. tatsujb

    tatsujb Post Master General

    Messages:
    12,902
    Likes Received:
    5,385
    good job, still soldier, we can work from there.
  18. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    Fr33Lancer likes this.
  19. tatsujb

    tatsujb Post Master General

    Messages:
    12,902
    Likes Received:
    5,385
    You kinda gotta put "everyone on Modder's forum" on author.
  20. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    My impression is that the PAMM layout won't work very well with a long list of names. Perhaps the description?

Share This Page