Wiki for Scripting Player Selection / Cycling?

Discussion in 'Halo and Forge Discussion' started by Darwi, Dec 11, 2020.

  1. Darwi

    Darwi ONI Agent

    Messages:
    7
    Likes Received:
    0
    I'm only just getting into some scripting. But one thing that took a week or so to get my head around, and doesn't seem to be well documented anywhere, is how to cycle through players (to read scores etc), or how to label players (for objects to follow etc).

    Anyway... I seem to have it up and working on both accounts.

    Is it worth me doing a tutorial here or on the scripting wiki? We've still got a year or so until Infinite drops and I guess we don't know what improvements will come. Obviously if this exists and I just didn't find it - I won't worry.

    Let me know.
     
  2. Darwi

    Darwi ONI Agent

    Messages:
    7
    Likes Received:
    0
    The following bit describes how I cycled through players for my "Spongacus" custom game type. It doesn't look like there are a lot of active Halo 5 scripters out there - but I would love to know if anyone is doing anything different.

    Essentially we;

    a) Cycle using Player [alpha] numbers.

    b) Use arbitrary values; 0 (waiting), 1 (selected), and 2 (used).

    c) Filter Players with the mod-list function number[include] - which reads their alpha channel values.

    d) Act on the currently selected player using a Number:Check for Player[alpha] = 1. The player data is passed to subsequent actions inside the ‘EXTRA’ and ‘ACTIVATOR’ objects.

    Here is the "Spongacus" script in all it's glory. The general cycling technique is demonstrated in the first three scripts.

    My shorthand is;
    - Scope + channel; eg. Pa = Player [alpha], Gs = Global [sierra].
    - Mod-list {add + includes - excludes}. eg. {P+0-D+SF} = Players[add], Number:0[include], Dead[exclude], Select First.
    - *fd = force dirty
    - {T} = This, {A} = Activator, {E} = Extra.

    a$1: Timer (0.10s) // cycle timer
    @1: Pa {P+1} SET 2 // move previously selected (1) to used (2)
    @2: Pa {P+0-D+SF} SET 1 *fd // move one from waiting (0) to selected (1)
    @3: O {T} SET ObjCount {P+0} *fd // count those waiting (0).
    ---

    a$2: NumChk O {T} = 0 // when there are no players waiting(0)...
    @1: Pa {P+2} SET 0 // refresh used (2) back to waiting (0).
    ---
    a$3: NumChk Pa = 1 // when a new player has been selected...
    @1: Gs SET GameValue {A} [P-Score] // save selected player's score in Gs

    And that's it. You now have a timer that continually cycles through each player and reads their current score! For the rest of the 'Spongacus' script we want to keep track of the high score (saved in global hotel) and use that to work out a range of how far each player is from the lead; (high score - player score) divided by 4.

    ---

    a$4: NumChk Gs > Gh // if we have a new high score...
    @1: Gh SET Gs // update the high score
    ---

    a$5: NumChk Pa = 1 // with newly selected player...
    @1: Go SET Po {A} // get the player's old score range
    @2: Gn SET Gh // work out new score range; (hotel - sierra) / 4
    @3: Gn DEC Gs
    @4: Gn DIV 4 *fd
    ---
    a$6: NumChk Gn != Go // when the player has a new score range...
    @1: Trait {P+1} Clr // reset trait
    @1: Gd SET Gn *fd // trigger second brain to change traits
    @2: Po {P+1} SET Gn // save to old range for next cycle
    ---
    a$7: NumChk Pa = 1 // use Ts to keep track of team scores
    @1: Ts {E} INC Gs // first add the player's current score
    @2: Ts {E} DEC Ps {A} // then deduct the previous cycle's score
    @3: Score T {E} SET Ts {A} // update formal score.
    @4: Ps {E} SET Gs // save score for use in the next cycle.

    A second brain then waits for Global[delta] to change and sets new player traits depending on the range.

    b$1: NumChk Gd = 1 // ie. score now in range 4 - 7 points from lead
    @1: Trait {E} alpha // set for 150% shields

    I'm still experimenting but currently using;
    - Delta 0 = normal.
    - Delta 1 = alpha trait; 150% shields
    - Delta 2 = bravo trait; 200% shields
    - Delta 3 = charlie trait; 150% health, 300% shields
    - Delta >= 4 = delta trait; 200% health, 500% shields
     
    #2 Darwi, Dec 16, 2020
    Last edited: Dec 23, 2020
  3. Darwi

    Darwi ONI Agent

    Messages:
    7
    Likes Received:
    0
    Part II is about allocating labels to each player. This is useful if you need to set up teams, particular roles, or to make objects follow players around. What we will do is look at a script that allocates labels and then makes an object follow a player if needed.

    - Aim is to allocate labels user-alpha through user-papa for up to 16 players.

    - Uses label user-zulu to keep track of players already labelled.

    - Needs one timer script and then another two scripts for each label (up to 33 in total).

    - use Global variables xray, yankee, and zulu to produce a number between 0 and 63 that helps to identify when when we need to apply a label.


    First we need a timer that repeatedly outputs these as factors of four on Global [yankee] for each user label; 0 for alpha, 4 for bravo, 8 for charlie, 12 for delta, and so on. You'll need to park this on a script brain somewhere.

    a$1: Timer (0.20s) // Doesn't need to be super fast
    @1: Gx INC 1
    @2: Gx REM GameValue [Players] // repeatedly counts 0 to (players - 1).
    @3: Gy SET Gx
    @4: Gy MUL 4 *fd // Outputs factors of four for each player.


    Then we have two scripts for each user label. These can be on separate brains or objects (if you want objects to follow the labelled player).

    The following are the scripts for user:alpha.

    b$1: NumChk Gy = 0 // 0 is for user:alpha
    @1: Gz SET Obj Count {P-z+SF} // 1 if any unlabelled players else 0.
    @2: Gz MUL * 2 // Changes our value to 0 or 2.
    @3: Gz INC ObjCount {P+a} // Adds 1 user:alpha is already in use.
    @4: Gz INC Gy // Final result is Gy +0, +1, +2, or +3.
    ---
    b$2: NumChk Gz = 2 // Looking for Gy + 2
    @1: Label Apply alpha {P+z-D+SF} // applies user:alpha to one unlabelled player.
    @2: Label Apply zulu {P+a} // marks the player as labelled.

    If you want an object to follow this player then put the scripts on the object and the add the scripts below - which simply work by asking if there is a player with the same user label then move towards that player else hide (reposition).

    ---

    b$3: Timer 0.05s // timer for object to follow player.
    @1: O {T} = ObjCount {P+a} // = 1 if a player has label user:alpha
    ---
    b$4: NumChk O {T} = 0 // no labelled player to follow...
    @1: Reposition {T} // so hide the object.
    ---
    b$5: NumChk O {T} = 1 // there is a labelled player to follow...

    @1: Move {T} {P+a} 1.2s // so move the object to the player.


    You can then copy these objects and amend for other labels.

    For example user:bravo would trigger on Global [yankee] = 4 and Global [zulu] = 6. You would also need to change the label references from user:alpha to user:bravo.

    User:charlie would trigger on Global [yankee] = 8 and Global [zulu] = 10...
     
    #3 Darwi, Dec 17, 2020
    Last edited: Dec 23, 2020

Share This Page