Untitled
raw download clone
JAVASCRIPT
views 68
,
size 5195 b
["help"].forEach(function (command) {
    nm.System.DisableChatCommandDisplay(command, true)
})

nm.DisableAutoShaman()
nm.DisableAutoNewGame()
nm.DisableAutoTimeLeft()

var first = false

var players = {}
var options = {
    Keys: [0x28, 0x53, 0x20],
}
var maps = ["@4075355", "@4074458", "@4074459", "@4074460", "@4074461", "@4074464", "@4074438", "@4074439", "@4074483", "@4074496", "@4074494",
    "@4074493", "@4076664,4076668", "@4076666", "@4076781", "@4076772", "@4076764", "@4076748", "@4074583", "@4074586", "@4074587", "@4076836",
    "@4076839", "@4076840", "@4076850", "@4076951", "@4077869", "@4077505", "@4078343", "@4078349", "@4077872", "@4077953", "@4077521", "@4076872",
    "@4076962", "@4077854", "@4077468", "@4077503", "@4077970", "@4077049", "@4078272", "@4077962", "@4077518", "@4076852", "@4077876", "@4077500",
    "@4077967", "@4078347", "@4077875", "@4077861", "@4078273", "@4076855", "@4077974", "@4077883", "@4076853", "@5000723", "@5000540", "@5000524",
    "@5000527", "@5000530", "@4077881", "@4078344", "@4077648", "@5001225", "@5000761", "@5000756", "@5000757", "@5003258", "@5002857", "@5001668",
    "@5001664", "@5001717", "@5001661", "@5001408", "@5001401"]
var state = {
    Started: false,
}

function EventNewGame() {
    state.Started = false

    nm.SetUIMapName("<N>Deathmatch")

    for (var playerName in players) {
        var player = players[playerName]

        player.PreviousCannonID = 0
        player.ShootAt = Date.now()
    }
}

function EventNewPlayer(playerName) {
    nm.SetUIMapName("<N>Deathmatch", playerName)

    players[playerName] = {
        Offset: {
            x: 2,
            y: 10,
        },
        PreviousCannonID: 0,
        ShootAt: Date.now(),

        canShoot: function () {
            if (this.ShootAt < (Date.now() - 800)) {
                return true
            }
            return false
        }
    }

    for (var i in options.Keys) {
        var key = options.Keys[i]

        nm.BindKeyboard(playerName, key, true, true);
    }
}


function EventPlayerDied(playerName) {
    if (players[playerName] == undefined) {
        return
    }
    var alivePlayers = getAlivePlayers()

    nm.SetUIMapName("<N>Deathmatch: <V>" + alivePlayers.length.toString() + "</V> в живых")
}

function EventPlayerLeft(playerName) {
    delete players[playerName]
}

function EventKeyboard(playerName, keyCode, down, x, y) {
    if (!state.Started || players[playerName] == undefined) {
        return
    }
    var player = players[playerName]
    var mouse = nm.Room.GetPlayer(playerName)
    if (mouse.IsDead) {
        return
    }

    if (keyCode == 0x28 || keyCode == 0x53 || keyCode == 0x20) {
        if (player.canShoot()) {
            player.ShootAt = Date.now()

            if (player.PreviousCannonID !== 0) {
                nm.RemoveObject(player.PreviousCannonID)
            }

            var posX = mouse.Turn == 0 ? (x - player.Offset.x) : (x + player.Offset.x)
            var posY = y + player.Offset.y
            var angle = mouse.Turn == 0 ? 270 : 90

            player.PreviousCannonID = nm.AddShamanObject(17, posX, posY, angle, 0, 0, false)
        }
    }
}

function EventChatCommand(playerName, command) {
    if (players[playerName] == undefined) {
        return
    }
    var player = players[playerName]

    var args = command.split(" ")
    switch (args[0]) {
        case "offset":
        case "off":
            if (args.length == 0) {
                nm.ChatMessage("<J># <BL>Офссет: X " + player.Offset.x + " | Y " + player.Offset.y, playerName)
                break
            }
            if (args.length !== 3) {
                nm.ChatMessage("<J># <BL>Используйте: !off x y", playerName)
                break
            }
            player.Offset.x = Number(args[1])
            player.Offset.y = Number(args[2])

            nm.ChatMessage("<J># <BL>Новый оффсет: X " + player.Offset.x + " | Y " + player.Offset.y, playerName)
            break;
        case "help":
            nm.ChatMessage("<J># <BL>- Help", playerName)
            nm.ChatMessage("<J># <BL>Используйте: !off x y", playerName)
            break;
    }
}

function EventLoop(time, remaining) {
    if (!first) {
        nm.Room.GetPlayers().forEach(function (player, i) {
            EventNewPlayer(player.Name);
        });

        nm.NewGame(maps[Math.floor(Math.random() * maps.length)])

        first = true
        return
    }

    if (time >= 3000 && !state.Started) {
        state.Started = true
    }

    if (remaining >= 500000 || remaining <= 0) {
        nm.NewGame(maps[Math.floor(Math.random() * maps.length)])
        return
    }

    if (remaining > 10000 && getAlivePlayers().length <= 1) {
        nm.SetGameTime(10)
    }
}

function getAlivePlayers() {
    var alivePlayers = []

    nm.Room.GetPlayers().forEach(function (player, i) {
        if (!player.IsDead) {
            alivePlayers.push(player)
        }
    });

    return alivePlayers
}
close fullscreen
Login or Register to edit or fork this paste. It's free.