Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.33 KB | None | 0 0
  1. 1
  2. list notecardsList;
  3. 2
  4.  
  5. 3
  6. integer listener;
  7. 4
  8. integer mainMenuChannel;
  9. 5
  10. integer accessChannel;
  11. 6
  12.  
  13. 7
  14. integer notecardLine;
  15. 8
  16.  
  17. 9
  18. string notecardName = "!access";
  19. 10
  20.  
  21. 11
  22. key query;
  23. 12
  24.  
  25. 13
  26. string access = "Owner";
  27. 14
  28.  
  29. 15
  30. list accessList;
  31. 16
  32.  
  33. 17
  34. integer randomNumber()
  35. 18
  36. {
  37. 19
  38.     return (integer)(llFrand(99999.0))*-1;
  39. 20
  40. }
  41. 21
  42.  
  43. 22
  44. mainMenu(key id)
  45. 23
  46. {
  47. 24
  48.     llListenRemove(listener);
  49. 25
  50.     mainMenuChannel = randomNumber();
  51. 26
  52.     menu(id,mainMenuChannel,"Main menu",["Access"]);
  53. 27
  54. }
  55. 28
  56.  
  57. 29
  58. menu(key user,integer channel,string title,list buttons)
  59. 30
  60. {
  61. 31
  62.     llListenRemove(listener);
  63. 32
  64.     listener = llListen(channel,"","","");
  65. 33
  66.     llDialog(user,title,buttons,channel);
  67. 34
  68.     llSetTimerEvent(25.0);
  69. 35
  70. }
  71. 36
  72.  
  73. 37
  74. accessMenu(key id)
  75. 38
  76. {
  77. 39
  78.     accessChannel = randomNumber();
  79. 40
  80.     menu(id,accessChannel,"Access Menu " + "\n \n \n *Actual Access Level = " + access,["Owner","Group","Anyone","<< Back","List"]);
  81. 41
  82. }
  83. 42
  84.  
  85. 43
  86. //Returns true if find is on src
  87. 44
  88. integer isOnList(list src, list find)
  89. 45
  90. {
  91. 46
  92.      return (llListFindList(src,find) > -1);
  93. 47
  94. }
  95. 48
  96.  
  97. 49
  98. //The function that checks if the toucher has access to the menu
  99. 50
  100. integer checkAccess(key id)
  101. 51
  102. {
  103. 52
  104.     string name = llToLower(llKey2Name(id));
  105. 53
  106.  
  107. 54
  108.     return (id == llGetOwner()) || (llSameGroup(id) && access == "Group") || ( (isOnList(accessList,[name]) && (access == "List") ) || (access == "Anyone") );
  109. 55
  110. }
  111. 56
  112.  
  113. 57
  114. default
  115. 58
  116. {
  117. 59
  118.     state_entry()
  119. 60
  120.     {
  121. 61
  122.  
  123. 62
  124.         if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
  125. 63
  126.         {
  127. 64
  128.             //A notecard named "!access" has been found, lets configure tha acess list
  129. 65
  130.             llOwnerSay("Configuring, please wait...");
  131. 66
  132.             notecardLine = 0;
  133. 67
  134.             query = llGetNotecardLine(notecardName,notecardLine);
  135. 68
  136.         }
  137. 69
  138.         else
  139. 70
  140.         {
  141. 71
  142.             state ready;
  143. 72
  144.         }
  145. 73
  146.     }
  147. 74
  148.  
  149. 75
  150.     dataserver(key requested, string data)
  151. 76
  152.     {
  153. 77
  154.         if (requested == query)
  155. 78
  156.         {
  157. 79
  158.             if (data != EOF)
  159. 80
  160.             {
  161. 81
  162.                 if ( (llGetSubString(data,0,0) != "#") && (data != "") ) //Ignore blank lines and lines starting with # (comments)
  163. 82
  164.                 {
  165. 83
  166.                     string name = llToLower(llStringTrim(data,STRING_TRIM)); //Get the lowercase name and remove white space at from beginning and end if there are
  167. 84
  168.  
  169. 85
  170.                     if (llGetFreeMemory() >= 1024) //Script memory check
  171. 86
  172.                     {
  173. 87
  174.                         accessList = (accessList = []) + accessList + [name];
  175. 88
  176.                     }
  177. 89
  178.                     else
  179. 90
  180.                     {
  181. 91
  182.                         llOwnerSay(name + " could not be added because the script is running out of memory");
  183. 92
  184.                         state ready;
  185. 93
  186.                     }
  187. 94
  188.                 }
  189. 95
  190.                 notecardLine++;
  191. 96
  192.                 query = llGetNotecardLine(notecardName,notecardLine);
  193. 97
  194.             }
  195. 98
  196.             else
  197. 99
  198.             {
  199. 100
  200.                 state ready;
  201. 101
  202.             }
  203. 102
  204.         }
  205. 103
  206.     }
  207. 104
  208.  
  209. 105
  210.     on_rez(integer n)
  211. 106
  212.     {
  213. 107
  214.         if (llGetInventoryType("!config") == INVENTORY_TEXTURE)
  215. 108
  216.         {
  217. 109
  218.             llOwnerSay("Configuring, please wait...");
  219. 110
  220.             notecardLine = 0;
  221. 111
  222.             query = llGetNotecardLine(notecardName,notecardLine);
  223. 112
  224.         }
  225. 113
  226.         else
  227. 114
  228.         {
  229. 115
  230.             state ready;
  231. 116
  232.         }
  233. 117
  234.     }
  235. 118
  236. }
  237. 119
  238.  
  239. 120
  240. state ready
  241. 121
  242. {
  243. 122
  244.     state_entry()
  245. 123
  246.     {
  247. 124
  248.         llOwnerSay("--- Ready ---");
  249. 125
  250.     }
  251. 126
  252.  
  253. 127
  254.     changed (integer c)
  255. 128
  256.     {
  257. 129
  258.         if (c & CHANGED_INVENTORY)
  259. 130
  260.         {
  261. 131
  262.             //we assume that notecard was edited so reload the script
  263. 132
  264.             llResetScript();
  265. 133
  266.         }
  267. 134
  268.     }
  269. 135
  270.  
  271. 136
  272.     touch_start(integer total_number)
  273. 137
  274.     {
  275. 138
  276.         key toucher = llDetectedKey(0);
  277. 139
  278.         if (checkAccess(toucher))
  279. 140
  280.         {
  281. 141
  282.             mainMenu(toucher);
  283. 142
  284.         }
  285. 143
  286.         else
  287. 144
  288.         {
  289. 145
  290.             llSay(0,"Sorry you don't have access to the main menu, current access level: " + access);
  291. 146
  292.         }
  293. 147
  294.     }
  295. 148
  296.  
  297. 149
  298.     listen(integer channel, string name, key id, string message)
  299. 150
  300.     {
  301. 151
  302.         if (channel == mainMenuChannel)
  303. 152
  304.         {
  305. 153
  306.             if ( (message == "Access") && (id == llGetOwner())) //Only owner can access the Access Menu
  307. 154
  308.             {
  309. 155
  310.                 accessMenu(id);
  311. 156
  312.             }
  313. 157
  314.             else
  315. 158
  316.             {
  317. 159
  318.                 llSay(0,"Sorry, only owner can access to this menu");
  319. 160
  320.             }
  321. 161
  322.         }
  323. 162
  324.         else if (channel == accessChannel)
  325. 163
  326.         {
  327. 164
  328.             if (message == "<< Back")
  329. 165
  330.             {
  331. 166
  332.                 mainMenu(id);
  333. 167
  334.                 return;
  335. 168
  336.             }
  337. 169
  338.  
  339. 170
  340.             access = message;
  341. 171
  342.             llOwnerSay("Access Mode: " + message);
  343. 172
  344.             accessMenu(id);
  345. 173
  346.         }
  347. 174
  348.     }
  349. 175
  350.  
  351. 176
  352.     timer()
  353. 177
  354.     {
  355. 178
  356.         llListenRemove(listener);
  357. 179
  358.         llSetTimerEvent(0.0);
  359. 180
  360.     }
  361. 181
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement