// Do stuff when someone/nobody is sitting (on any prim)

float SIT_ALPHA = 0.0 ; // prim invisible on sit: 0.0
float UNSIT_ALPHA = 1.0 ; // prim visible when nobody is sitting: 1.0

string TEXT="TEST TEXT";
string SITTEXT="";
vector col=< 1.0 , 1.0 , 1.0 >; // text color
float transp= 1.0 ; // 1.0 = text full visibility

integer LAST=0;
integer GetNumberOfAgents(){
    integer a = llGetNumberOfPrims();
    integer b = a;
    if(1 < a)
        while(llGetAgentSize(llGetLinkKey(a)))
            --a;
    return b - a;
}

default {
    state_entry() {
            llSetAlpha(UNSIT_ALPHA, ALL_SIDES);
            llSetText(TEXT, col, transp);
    }
    changed(integer change) {
        if(change & CHANGED_LINK) {
            integer na=GetNumberOfAgents();
            if(na == 1 && !LAST ){ // someone is sitting
                llSetAlpha(SIT_ALPHA, ALL_SIDES);
                llSetText(SITTEXT, col, transp);
            }
            else if (!na) { // nobody is sitting
                llSetAlpha(UNSIT_ALPHA, ALL_SIDES);
                llSetText(TEXT, col, transp);
            }
            LAST=na;
        }
    }
    on_rez(integer r) {
        llResetScript();
    }
}