silbinarywolf / sw-zombie-fortress

A VScript mod that aims to be a faithful reimplementation of the Zombie Fortress mode made originally with SourceMod
Other
0 stars 0 forks source link

last player to join is always on the zombie team #25

Closed silbinarywolf closed 1 year ago

silbinarywolf commented 1 year ago

This will be fixed in 0.3.1

Discovered in playtesting tonight with some folks.

silbinarywolf commented 1 year ago

The fix:

// Based on: https://stackoverflow.com/a/2450976/5013410
::ShuffleArray <- function(array) {
    local currentIndex = array.len();

    // While there remain elements to shuffle.
    while (currentIndex > 0) {
        // Pick a remaining element.
        local randomIndex = RandomInt(0, currentIndex - 1);
        currentIndex--;

        // And swap it with the current element.
        local current = array[currentIndex];
        local random = array[randomIndex];
        array[currentIndex] = random;
        array[randomIndex] = current;
    }
}