Added turn controler script
This commit is contained in:
parent
20c14e793e
commit
5089aab2c6
2 changed files with 71 additions and 0 deletions
8
contributed/turn controler for multiplayer/README.md
Normal file
8
contributed/turn controler for multiplayer/README.md
Normal file
|
@ -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.
|
63
contributed/turn controler for multiplayer/script.txt
Normal file
63
contributed/turn controler for multiplayer/script.txt
Normal file
|
@ -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)
|
Reference in a new issue