Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simon 1.1 Game Script

BelGarath Stern
CEO Bel-G Corp.
Join date: 19 Dec 2004
Posts: 9
08-05-2005 06:30
I put some prims together and trying to learn how lists work i came up with this. So i thought ide share what i made.
This is not a tutorial sombody else can do that if they wish. If you know the game simon then you will know where the scripts go. i dident comment much of the code i needed the room for code ;-].

As i was learning i wrote the scripts the way i knew how at the time, i'm sure there are better ways to do things but hey it works.

For those that can't be bothered building it, you can pick up a copy of mine for L$250
at:

TP To Simon Vendor
Simon Picture

Main Control Script.
Goes in main prim.

CODE


//BelGarath Stern Was Here.
string name = "No Player";
integer waiting;
integer round = 0;
integer this_round = 0;
integer counter;
integer ran_num;
list ran_numstring;

integer last_clicked = 0;
integer top_round = 0;
string top_player = "";
integer waitingforcommand = FALSE;
integer owner_listen;
float randBetween(float min, float max)
{
return llFrand(max - min) + min;
}

play_round()
{

round +=1;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);



ran_num = (integer)randBetween(1,5);
ran_numstring += [(string)ran_num];
integer iLen = llGetListLength(ran_numstring);
//llWhisper(0, llList2String(ran_numstring, 0) + llList2String(ran_numstring, 1));


integer i = 0;
for(i = 0; i < iLen; ++i) {
llSleep(0.5);

llMessageLinked(LINK_ALL_CHILDREN, 0, "light_up_" + llList2String(ran_numstring,i), NULL_KEY);
//llWhisper(0, llList2String(ran_numstring, i));
}
waiting = TRUE;
this_round = round;
this_round -=1;
counter = 0;
//llWhisper(0, (string)counter + " this round" + (string)this_round);
llMessageLinked(LINK_ALL_CHILDREN, 0, "allow_click", NULL_KEY);
llSetTimerEvent(10.0);
return;
}



check_clicked()
{

//counter +=1;
if (last_clicked == (integer)llList2String(ran_numstring, counter)) {
llSetTimerEvent(0.0);
llSetTimerEvent(10.0);
last_clicked = 0;
//llWhisper(0, (string)counter + " this round" + (string)this_round);
//counter +=1;
//return;
if (counter == this_round) {
//llWhisper(0, (string)counter + " this round" + (string)this_round);
waiting = FALSE;
llMessageLinked(LINK_ALL_CHILDREN, 0, "no_click", NULL_KEY);
llSetTimerEvent(0.0);
llSleep(2);
play_round();
//counter +=1;
//return;
}
else {
counter += 1;
return;
}

}
else {
llSetTimerEvent(0.0);
end_game();
return;
}
}


end_game()
{
integer round_tmp = round;
round_tmp -=1;
if (top_round < round_tmp) {
top_round = round_tmp;
top_player = name;
llWhisper(0, "Well done. " + name + ". New High Score");
}
ran_numstring = [];
name = "No Player";
round = 0;
waiting = FALSE;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);
llMessageLinked(LINK_ALL_CHILDREN, 0, "end", NULL_KEY);
llTriggerSound("e3cb771c-8f93-1df4-c3a9-338c08713b82",0.9);
llSetTimerEvent(0.0);


}



default
{
state_entry()
{
//ownername = llKey2Name(llGetOwner());
//owner_listen = llListen(0,"",llGetOwner(),"");
llWhisper(0, "Starting Simon. Scripted for you enjoyment by BelGarath Stern.");
//top_round = 0;
//top_player = "";
waiting = FALSE;
ran_numstring = [];
round = 0;
ran_num;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);
llPreloadSound("e3cb771c-8f93-1df4-c3a9-338c08713b82"); // lose
}
touch_start(integer total_number)
{
if (llGetOwner() == llDetectedKey(0))
{
waitingforcommand = TRUE;
llWhisper(0, "Waiting For Command...");
state wfc;
}

}
timer()
{
llSetTimerEvent(0.0);
end_game();
//llSetTimerEvent(0.0);



}
link_message(integer sender_num, integer num, string str, key id)
{
if (str=="clicked_1" && waiting == TRUE) {
last_clicked = 1;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_2" && waiting == TRUE) {
last_clicked = 2;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_3" && waiting == TRUE) {
last_clicked = 3;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="clicked_4" && waiting == TRUE) {
last_clicked = 4;
check_clicked();
//llSetTimerEvent(0.0);
//llSetTimerEvent(10.0);
return;
}
if (str=="start") {
llSetObjectDesc("Creator: BelGarath Stern.");
string str2 = (string)id;
name = str2;
llSetText("Top Player: " + top_player + " \n Highest Round: " + (string)top_round + " \n Current Player: \n" + name + "\n Round: \n" + (string)round + " \n \n \n \n \n \n \n \n \n \n \n \n \n",<0,1,0>,1.0);

play_round();
}
}
// on_rez(integer sparam)
// {
// llResetScript();
// }
}


state wfc
{
state_entry()
{
owner_listen = llListen(0,"",llGetOwner(),"");
llSetTimerEvent(20);
}
listen(integer channel, string name, key id, string message)
{
//llWhisper(0, "channel:" + (string)channel + " name:" + name + " id:" + (string)id + " message:" + message);
if (waitingforcommand == TRUE) {
list said = llParseString2List(message, [" "], []);
if (llToLower(llList2String(said, 0)) == "/simon") {
if (llToLower(llList2String(said, 1)) == "reset") {
//llResetScript();
llSetTimerEvent(0.0);
waitingforcommand == FALSE;
state default;
top_round = 0;
top_player = "";
}
}
}
}


timer()
{
llSetTimerEvent(0.0);
waitingforcommand == FALSE;
state default;
}
}



Start Button.

CODE


//BelGarath Stern Was Here.
integer in_game;
string name;
default
{
state_entry()
{
in_game = FALSE;
llSetColor(<1,0,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}

touch_start(integer total_number)
{

if (in_game == FALSE) {
name = llKey2Name(llDetectedKey(0));
llMessageLinked(LINK_ALL_OTHERS, 0, "start", name);
//llMessageLinked(1, 0, "start", NULL_KEY);
llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = TRUE;
}


}
link_message(integer sender_num, integer num, string str, key id)
{

if (str == "end") {
in_game = FALSE;
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
name ="";

}
}
on_rez(integer sparam)
{
llResetScript();
}
}



Button 1 {Green}.

CODE


//BelGarath Stern Was Here.
integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0,0.74,0>,ALL_SIDES);
llPreloadSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5"); // yellow
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 1");
llMessageLinked(1, 0, "clicked_1", NULL_KEY);
llSetColor(<0,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5",0.9);
llSleep(0.3);
llSetColor(<0,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;

}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_1") {
llSetColor(<0,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("03a0e991-ac4c-771d-26c1-8796b0b0b9e5",0.9);
llSleep(0.3);
llSetColor(<0,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
in_game = FALSE;
llSetColor(<0,0.74,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 2 {Yellow}

CODE


//BelGarath Stern Was Here.
integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0.74,0.74,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e"); // blue

}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 2");
llMessageLinked(1, 0, "clicked_2", NULL_KEY);
llSetColor(<1,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e",0.9);
llSleep(0.3);
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_2") {
llSetColor(<1,1,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("1d51f673-15b4-fa9c-aecd-1a162fe3763e",0.9);
llSleep(0.3);
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0.74,0.74,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 3 {Blue}

CODE


integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0,0.71,0.71>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("7c043aa3-64df-a0f1-c825-fad216153272"); // green
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 3");
llMessageLinked(1, 0, "clicked_3", NULL_KEY);
llSetColor(<0,1,1>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("7c043aa3-64df-a0f1-c825-fad216153272",0.9);
llSleep(0.3);
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_3") {
llSetColor(<0,1,1>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("7c043aa3-64df-a0f1-c825-fad216153272",0.9);
llSleep(0.3);
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0,0.71,0.71>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}


Button 4 {Red}

CODE


//BelGarath Stern Was Here.

integer in_game = FALSE;
integer can_click = FALSE;
string name = "";

default
{
state_entry()
{
in_game = FALSE;
can_click = FALSE;
llSetColor(<0.74,0,0>,ALL_SIDES);
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
llPreloadSound("6295075d-674e-13c1-3128-237009b38e41"); // red
}

touch_start(integer total_number)
{

if (in_game && can_click) {
if (llKey2Name(llDetectedKey(0)) == name) {
//llWhisper(0, "player clicked 4");
llMessageLinked(1, 0, "clicked_4", NULL_KEY);
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("6295075d-674e-13c1-3128-237009b38e41",0.9);
llSleep(0.3);
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
//llMessageLinked(1, 0, "start", NULL_KEY);
//llSetColor(<0.9,0.1,0.5>,ALL_SIDES);
//in_game = TRUE;
}
}


}
link_message(integer sender_num, integer num, string str, key id)
{
if (str == "light_up_4") {
llSetColor(<1,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
llTriggerSound("6295075d-674e-13c1-3128-237009b38e41",0.9);
llSleep(0.3);
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);

}

if(str=="start") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_LIGHT]);
string str2 = (string)id;
name = str2;
in_game = TRUE;
}

if (str == "end") {
llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
in_game = FALSE;
llSetColor(<0.74,0,0>,ALL_SIDES);
//llSetPrimitiveParams([PRIM_MATERIAL,PRIM_MATERIAL_GLASS]);
name ="";

}
if(str=="allow_click") {
can_click = TRUE;
}

if (str == "no_click") {
can_click = FALSE;

}
}
}

_____________________
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Discussion Thread
08-06-2005 12:07
/54/8e/56683/1.html
_____________________
i've got nothing. ;)