|
Kevin Paisley
Registered User
Join date: 26 Oct 2006
Posts: 32
|
03-26-2007 12:16
Hi. I was tweaking a sample public domain menu script for use on my tip jar. I have it pretty much the way I want it but was unable after many attempts trying different functions to get it to only be accessable by the owner of it. There is probley a simple way to do this that I am not understanding. I was able to get the main menu to come up but not able to access the items as owner. I reverted back to the original creation of mine here that is accessable to everyone. How would i make this to where only the owner can access the menu on touch? Thank You, Kevin Paisley integer channel; // channel that we are listening on integer listener; // internal number representing the listener key agentKey; // persons key who is using menu string agentName; // person who is using menu float timeout = 60; // number of seconds before dialogs time out
string menu = ""; // current menu being displayed to user
// menu buttons ... list mainButtons = ["Blue Light", "White Light", "Red Light", "Green Light", "Light Off", "Reset Total", "Particles On", "Particles Off"];
init() { stopListening(); } stopListening() { // stop listening if(listener != 0) { llListenRemove(listener); listener = 0; } // set to main menu menu = ""; // forget current user agentKey = NULL_KEY; agentName = ""; channel = 0; // stop timing out llSetTimerEvent(0); } mainMenuHandler(string message) { menu = message; if(message == "Blue Light") llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <4.0, 0.0, 1.0>, 1.0, 10.0, 0.75]); else if(message == "White Light") llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 1.0>, 1.0, 10.0, 0.75]); else if(message == "Red Light") llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <8.0, 0.0, 0.0>, 1.0, 10.0, 0.75]); else if(message == "Green Light") llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <2.0, 1.0, 0.0>, 1.0, 10.0, 0.75]); else if(message == "Light Off") llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 1.0, 10.0, 0.75]); else if(message == "Particles On") llResetOtherScript("Particle Script"); else if(message == "Particles Off") llParticleSystem([]); else if(message == "Reset Total") llResetOtherScript("Main"); else { llInstantMessage(agentKey, "Unknown menu item - " + message); stopListening(); return; } // extend timeout llSetTimerEvent(timeout); } unknownMenuHandler(string message) { llInstantMessage(agentKey, "Unknown menu item - " + message); stopListening(); } default { state_entry() { init(); } on_rez(integer start_param) { init(); }
touch_start(integer total_number) { // someone else using this? if(listener != 0 && llDetectedKey(0) != agentKey) { llInstantMessage(llDetectedKey(0), agentName + " is using that."); return; }
// remember who is using this agentKey = llDetectedKey(0); agentName = llDetectedName(0);
// if we are not listening already if(listener == 0) { // set a random channel betweed -4000 and -2000 channel = (integer)(llFrand(2000) - 4000); // start listening only to the agent on our hidden channel listener = llListen(channel, agentName, agentKey, ""); } // set menu to default menu = ""; // show them buttons llDialog(agentKey, "Main Menu", mainButtons, channel); // set timeout llSetTimerEvent(timeout); } listen(integer channel, string name, key id, string message) { // handle results based on menu end-user was viewing if(menu == "") mainMenuHandler(message); else unknownMenuHandler(message); } timer() { // let agent know that we are not listening llInstantMessage(agentKey, "Your menu has timed out!"); stopListening(); } }
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
03-26-2007 12:21
In the touch event, just check the detected id against the owner and ignore if it doesn't match.
|
|
Kevin Paisley
Registered User
Join date: 26 Oct 2006
Posts: 32
|
03-26-2007 12:46
From: Newgate Ludd In the touch event, just check the detected id against the owner and ignore if it doesn't match. Tried doing that in the script and was able to get the main menu up but none of the buttons responded. Not really sure how i would go about doing that  Kevin Paisley
|
|
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
|
03-26-2007 13:20
From: Kevin Paisley Tried doing that in the script and was able to get the main menu up but none of the buttons responded. Not really sure how i would go about doing that  Kevin Paisley all you actually need is the following in the touch handler
touch_start(integer total_number) { // someone else using this? key id = llDetectedKey(0); if(id == llGetOwner()) { // Do stuff } }
The rest should stay pretty much as is. Your light colours are not going to work as you expect, colour vectors are normalised, i.e. between 0 and 1. Take the RGB values (0-255) and divide by 255 I've taken the liberty of rewritting it more in line with how I would do it. You didnt really need the additional global variables for the functionality you had. integer Channel; // channel that we are listening on integer listener; // internal number representing the listener float timeout = 60.; // number of seconds before dialogs time out
// menu buttons ... list mainButtons = ["Blue Light", "White Light", "Red Light", "Green Light", "Light Off", "Reset Total", "Particles On", "Particles Off"];
stopListening() { // stop listening if(listener != 0) { llListenRemove(listener); listener = 0; } // stop timing out llSetTimerEvent(0); }
mainMenuHandler(string message, key id) { stopListening(); integer index = llListFindList(mainButtons, [ message ] ); if(0 == index) llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.0, 0.0, 1.0>, 1.0, 10.0, 0.75]); else if(1 == index) llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 1.0, 1.0>, 1.0, 10.0, 0.75]); else if(2 == index) llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1.0, 0.0, 0.0>, 1.0, 10.0, 0.75]); else if(3 == index) llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <0.0, 1.0, 0.0>, 1.0, 10.0, 0.75]); else if(4 == index) llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 1.0, 10.0, 0.75]); else if(5 == index) llResetOtherScript("Main"); else if(6 == index) llResetOtherScript("Particle Script"); else if(7 == index) { // This no longer works consistently llParticleSystem([]); } else { llInstantMessage(id, "Unknown menu item - " + message); } }
default { state_entry() { stopListening(); } on_rez(integer start_param) { stopListening(); }
touch_start(integer total_number) { // someone else using this? key id = llDetectedKey(0); if(id == llGetOwner()) { // if we are not listening already if(listener == 0) { // set a random channel betweed -4000 and -2000 Channel = (integer)(llFrand(2000) - 4000); // start listening only to the agent on our hidden channel listener = llListen(Channel, "", id, ""); } // show them buttons llDialog(id, "Main Menu", mainButtons, Channel); // set timeout llSetTimerEvent(timeout); } } listen(integer channel, string name, key id, string message) { // handle results based on menu end-user was viewing mainMenuHandler(message, id); } timer() { // let agent know that we are not listening llInstantMessage(llGetOwner(), "Your menu has timed out!"); stopListening(); } }
|