User:Decimus Schomer/Projects/Chess/Script
< User:Decimus Schomer | Projects | Chess
This is the page about how to use the chessboard - a page about it is available here
Decimus' user page | Decimus' talk page | Decimus' scripts | Decimus' script libraries | Decimus' projects
Main projects page | Chess | Connect-4
Main chess page | Script | Move-check scripts
Script
// SL Chess: Board script // Copyright (C) 2007 Decimus Schomer // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. // Changelog // * 14th July 2007: Version 1.0 string VERSION = "SL Chess version 1.0"; integer st = 0; integer turn = 0; integer IN_CHANNEL = 12; integer INTERCOM_CHANNEL = -12; key p1; string pn1; key p2; string pn2; rez_piece(string name, rotation r, integer xpos, integer ypos) { llRezObject(name, llGetPos() + <(xpos-3.5)*1.25, (ypos-3.5)*1.25, 1>, ZERO_VECTOR, r, xpos + (8 * ypos)); } rez_piece_quad(string n1, string n2, rotation r1, rotation r2, integer x) { rez_piece(n1, r1, x, 7); rez_piece(n1, r1, 7-x, 7); rez_piece(n2, r2, x, 0); rez_piece(n2, r2, 7-x, 0); } rez_pieces() { integer n; for (n = 0; n < 8; n++) { rez_piece("Black Pawn", ZERO_ROTATION, n, 6); rez_piece("White Pawn", ZERO_ROTATION, n, 1); } rez_piece_quad("Black Rook", "White Rook", ZERO_ROTATION, ZERO_ROTATION, 0); rez_piece_quad("Black Knight", "White Knight", llEuler2Rot(<90, 0, 270> * DEG_TO_RAD), llEuler2Rot(<270, 0, 90> * DEG_TO_RAD), 1); rez_piece_quad("Black Bishop", "White Bishop", ZERO_ROTATION, ZERO_ROTATION, 2); rez_piece("Black Queen", llEuler2Rot(<180, 0, 0> * DEG_TO_RAD), 4, 7); rez_piece("White Queen", llEuler2Rot(<180, 0, 0> * DEG_TO_RAD), 3, 0); rez_piece("Black King", ZERO_ROTATION, 3, 7); rez_piece("White King", ZERO_ROTATION, 4, 0); } default { state_entry() { llListen(IN_CHANNEL, "", "", ""); llSetText("Chess: Idle", <0,0,1>, 10); } touch_start(integer n) { integer i; for (i = 0; i < n; i++) { llGiveInventory(llDetectedKey(i), "Chess instructions"); } } listen(integer channel, string name, key id, string msg) { if (msg == "play") { if (st == 0) { p1 = id; pn1 = name; st = 1; llSetText("Chess: " + pn1 + " vs. ?", <0,0,1>, 10); llSay(0, name + ", you have been added to the game as whites."); } else if (st == 1) { p2 = id; pn2 = name; turn = 0; st = 2; llSetText("Chess: " + pn1 + " vs. " + pn2 + "; " + pn1 + "'s (white's) turn", <0,0,1>, 10); llInstantMessage(p1, name + " has decided to play against you. It is your turn."); llSay(0, name + ", a game between you and " + pn1 + " has been started."); rez_pieces(); } } else if (msg == "quit") { if (id == p1) { if (st == 2) { llSay(0, "The game between you and " + pn2 + " has been ended."); llInstantMessage(p2, pn1 + " has resigned from the game."); } else llSay(0, "You have been removed from this game."); } else if (id == p2) { llSay(0, "The game between you and " + pn1 + " has been ended."); llInstantMessage(p1, pn2 + " has resigned from the game."); } llSay(INTERCOM_CHANNEL, "quit"); st = 0; llSetText("Chess: Idle", <0,0,1>, 10); } else if (msg == "version") llSay(0, VERSION); else if (msg == "license") llGiveInventory(id, "Chess License"); } }
Instructions notecard
This text (or an equivalent) must be copied into a notecard in the board object:
Instructions for SL Chess =============== These instructions assume you already know how to play chess; they simply tell you how to use this version, specially made for SL How to interpret the floating text ------------------------------------- If you look at the text above the controller object, it will say 'Chess:' followed by either (things in angle brackets ('<' and '>') mean something of that type, *not* the literal text): * 'Idle' if nobody is currently playing * '<name> vs. ?' (a literal question mark) if a person has chosen to play but no opponents are playing them * '<name> vs. <name>; <name>'s (<white/black>'s) turn' when a game is in progress Commands ------------ All commands must be said on channel 12. This means that you have to prefix them with '/12'. 'play' - Unless a game is currently in progress, this will add you to a new game. 'quit' - If you are playing a game, this will make you resign. Currently, there is no feature to detect when someone has won, so when someone does win one of the players will have to say this. 'version' - Say this to find out the version of the chess script used here 'license' - Get a copy of the notecard containing the GNU GPL, which SL Chess is licensed under How to play ------------- Once both players have joined the game (Commands->'play' above), the pieces for each player will appear. As of now, moves are not supported, so the owner of the chessboard will have to set move permissions on each piece, then you have to move them manually.
How to use
To use this, you will need to make an object containing:
- The script above
- A notecard called 'Chess instructions', containing the text under the 'Instructions notecard' heading above.
- A notecard called 'Connect-4 license', containing the GPL.
- Pieces - two for each of the following names, one prefixed with 'White ' and the other with 'Black ': 'Rook', 'Knight', 'Bishop', 'King', 'Queen' and 'Pawn'.
Or you can just go here and copy the chessboard from there :p