From 5089aab2c646dfa0c3690f71763f51383ab5c91a Mon Sep 17 00:00:00 2001 From: FreddyE Date: Mon, 12 Oct 2020 09:44:27 +0200 Subject: [PATCH] Added turn controler script --- .../turn controler for multiplayer/README.md | 8 +++ .../turn controler for multiplayer/script.txt | 63 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 contributed/turn controler for multiplayer/README.md create mode 100644 contributed/turn controler for multiplayer/script.txt diff --git a/contributed/turn controler for multiplayer/README.md b/contributed/turn controler for multiplayer/README.md new file mode 100644 index 0000000..1063f1a --- /dev/null +++ b/contributed/turn controler for multiplayer/README.md @@ -0,0 +1,8 @@ +This script makes multiplayer games turn based. + +How to use: + +Paste the script into input modifier tab, set the game to use "third person". +The script detects player names, adds them to a turn list and determines who is next. +All input by other players will be set to "" and a message will be displayed informing +players who´s turn it is. \ No newline at end of file diff --git a/contributed/turn controler for multiplayer/script.txt b/contributed/turn controler for multiplayer/script.txt new file mode 100644 index 0000000..483f02b --- /dev/null +++ b/contributed/turn controler for multiplayer/script.txt @@ -0,0 +1,63 @@ +const modifier = (text) => { + + modifiedText = text + + if(!state.playernames){ + + console.log("setup") + + state.playernames = [] + state.lastplayer = "" + state.nextplayerindex = 0 + + + } + + + + // check if a new player name appears + + textspl = modifiedText.split(" ") + + name = textspl[1] + + + if(state.playernames.includes(name) == false){ + + state.playernames.push(name) + + + } + + //check if there are at least two players, if true start turn routine + + if(state.playernames.length > 1){ + + state.nextplayerindex = state.playernames.indexOf(state.lastplayer) + 1 + + if(!state.playernames[state.nextplayerindex]){state.nextplayerindex = 0} + + if(modifiedText.includes("> " + state.playernames[state.nextplayerindex] ) == false ) { + + + + + modifiedText = "" + state.message = "It´s " + state.playernames[state.nextplayerindex] + "'s turn" + } + + } + + + + + state.lastplayer = name + + + + // You must return an object with the text property defined. + return { text: modifiedText } +} + +// Don't modify this part +modifier(text)