Hal Canary (hwc) wrote in sl_creators,
Hal Canary
hwc
sl_creators

Basic Vote Script


  1. Create a box with the following dimensions: <0.672, 0.672, 0.5>.

  2. Drop this script into it.

  3. Make several copies.




// Basic Vote Script
// Copyright 2008 Hal Canary
//
// Version 1.2, 2008-09-07
//
// License Information:
//    This program is free software; you can redistribute it and/or
//    modify it under the terms of version 2 of the GNU General
//    Public License as published by the Free Software Foundation.
//
//    A copy of the license can be found at:
//        http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
//
//    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.

// How to use this bad boy:
//    Rez any number of boxes next to each other.  If someone 
//    is unqualified to enter the race but clicks on a box
//    anyway, or has accidentally clicked on two boxes, just
//    delete the offending box and re-rez.
//
//    When the contest is over, just delete the boxes and re-rez.
//
//    Voters can vote for more than one candidate, but that just
//    dilutes their vote.

string contestant;
integer votes;
list voters;
integer VOTEMODE;

integer click(key dkey) {
    if (!VOTEMODE) {
        contestant = llKey2Name(dkey);
        llSay(0, contestant + " has entered the contest!");
        llHTTPRequest( "http://world.secondlife.com/resident/"
            + (string)dkey,[HTTP_METHOD,"GET"],"");
        llSetText("Touch me vote for\n"+contestant,<1,1,1>,1.0);
        VOTEMODE = TRUE;
        return 0;
    }
    string voter = llKey2Name(dkey);
    integer i;
    integer end = llGetListLength(voters);
    string test;
    for (i=0; i<end; i++) {
        test = llList2String(voters, i);
        if (test == voter) {
            llInstantMessage(dkey, "/me IMs: " + voter
                + ", you can't vote for the same contestant twice!"
                + "  Don't waste my time.");
            return 0;
        }
    }
    llSay(0, "Someone has just voted for " + contestant + "!");
    llInstantMessage(dkey, "/me IMs: " + voter 
        + ", you just voted for " + contestant + ".");
    votes = votes + 1;
    llSetText("Touch me vote for\n"+contestant+"\n("
        +(string)votes+")",<1,1,1>,1.0);
    voters = voters + [voter];
    return 0;        
}

default {
    state_entry() { // reset everything
        llSetText("Touch me to enter contest",<1,1,1>,1.0);
        VOTEMODE = FALSE;
        votes = 0;
        voters = [];
        llSetTexture("45c2b1e4-669c-5d64-7e09-1661cf68410a",ALL_SIDES);
    }
    touch_start(integer total_number) {
        integer n;
        for(n=0; n<total_number; n++) {
            click(llDetectedKey(n));
        }
    }
    http_response(key req,integer stat, list met, string body) {
        // based on code contributed by Jana Kamachi
        // http://wiki.secondlife.com/wiki/User:Jana_Kamachi/Profile
        integer stringindex = llSubStringIndex(body,
            "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/");
        if (stringindex == -1) {
            return; // no profile iamge
        }
        llSetTexture((key)llGetSubString(
            body,
            stringindex+llStringLength(
            "<img alt=\"profile image\" src=\"http://secondlife.com/app/image/"),
            llSubStringIndex(body,"\" class=\"parcelimg\" />")-3)
            ,ALL_SIDES);
    }
}
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your IP address will be recorded 

  • 0 comments