Musical Chair

De DigiWiki.

Musical Chairs Controller for rot prim.

// Musical Chairs Controller (for rot prim)
list namesPlaying=[];
list namesSitting=[];
list pillowsActive=[2,3,4,5,6,7];
list pillowsSitting=[];
integer roundNumber=1;
 
setText(string text){
    llSetText(text,<1,1,1>,1);
}
 
integer isInList(list src, list test){
    integer r;
    if (src==[]) r = FALSE;
    else{
        r = llListFindList(src,test);
        if (r==-1) r = FALSE;
        else r = TRUE;
    }
    return r;
}
 
default{
    state_entry(){
        llMessageLinked(-3,0,"gameReset",NULL_KEY);
        setText("Touch to start musical chairs");
        llStopSound();
    }
 
    touch_start(integer total_number){
        llSay(0,"New game starting.  Anyone want to play?");
        state gameWalk;
    }
}
 
state gameWalk{
    state_entry(){
        setText("Walk until the music stops.");
        llMessageLinked(-3,0,"gameWalk",NULL_KEY);
 
        llLoopSound("liszt",1);
        float delay=llFrand(6)+3;
        llSleep(delay);
        llStopSound();
 
        state gameRun;
    }
}
 
state gameRun{
    state_entry(){
        namesSitting=[];
        pillowsSitting=[];
        setText("Music Stopped.  Stand on a pillow!");
        llMessageLinked(-3,0,"gameRun",NULL_KEY);
        llSetTimerEvent(10);
    }
 
    link_message(integer sender_num, integer num, string message, key id){
 
        if (roundNumber==1 && !isInList(namesPlaying,[message])){
            namesPlaying+=[message];
        }
 
        if (!isInList(namesPlaying,[message])){
            llInstantMessage(id,"You're not playing this round.  You'll have to wait until the next game starts.");
            llMessageLinked(sender_num,0,"invalidSit",NULL_KEY);
        }
 
        if (isInList(namesSitting,[message])){
            llMessageLinked(sender_num,0,"invalidSit",NULL_KEY);
            llInstantMessage(id,"You've already got a seat.  Stop trying to take two.");
        }
 
        if (isInList(namesPlaying,[message]) && !isInList(namesSitting,[message])){
            namesSitting+=[message];
            pillowsSitting+=[sender_num];
        }
    }
 
    timer(){
        llSetTimerEvent(0);
        if (pillowsSitting==[])
            llResetScript();
 
        if (llGetListLength(pillowsSitting)==1){
            string strMessage = llList2String(namesSitting,0)+" is the winner!";
            if (roundNumber==1)
                strMessage = strMessage + " But musical chairs is more fun with more than one player.";
            llSay(0,strMessage);
            llResetScript();
        }
        else{
            integer listLength=llGetListLength(namesSitting);
            string strMessage="";
            integer x=listLength;
            while (x>2){
                strMessage = strMessage + llList2String(namesSitting,x-3) + ", ";
                x-=1;
            }
            strMessage = strMessage + llList2String(namesSitting,listLength-2) + " and " + llList2String(namesSitting,listLength-1) + " continue on to the next round!";
            llSay(0,strMessage);
        }
 
        roundNumber+=1;
        setText("Round Finished");
        llSleep(1);
 
        integer x=2;
        while (x<8){
            if (!isInList(pillowsSitting,[x])){
                llMessageLinked(x,0,"seatDisable",NULL_KEY);
            }
            x+=1;
        }
 
        llMessageLinked(llList2Integer(pillowsSitting,0),0,"seatDisable",NULL_KEY);
        namesPlaying = namesSitting;
        state gameWalk;
    }
}

Pillow for chairs.

// Pillow (for chairs)
list colors=[<.5,.5,0>,<.5,0,.5>,<0,.5,.5>,<0,0,.5>,<0,.5,0>,<.5,0,0>,<.2,.2,.2>,<.8,.8,.8>];
integer colorNum=0;
 
integer detected;
 
change_color(){
    colorNum+=1;
    if (colorNum>llGetListLength(colors)){
        colorNum=1;
    }
    vector color=llList2Vector(colors,colorNum-1);    
    llSetColor(color, ALL_SIDES);
}
 
default{
    state_entry(){
        llSetText("",<1,1,1>,1);
        llSetAlpha(1,-1);
        llSitTarget(<-1, 0, 0>, ZERO_ROTATION);
    }
 
    link_message(integer sender_num, integer num, string message, key id){
        if(message=="gameReset") llResetScript();
        if(message=="gameWalk") state gameWalk;
        if(message=="gameRun") state gameRun;
        if(message=="seatDisable") state seatDisable;
    }
    changed(integer change){
        if(change & CHANGED_LINK){
            key user = llAvatarOnSitTarget();
            if(user){
                llUnSit(user);
                llInstantMessage(user,"Just stand on the pillows.  You don't have to sit.");
            }
        }
    }
 
    touch_start(integer num){
        change_color();
    }
}        
 
 
state gameWalk{
    state_entry(){
        llSetText("",<1,1,1>,1);        
    }
    link_message(integer sender_num, integer num, string message, key id){
        if(message=="gameReset") llResetScript();
        if(message=="gameRun") state gameRun;
        if(message=="seatDisable") state seatDisable;
    }
    changed(integer change){
        if(change & CHANGED_LINK){
            key user = llAvatarOnSitTarget();
            if(user){
                llUnSit(user);
                llInstantMessage(user,"Just stand on the pillows.  You don't have to sit.");
            }
        }
    }
}
 
state gameRun{
    state_entry(){
        detected=0;
        llSetText("",<1,1,1>,1);
    }    
 
    collision_start(integer num){
        if (detected==0){
            llSetText(llDetectedName(0),<1,1,1>,1);
            llMessageLinked(1, 0, llDetectedName(0), llDetectedKey(0));
            detected=1;
        }
    }
 
    link_message(integer sender_num, integer num, string message, key id){
        if(message=="gameReset") llResetScript();
        if(message=="gameWalk") state gameWalk;
        if(message=="seatDisable") state seatDisable;
 
        if(message=="invalidSit"){
            llSetText("",<1,1,1>,1);
            llSleep(1);
            detected=0;
        }
    }
    changed(integer change){
        if(change & CHANGED_LINK){
            key user = llAvatarOnSitTarget();
            if(user){
                llUnSit(user);
                llInstantMessage(user,"Just stand on the pillows.  You don't have to sit.");
            }
        }
    }
}
 
state seatDisable{
    state_entry(){
        llSetText("",<1,1,1>,1);
        llSetAlpha(0,-1);
    }
 
    link_message(integer sender_num, integer num, string message, key id){
        if(message=="gameReset") llResetScript();
    }
    changed(integer change){
        if(change & CHANGED_LINK){
            key user = llAvatarOnSitTarget();
            if(user){
                llUnSit(user);
                llInstantMessage(user,"Just stand on the pillows.  You don't have to sit.");
            }
        }
    }
}
Outils personnels
  • Cette page a été consultée 1 156 fois.
donate
Google Ads