a62e2486-d481-1758-346c-f24aed5488bd_script.lsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*
  4. * Part of the Sloodle project (www.sloodle.org)
  5. *
  6. * Copyright (c) 2011-06 contributors (see below)
  7. * Released under the GNU GPL v3
  8. * -------------------------------------------
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * All scripts must maintain this copyrite information, including the contributer information listed
  24. *
  25. * Contributers:
  26. * Originally Written by Tdub Dowler
  27. * Modified by Awsoonn Rawley
  28. * Refactored by Strife Onizuka
  29. * Modified by Paul Preibisch and Edmund Edgar for Sloodle and Opensim to eliminate the need for a sepearate script in each zztext prim, and to be independant of texture UUIDS
  30. *
  31. */
  32. list decode=[]; // to handle special characters from CP850 page for european countries
  33. integer SLOODLE_CHANNEL_SCOREBOARD_UPDATE_COMPLETE = 1639271140;
  34. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES = 1639272100;
  35. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_CONFIG = -1639272000;
  36. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_SET_CELL_INFO=-1639272001; //this is set on the zztext prims cell description
  37. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_REMAP_INDICIES=-1639272002;
  38. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_RESET_INDICIES=-1639272003;
  39. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_SET_THICKNESS=-1639272004;
  40. integer SLOODLE_CHANNEL_SCOREBOARD_SCORES_SET_COLOR=-1639272005;
  41. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_CONFIG = -1639273000;
  42. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_SET_CELL_INFO = -1639273001;
  43. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_REMAP_INDICIES = -1639273002;
  44. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_RESET_INDICIES = -1639273003;
  45. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_SET_THICKNESS = -1639273004;
  46. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM_SET_COLOR = -1639273005;
  47. integer SLOODLE_CHANNEL_SCOREBOARD_TEAM = 1639273100;
  48. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_CONFIG = -1639274000;
  49. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_SET_CELL_INFO = -1639274001;
  50. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_REMAP_INDICIES = -1639274002;
  51. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_RESET_INDICIES = -1639274003;
  52. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_SET_THICKNESS = -1639274004;
  53. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY_SET_COLOR = -1639274005;
  54. integer SLOODLE_CHANNEL_SCOREBOARD_CURRENCY = 1639274100;
  55. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_CONFIG = -1639275000;
  56. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_SET_CELL_INFO = -1639275001;
  57. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_REMAP_INDICIES = -1639275002;
  58. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_RESET_INDICIES = -1639275003;
  59. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_SET_THICKNESS = -1639275004;
  60. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE_SET_COLOR = -1639275005;
  61. integer SLOODLE_CHANNEL_SCOREBOARD_TITLE= 1639275100;
  62. integer SLOODLE_CHANNEL_ZZTEXT_TEXTURE_CONFIG= -1639276000;
  63. list CHARACTER_GRID;
  64. integer FACE_1 = 3;
  65. integer FACE_2 = 7;
  66. integer FACE_3 = 4;
  67. integer FACE_4 = 6;
  68. integer FACE_5 = 1;
  69. /*
  70. FUNCTION debug(string message)
  71. debugging function - use the prim material setting as a toggle for debug messages.
  72. if material is flesh (means a human needs to read message) then debugging is on, of material is not flesh
  73. debugging is off
  74. */
  75. debug (string message){
  76. list params = llGetPrimitiveParams ([PRIM_MATERIAL ]);
  77. if (llList2Integer (params ,0)==PRIM_MATERIAL_FLESH){
  78. llOwnerSay(llGetObjectName()+"."+llGetScriptName()+": "+message);
  79. }
  80. }
  81. vector GetGridOffset(vector grid_pos) {
  82. // Zoom in on the texture showing our character pair.
  83. integer Col = llRound(grid_pos.x) % 40; // PK was 20
  84. integer Row = llRound(grid_pos.y) % 20; // PK was 10
  85. // Return the offset in the texture.
  86. return <-0.45 + 0.025 * Col, 0.45 - 0.05 * Row, 0.0>; // PK was 0.05 and 0.1
  87. }
  88. /*
  89. * renderString will render the string to all the zzTextprims having the name which is set via the zzTextPrimNames
  90. * make sure to name each zztextprim the same name, and also in their description field to number each prim from 1 - your max number of zztextprims,
  91. * So if your display has 50 prims, put in their description 1, then the next zzprim description 2 etc
  92. */
  93. renderString(string str,string zzTextPrimNames){
  94. integer prims = llGetNumberOfPrims();
  95. vector GridPos1;vector GridPos2;vector GridPos3;vector GridPos4;vector GridPos5;
  96. integer currentLink=0;
  97. integer currentCellCharPosition=0;
  98. string linkDescription;
  99. string textToRender;
  100. do{
  101. if (llList2String(llGetLinkPrimitiveParams(currentLink, [PRIM_NAME]),0)==zzTextPrimNames){
  102. currentCellCharPosition=llList2Integer(llGetLinkPrimitiveParams(currentLink, [PRIM_DESC]),0)*10;
  103. //get the part of the text between the cells start and end position
  104. textToRender = llGetSubString(str, currentCellCharPosition, currentCellCharPosition+ 9);
  105. // Get the grid positions for each pair of characters.
  106. GridPos1 = GetGridPos( GetIndex(llGetSubString(textToRender, 0, 0)),GetIndex(llGetSubString(textToRender, 1, 1)) );
  107. GridPos2 = GetGridPos( GetIndex(llGetSubString(textToRender, 2, 2)),GetIndex(llGetSubString(textToRender, 3, 3)) );
  108. GridPos3 = GetGridPos( GetIndex(llGetSubString(textToRender, 4, 4)),GetIndex(llGetSubString(textToRender, 5, 5)) );
  109. GridPos4 = GetGridPos( GetIndex(llGetSubString(textToRender, 6, 6)),GetIndex(llGetSubString(textToRender, 7, 7)) );
  110. GridPos5 = GetGridPos( GetIndex(llGetSubString(textToRender, 8, 8)),GetIndex(llGetSubString(textToRender, 9, 9)) );
  111. key gridTexture1= GetGridTexture(GridPos1);key gridTexture2= GetGridTexture(GridPos2);key gridTexture3= GetGridTexture(GridPos3);key gridTexture4= GetGridTexture(GridPos4);key gridTexture5= GetGridTexture(GridPos5);
  112. llSetLinkPrimitiveParamsFast(currentLink,
  113. [
  114. PRIM_TEXTURE, FACE_1, gridTexture1, <0.125, 0.05, 0>, GetGridOffset(GridPos1) + <0.0375-0.025-0.002, 0.025, 0>, 0.0,
  115. PRIM_TEXTURE, FACE_2, gridTexture2, <0.05, 0.05, 0>, GetGridOffset(GridPos2)+<-0.025-0.002, 0.025,0>, 0.0,
  116. PRIM_TEXTURE, FACE_3, gridTexture3, <-0.74, 0.05, 0>, GetGridOffset(GridPos3)+ <-.34-0.002, 0.025, 0>, 0.0,
  117. PRIM_TEXTURE, FACE_4,gridTexture4, <0.05, 0.05, 0>, GetGridOffset(GridPos4)+<-0.025-0.002, 0.025,0>, 0.0,
  118. PRIM_TEXTURE, FACE_5, gridTexture5, <0.125, 0.05, 0>, GetGridOffset(GridPos5) + <0.0375-0.025-0.077-0.002, 0.025, 0>, 0.0
  119. ]
  120. );
  121. }
  122. }while(++currentLink < prims);
  123. }
  124. loadTextures(){
  125. CHARACTER_GRID=[];
  126. integer numTextures;
  127. numTextures = llGetInventoryNumber(INVENTORY_TEXTURE);
  128. integer i=0;
  129. for (i=0;i<numTextures;i++){
  130. string name = llGetInventoryName(INVENTORY_TEXTURE,i);
  131. CHARACTER_GRID+=llGetInventoryKey(name);
  132. }
  133. }
  134. string GetGridTexture(vector grid_pos) {
  135. // Calculate the texture in the grid to use.
  136. integer GridCol = llRound(grid_pos.x) / 40; // PK was 20
  137. integer GridRow = llRound(grid_pos.y) / 20; // PK was 10
  138. // Lookup the texture.
  139. key Texture = llList2Key(CHARACTER_GRID, GridRow * (GridRow + 1) / 2 + GridCol);
  140. return Texture;
  141. }
  142. string LOAD_MSG = "Loading...";
  143. ///////////// END CONSTANTS ////////////////
  144. integer prims;
  145. set_scoreboard_score_text(string msg)
  146. {
  147. renderString(msg,"zztextprim");
  148. }
  149. set_scoreboard_team_text(string msg)
  150. {
  151. renderString(msg,"zztextprim_team");
  152. }
  153. set_scoreboard_currency_text(string msg)
  154. {
  155. renderString(msg,"zztextprim_currency");
  156. }
  157. set_scoreboard_title_text(string msg)
  158. {
  159. renderString(msg,"zztextprim_title");
  160. }
  161. vector GetGridPos(integer index1, integer index2) {
  162. // There are two ways to use the lookup table...
  163. integer Col;
  164. integer Row;
  165. if (index1 >= index2) {
  166. // In this case, the row is the index of the first character:
  167. Row = index1;
  168. // And the col is the index of the second character (x2)
  169. Col = index2 * 2;
  170. }
  171. else { // Index1 < Index2
  172. // In this case, the row is the index of the second character:
  173. Row = index2;
  174. // And the col is the index of the first character, x2, offset by 1.
  175. Col = index1 * 2 + 1;
  176. }
  177. return <Col, Row, 0>;
  178. }
  179. // All displayable characters. Default to ASCII order.
  180. string gCharIndex;
  181. ResetCharIndex() {
  182. gCharIndex = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`";
  183. // \" <-- Fixes LSL syntax highlighting bug.
  184. gCharIndex += "abcdefghijklmnopqrstuvwxyz{|}~";
  185. // cap cedille u: e/ a^ a: a/ a ring cedille e^ e:
  186. decode= ["%C3%87", "%C3%BC", "%C3%A9", "%C3%A2", "%C3%A4", "%C3%A0", "%C3%A5", "%C3%A7", "%C3%AA", "%C3%AB",
  187. // e\ i: i^ i\ A: A ring E/ ae AE marker >
  188. "%C3%A8", "%C3%AF", "%C3%AE", "%C3%AC", "%C3%84", "%C3%85", "%C3%89", "%C3%A6", "%C3%86", "%E2%96%B6" ,
  189. // o: o/ u^ u\ y: O: U: cent pound yen
  190. "%C3%B6", "%C3%B2", "%C3%BB", "%C3%B9", "%C3%BF", "%C3%96", "%C3%9C", "%C2%A2", "%C2%A3", "%C2%A5",
  191. // A^ a/ i/ o/ u/ n~ E: y/ inv ? O^
  192. "%C3%82", "%C3%A1", "%C3%AD", "%C3%B3", "%C3%BA", "%C3%B1", "%C3%8B", "%C3%BD", "%C2%BF", "%C3%94",
  193. // inv ! I\ I/ degree E^ I^ o^ U^
  194. "%C2%A1", "%C3%8C", "%C3%8D", "%C2%B0", "%C3%8A", "%C3%8E", "%C3%B4", "%C3%9B",
  195. // Y: euro german ss E\ A\ A/ U\ U/ O\ O/
  196. "%C3%9D", "%E2%82%AC", "%C3%9F", "%C3%88", "%C3%80", "%C3%81", "%C3%99", "%C3%9A", "%C3%92", "%C3%93",
  197. // Sv sv zv Zv Y: I:
  198. "%C5%A0", "%C5%A1", "%C5%BE", "%C5%BD", "%C3%9D", "%C3%8C" ];
  199. }
  200. integer GetIndex(string char)
  201. {
  202. integer ret=llSubStringIndex(gCharIndex, char);
  203. if(ret>=0) return ret;
  204. // special char do nice trick :)
  205. string escaped=llEscapeURL(char);
  206. if(escaped=="%E2%80%99") return 7; // remap ’
  207. //llSay(0,"Looking for "+escaped);
  208. integer found=llListFindList(decode, [escaped]);
  209. // not found
  210. if(found<0) return 0;
  211. // return correct index
  212. return llStringLength(gCharIndex)+found;
  213. }
  214. XytstOrder()
  215. {
  216. // Fills each cell of the board with it's number.
  217. string str = "";
  218. integer i = 0;
  219. do
  220. {
  221. str += llGetSubString(" " + (string)i,-10,-1);
  222. llSetText("Generating Pattern: " + (string)i, <0,1,0>, 1.0);
  223. }while(++i < prims);
  224. llSetText("Displaying Order Test...", <0,1,0>, 1.0);
  225. // Send the message
  226. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_SCOREBOARD_SCORES_CONFIG, str, "");
  227. llSetText("", <0,1,0>, 0);
  228. }
  229. default
  230. {
  231. on_rez(integer start)
  232. {
  233. llResetScript();
  234. }
  235. state_entry()
  236. {
  237. // Determin the number of prims.
  238. prims = llGetNumberOfPrims();
  239. ResetCharIndex();
  240. loadTextures();
  241. // Clear the screen.
  242. set_scoreboard_score_text("");
  243. set_scoreboard_score_text("");
  244. set_scoreboard_team_text("");
  245. set_scoreboard_currency_text("");
  246. set_scoreboard_title_text(LOAD_MSG);
  247. integer StartLink = llGetLinkNumber() + 1;
  248. // Configure the board.
  249. integer i = 0;
  250. // set_scoreboard_score_text("THIS IS A TEST 123");
  251. }
  252. link_message(integer sender_num, integer num, string str, key id) {
  253. if (num==SLOODLE_CHANNEL_SCOREBOARD_UPDATE_COMPLETE){
  254. list lines = llParseString2List(str, ["\n"], []);
  255. list status = llParseString2List(llList2String(lines,1), ["|"], []); //status|page_num|num_page|scoreboard_name|team|currency
  256. integer pageNum = llList2Integer(status,1);
  257. integer numPages = llList2Integer(status,2);
  258. string scoreboardName= llList2String(status,3);
  259. string teamName= llList2String(status,4);
  260. string currency= llList2String(status,5);
  261. list users;
  262. integer numLines = llGetListLength(lines);
  263. debug("****************numLines: "+(string)numLines);
  264. integer numUsers= llGetListLength(lines)-2;
  265. integer i=0;
  266. list scores;
  267. string scoreboardText="";
  268. //the first two lines are our status and info lines
  269. //the remaining lines is our userdata
  270. for (i=2;i<numLines;i++){
  271. list userData=llParseString2List(llList2String(lines,i),["|"], []);
  272. debug("parsing: "+llList2String(lines,i));
  273. users+=llList2Key(userData,0);
  274. scores+=llList2Integer(userData,1);
  275. scoreboardText+=llList2String(userData,2);
  276. }
  277. set_scoreboard_score_text(scoreboardText);
  278. set_scoreboard_team_text(teamName);
  279. set_scoreboard_currency_text(currency);
  280. set_scoreboard_title_text(scoreboardName);
  281. }
  282. }
  283. }
  284. // Please leave the following line intact to show where the script lives in Git:
  285. // SLOODLE LSL Script Git Location: mod/scoreboard-1.0/objects/default/assets/_zztext_efficient_board_control.lslp