This repository has been archived on 2025-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
AIDScripting/contributed/turn controler for multiplayer/script.txt
2020-10-12 09:44:27 +02:00

63 lines
1.1 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)