Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- list notecardsList;
- 2
- 3
- integer listener;
- 4
- integer mainMenuChannel;
- 5
- integer accessChannel;
- 6
- 7
- integer notecardLine;
- 8
- 9
- string notecardName = "!access";
- 10
- 11
- key query;
- 12
- 13
- string access = "Owner";
- 14
- 15
- list accessList;
- 16
- 17
- integer randomNumber()
- 18
- {
- 19
- return (integer)(llFrand(99999.0))*-1;
- 20
- }
- 21
- 22
- mainMenu(key id)
- 23
- {
- 24
- llListenRemove(listener);
- 25
- mainMenuChannel = randomNumber();
- 26
- menu(id,mainMenuChannel,"Main menu",["Access"]);
- 27
- }
- 28
- 29
- menu(key user,integer channel,string title,list buttons)
- 30
- {
- 31
- llListenRemove(listener);
- 32
- listener = llListen(channel,"","","");
- 33
- llDialog(user,title,buttons,channel);
- 34
- llSetTimerEvent(25.0);
- 35
- }
- 36
- 37
- accessMenu(key id)
- 38
- {
- 39
- accessChannel = randomNumber();
- 40
- menu(id,accessChannel,"Access Menu " + "\n \n \n *Actual Access Level = " + access,["Owner","Group","Anyone","<< Back","List"]);
- 41
- }
- 42
- 43
- //Returns true if find is on src
- 44
- integer isOnList(list src, list find)
- 45
- {
- 46
- return (llListFindList(src,find) > -1);
- 47
- }
- 48
- 49
- //The function that checks if the toucher has access to the menu
- 50
- integer checkAccess(key id)
- 51
- {
- 52
- string name = llToLower(llKey2Name(id));
- 53
- 54
- return (id == llGetOwner()) || (llSameGroup(id) && access == "Group") || ( (isOnList(accessList,[name]) && (access == "List") ) || (access == "Anyone") );
- 55
- }
- 56
- 57
- default
- 58
- {
- 59
- state_entry()
- 60
- {
- 61
- 62
- if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
- 63
- {
- 64
- //A notecard named "!access" has been found, lets configure tha acess list
- 65
- llOwnerSay("Configuring, please wait...");
- 66
- notecardLine = 0;
- 67
- query = llGetNotecardLine(notecardName,notecardLine);
- 68
- }
- 69
- else
- 70
- {
- 71
- state ready;
- 72
- }
- 73
- }
- 74
- 75
- dataserver(key requested, string data)
- 76
- {
- 77
- if (requested == query)
- 78
- {
- 79
- if (data != EOF)
- 80
- {
- 81
- if ( (llGetSubString(data,0,0) != "#") && (data != "") ) //Ignore blank lines and lines starting with # (comments)
- 82
- {
- 83
- string name = llToLower(llStringTrim(data,STRING_TRIM)); //Get the lowercase name and remove white space at from beginning and end if there are
- 84
- 85
- if (llGetFreeMemory() >= 1024) //Script memory check
- 86
- {
- 87
- accessList = (accessList = []) + accessList + [name];
- 88
- }
- 89
- else
- 90
- {
- 91
- llOwnerSay(name + " could not be added because the script is running out of memory");
- 92
- state ready;
- 93
- }
- 94
- }
- 95
- notecardLine++;
- 96
- query = llGetNotecardLine(notecardName,notecardLine);
- 97
- }
- 98
- else
- 99
- {
- 100
- state ready;
- 101
- }
- 102
- }
- 103
- }
- 104
- 105
- on_rez(integer n)
- 106
- {
- 107
- if (llGetInventoryType("!config") == INVENTORY_TEXTURE)
- 108
- {
- 109
- llOwnerSay("Configuring, please wait...");
- 110
- notecardLine = 0;
- 111
- query = llGetNotecardLine(notecardName,notecardLine);
- 112
- }
- 113
- else
- 114
- {
- 115
- state ready;
- 116
- }
- 117
- }
- 118
- }
- 119
- 120
- state ready
- 121
- {
- 122
- state_entry()
- 123
- {
- 124
- llOwnerSay("--- Ready ---");
- 125
- }
- 126
- 127
- changed (integer c)
- 128
- {
- 129
- if (c & CHANGED_INVENTORY)
- 130
- {
- 131
- //we assume that notecard was edited so reload the script
- 132
- llResetScript();
- 133
- }
- 134
- }
- 135
- 136
- touch_start(integer total_number)
- 137
- {
- 138
- key toucher = llDetectedKey(0);
- 139
- if (checkAccess(toucher))
- 140
- {
- 141
- mainMenu(toucher);
- 142
- }
- 143
- else
- 144
- {
- 145
- llSay(0,"Sorry you don't have access to the main menu, current access level: " + access);
- 146
- }
- 147
- }
- 148
- 149
- listen(integer channel, string name, key id, string message)
- 150
- {
- 151
- if (channel == mainMenuChannel)
- 152
- {
- 153
- if ( (message == "Access") && (id == llGetOwner())) //Only owner can access the Access Menu
- 154
- {
- 155
- accessMenu(id);
- 156
- }
- 157
- else
- 158
- {
- 159
- llSay(0,"Sorry, only owner can access to this menu");
- 160
- }
- 161
- }
- 162
- else if (channel == accessChannel)
- 163
- {
- 164
- if (message == "<< Back")
- 165
- {
- 166
- mainMenu(id);
- 167
- return;
- 168
- }
- 169
- 170
- access = message;
- 171
- llOwnerSay("Access Mode: " + message);
- 172
- accessMenu(id);
- 173
- }
- 174
- }
- 175
- 176
- timer()
- 177
- {
- 178
- llListenRemove(listener);
- 179
- llSetTimerEvent(0.0);
- 180
- }
- 181
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement