// Needs "single avatar multisit" with /i on notecard (and multipose setup)

list main_menu = ["Time", "Cancel"];
list sit_menu = ["Sit Options"]; // Will be on menu if sitting
list MENU;

// A listen is needed but only for this script's dialog: it's not for sit options
integer listen_handle;
integer channel; 

integer AgentSitting(key kk) {
    integer a = llGetNumberOfPrims();
    while(1 < a){
        key lk=llGetLinkKey(a);
        if(llGetAgentSize(lk)){
            if (lk==kk) return TRUE;
            --a;
        }
        else return FALSE;
    }
    return FALSE;
}

dlg(key kk) {
    stopt();
    channel = -((integer)llFrand(20000000)+1000);
    listen_handle = llListen(channel, "", kk, "");
    llSetTimerEvent(120);
    llDialog(kk, "\n\nSelect an Option", MENU, channel);
}

stopt(){
   llListenRemove(listen_handle);
   llSetTimerEvent(0);
}

default 
{
    listen(integer channel, string name, key id, string message) {             
        if (llListFindList(MENU, [message]) != -1) {
            if (message == "Sit Options") llDialog(id, "\nCLICK:\n\nm for Menu\n\na to Adjust Position", ["m","a"], 1);
            else if (message == "Time") llSay(0,llGetTimestamp()); 
            stopt();
        }
    }   
    
    timer(){ stopt(); }
    
    touch_start(integer s) {
        key k=llDetectedKey(0);
        MENU=main_menu;
        if (AgentSitting(k)) MENU=sit_menu+MENU; // add sitting options
        dlg(k);
    }
}