options: display: "10x20" display-symbol: "█" display-bgcolor1: "abd853" display-bgcolor2: "95bf43" display-bordercolor: "568a34" display-lastsnakecolor: "4e7def" display-firstsnakecolor: "87aaff" display-applecolor: "fb574c" display-totalbg: (0,0,0,0) #(255,85,136,49) display-scoreadd: 10 display-border: true game-tick: 1 seconds command /snake []: permission: * trigger: if arg-1 is not set: send "" send " &6/snake &astart &3- &7Starts a game" send " &6/snake &astop &3- &7Ends a game" send "" if arg-1 is "Start" or "Stop": snake(player, arg-1, false) set {_p} to pitch of player set {_y} to yaw of player set {_gm} to player's gamemode set player's gamemode to spectator while {Snake::%player%::*} is set: set pitch of player to -90 set yaw of player to 0 wait 1 tick set player's gamemode to survival set yaw of player to {_y} set pitch of player to {_p} if arg-1 contains "GameControl-": snake(player, arg-1, false) on quit: snake(player, "Stop", false) on player move: if {Snake::%player%::*} is set: cancel event on player rotate: if {Snake::%player%::*} is set: cancel event on dismount: if {Snake::%player%::*} is set: cancel event function snake(player: player, type: text, force: boolean): if {_type} is "Start": snake({_player}, "Stop", true) add 1 to {GameID} spawn a bat at location of {_player}: set ai of entity to false entity.setInvulnerable(true) make entity invisible set {Snake::%{_player}%::entity} to last spawned bat make {_player} ride {Snake::%{_player}%::entity} set {_loc} to location at {_player} set pitch of {_loc} to -90 set {_loc} to location 5 block infront of {_loc} add 1 to z-coordinates of {_loc} spawn a text display at {_loc}: set {_display} to last spawned text display set display billboard of {_display} to center set display brightness of {_display} to displayBrightness(10,10) set display text shadowed of {_display} to false set interpolation start of entity to 0 set interpolation duration of entity to 10 set display text of {_display} to " " set display scale of {_display} to vector(0,0,0) set display text background color of {_display} to bukkitColor({@display-totalbg}) wait 2 ticks set display scale of {_display} to vector(1,1,1) set {Snake::%{_player}%::Display} to {_display} set {Snake::%{_player}%::Status} to true set {Snake::%{_player}%::Control} to "D" set {Snake::%{_player}%::GameID} to {GameID} set {Snake::%{_player}%::Score} to 0 set {_size::*} to {@display} split at "x" set {Snake::%{_player}%::X} to floor({_size::1} parsed as number/2) set {Snake::%{_player}%::Y} to ceil({_size::2} parsed as number/2)-3 loop 3 times: add "%{Snake::%{_player}%::X}%x%{Snake::%{_player}%::Y}+loop-value%" to {Snake::%{_player}%::SnakeCoords::*} if loop-value is 3: set {Snake::%{_player}%::X} to {Snake::%{_player}%::X} set {Snake::%{_player}%::Y} to {Snake::%{_player}%::Y}+loop-value addapple({_player}) snakebg({_player}) if {Snake::%{_player}%::Status} is set: if {_type} is "GameOver": wait 1 tick {Snake::%{_player}%::entity}.remove() {Snake::%{_player}%::Display}.remove() delete {Snake::%{_player}%::*} if {_type} is "Stop": wait 1 tick {Snake::%{_player}%::entity}.remove() {Snake::%{_player}%::Display}.remove() delete {Snake::%{_player}%::*} if {_force} is false: send " " to {_player} send "&cStopped the !" to {_player} send " " to {_player} if {_type} contains "GameControl-": set {_click::*} to {_type} split at "-" set {_size::*} to {@display} split at "x" if {_click::2} is "W": if {Snake::%{_player}%::Control} is not "S": set {Snake::%{_player}%::Control} to "W" snakebg({_player}) else: if {_click::2} is "A": if {Snake::%{_player}%::Control} is not "D": set {Snake::%{_player}%::Control} to "A" snakebg({_player}) else: if {_click::2} is "S": if {Snake::%{_player}%::Control} is not "W": set {Snake::%{_player}%::Control} to "S" snakebg({_player}) else: if {_click::2} is "D": if {Snake::%{_player}%::Control} is not "A": set {Snake::%{_player}%::Control} to "D" snakebg({_player}) else: function backcheck(player: player, option: text, option2: text) :: boolean: if {_option} is "add": add 1 to {Snake::%{_player}%::%{_option2}%} if size of {Snake::%{_player}%::SnakeCoords::*} > 1: loop {Snake::%{_player}%::SnakeCoords::*}: if loop-value is "%{Snake::%{_player}%::X}%x%{Snake::%{_player}%::Y}%": remove 1 from {Snake::%{_player}%::%{_option2}%} return false if {_option} is "remove": remove 1 from {Snake::%{_player}%::%{_option2}%} if size of {Snake::%{_player}%::SnakeCoords::*} > 1: loop {Snake::%{_player}%::SnakeCoords::*}: if loop-value is "%{Snake::%{_player}%::X}%x%{Snake::%{_player}%::Y}%": add 1 to {Snake::%{_player}%::%{_option2}%} return false return true function addapple(player: player): set {_size::*} to {@display} split at "x" loop {_size::1} parsed as number times: loop {_size::2} parsed as number times: add "%(loop-value-1) - 1%x%loop-value-2%" to {_fields::*} loop {Snake::%{_player}%::SnakeCoords::*}: remove loop-value from {_fields::*} set {_a} to random element out of {_fields::*} set {Snake::%{_player}%::AppleCords::*} to "%{_a}%" on player input packet: if {Snake::%player%::*} is set: if event-string = "A" or "W" or "S" or "D": if difference between now and {DetectNow::%player%} > 0.1 second: snake(player, "GameControl-%event-string%", false) if event-string = "SPACE": snake(player, "Stop", false) set {DetectNow::%player%} to now function snakebg(player: player): set {_size::*} to {@display} split at "x" if {Snake::%{_player}%::Control} is "W": if backcheck({_player}, "remove", "X") is false: set {_stop} to true if {Snake::%{_player}%::Control} is "A": if backcheck({_player}, "remove", "Y") is false: set {_stop} to true if {Snake::%{_player}%::Control} is "S": if backcheck({_player}, "add", "X") is false: set {_stop} to true if {Snake::%{_player}%::Control} is "D": if backcheck({_player}, "add", "Y") is false: set {_stop} to true if {_stop} is true: send "" to {_player} send " &cYou lost! (You've made a loop!)" to {_player} send "" to {_player} snake({_player}, "GameOver", false) stop set {_lastelement} to first element out of {Snake::%{_player}%::SnakeCoords::*} remove first element out of {Snake::%{_player}%::SnakeCoords::*} from {Snake::%{_player}%::SnakeCoords::*} set {Snake::%{_player}%::SnakeCoords::*} to {Snake::%{_player}%::SnakeCoords::*} and "%{Snake::%{_player}%::X}%x%{Snake::%{_player}%::Y}%" set {_bgsymbol} to "<##%{@display-bordercolor}%>%{@display-symbol}%" loop {Snake::%{_player}%::SnakeCoords::*}: set {_checkCord::*} to loop-value split at "x" set {_X-Check} to {_checkCord::1} parsed as number set {_Y-Check} to {_checkCord::2} parsed as number if {_Y-Check} < 1: set {_stop} to true if {_Y-Check} > {_size::2} parsed as number: set {_stop} to true if {_X-Check} < 0: set {_stop} to true if {_X-Check} > {_size::1} parsed as number-1: set {_stop} to true if {_stop} is true: send "" to {_player} send " &cYou lost! (You touched a wall!)" to {_player} send "" to {_player} snake({_player}, "GameOver", false) stop set {_text} to "&cScore: %{Snake::%{_player}%::Score}%" + nl if {@display-border} is true: loop {_size::2} parsed as number +2 times: set {_top} to formatted "%{_top} ? ""%<##%{@display-bordercolor}%>%{@display-symbol}%" set {_text} to {_text} + {_top} loop size of {Snake::%{_player}%::SnakeCoords::*} times: set {_b} to "%{_b} ? ""%%{@display-symbol}% " set {_grad} to formatted gradient("%{_b}%", ("%{@display-lastsnakecolor}%", "%{@display-firstsnakecolor}%")) set {_grad::*} to {_grad} split at " " loop {_size::1} parsed as number times: delete {_x} if mod({_size::2} parsed as number, 2) is 0: add 1 to {_bgcolor} loop {_size::2} parsed as number times: add 1 to {_bgcolor} and {_field} set {_color} to {@display-bgcolor2} if mod({_bgcolor}, 2) is 0: set {_color} to {@display-bgcolor1} set {_centerX} to floor({_size::1} parsed as number/2) set {_centerY} to ceil({_size::2} parsed as number/2) loop {Snake::%{_player}%::AppleCords::*}: set {_cord-info::*} to loop-value-3 split at "x" set {_cord-info::1} to {_cord-info::1} parsed as number set {_cord-info::2} to {_cord-info::2} parsed as number if {_field} is floor({_cord-info::1}*{_size::2} parsed as number + {_cord-info::2}): set {_color} to {@display-applecolor} loop {Snake::%{_player}%::SnakeCoords::*}: set {_CheckAX} to loop-value-3 set {_cord-info::*} to loop-value-3 split at "x" set {_cord-info::1} to {_cord-info::1} parsed as number set {_cord-info::2} to {_cord-info::2} parsed as number if {_field} is floor({_cord-info::1}*{_size::2} parsed as number + {_cord-info::2}): set {_color} to formatted {_grad::%loop-index%} replace all {@display-symbol} with "" in {_color} loop {Snake::%{_player}%::AppleCords::*}: if loop-value-4 is {_CheckAX}: remove loop-value-4 from {Snake::%{_player}%::AppleCords::*} set {Snake::%{_player}%::SnakeCoords::*} to {_lastelement} and {Snake::%{_player}%::SnakeCoords::*} addapple({_player}) add {@display-scoreadd} to {Snake::%{_player}%::Score} delete {_control} delete {_endsymbol} if {@display-border} is true: if mod({_field}, {_size::2} parsed as number) is 0: set {_endsymbol} to {_bgsymbol} if length of {_color} is 6: set {_color} to "<##%{_color}%>" set {_x} to formatted "%{_x} ? ""%%{_color}%%{@display-symbol}%%{_endsymbol} ? ""%%{_control} ? ""%" if {@display-border} is false: delete {_bgsymbol} if loop-counter-1 is 1: set {_nl} to "" else: set {_nl} to nl set {_text} to formatted {_text} + {_nl} + formatted "%{_bgsymbol} ? ""%%{_x}%" if {@display-border} is true: set {_text} to formatted {_text} + nl + formatted "<##%{@display-bordercolor}%>%{_top}%" set display text of {Snake::%{_player}%::Display} to {_text} set {_gameID} to {Snake::%{_player}%::GameID} wait {@game-tick} if {_gameID} is {Snake::%{_player}%::GameID}: if {Snake::%{_player}%::Status} is set: if {_X-Check} is {Snake::%{_player}%::X}: if {_Y-Check} is {Snake::%{_player}%::Y}: snakebg({_player}) # _____ _ _ _ _ _ _ # / ____| | | | | | | | (_) | # | | ___ | | ___ _ __ | | | | |_ _| |___ TM | A colorful script brought to you by Sourbun et Mr. Darth :D # | | / _ \| |/ _ \| '__| | | | | __| | / __| | Version 2.3 # | |___| (_) | | (_) | | | |__| | |_| | \__ \ # \_____\___/|_|\___/|_| \____/ \__|_|_|___/ function gradient(input: string, color: strings) :: string: loop {_color::*}: set {_rgb::%loop-index%::*} to HexToRGB(loop-value) set {_n} to size of {_color::*} -1 set {_delta} to 180 / (length of uncolored {_input}/{_n} - 1) loop {_n} times: loop ceil(length of uncolored {_input}/{_n}) times: set {_y} to ((loop-value-1) -1)*(ceil((length of uncolored {_input})/{_n})) + (loop-value-2) while character at {_y}+{_x} in {_input} is "§": if "abcdefklmnor0123456789" contains character at {_y}+{_x}+1 in {_input}: set {_format} to (join {_format} and "&%character at {_y}+{_x}+1 in {_input}%") if character at {_y}+{_x}+1 in {_input} is not "r", else ("") add 2 to {_x} set {_character} to character at {_y} in uncolored {_input} set {_startColorProportion} to (0.5 * (sin(({_delta}*((loop-value-2)-1))+90) + 1)) set {_endColorProportion} to (0.5 * (sin(({_delta}*((loop-value-2)-1))+270) + 1)) loop 3 times: set {_n::%loop-value-3%} to ({_rgb::%loop-value-1%::%loop-value-3%} * {_startColorProportion}) + ({_rgb::%((loop-value-1) + 1)%::%loop-value-3%} * {_endColorProportion}) set {_output} to join {_output}, RGBToHex({_n::*}), {_format} and {_character} return colored {_output} function RGBToHex(number: numbers) :: string: loop {_number::*}: set {_r} to join {_r}, (character at (mod((floor(min(max(loop-value, 0), 255) / 16)), 16) + 1) in "0123456789ABCDEF") and (character at ((mod(min(max(loop-value, 0), 255), 16)) + 1) in "0123456789ABCDEF") return colored "<##%{_r}%>" #HexToRGB(hex: string) # @description Function to convert a hex value to the 3 Color values # @param: 6 letter hex string # @return 3 numbers function HexToRGB(hex: string) :: numbers: replace all "##" with "" in {_hex} set {_s::*} to split "0123456789abcdefklmnor" at "" loop 3 times: set {_n} to subtext of {_hex} from characters (loop-value -1)*2+1 to loop-value*2 in lower case add (index of first element out of (split {_n} at "") in "0123456789abcdefklmnor" -1)* 16 to {_rgb::%loop-value-1%} add index of 2nd element out of (split {_n} at "") in "0123456789abcdefklmnor"-1 to {_rgb::%loop-value-1%} return {_rgb::*}