xs_texture.lsl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // :CATEGORY:XS Pet
  2. // :NAME:XS Pet Robot
  3. // :AUTHOR:Ferd Frederix
  4. // :KEYWORDS: Pet,XS,breed,breedable,companion,Ozimal,Meeroo,Amaretto,critter,Fennux,Pets
  5. // :CREATED:2013-09-06
  6. // :EDITED:2014-01-30 12:24:21
  7. // :ID:988
  8. // :NUM:1455
  9. // :REV:0.50
  10. // :WORLD:Second Life, OpenSim, Opensim
  11. // :DESCRIPTION:
  12. // XS Pet xs_texture plug in
  13. // :CODE:
  14. //xs_texture plug in
  15. // 12-3-2012 - no longer dorks with the offset, repeat, or rotation when applying a texture
  16. /////////////////////////////////////////////////////////////////////
  17. // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
  18. // See http://creativecommons.org/licenses/by-nc-sa/3.0/
  19. // Noncommercial -- You may not use this work for commercial purposes
  20. // If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
  21. // This means that you cannot sell this code but you may share this code.
  22. // You must attribute authorship to me and leave this notice intact.
  23. //
  24. // Exception: I am allowing this script to be sold inside an original build.
  25. // You are not selling the script, you are selling the build.
  26. // Ferd Frederix
  27. //////////////////////////////////////////////////////////
  28. // CONFIGURATION //
  29. //////////////////////////////////////////////////////////
  30. // you must put in a UUID from this web site here and in the Server script
  31. // http://gridurl.appspot.com/random
  32. string UUID = "48246356-a7c5-474b-a6fe-f2cec98926b2"; // do not use this number, use your own from http://gridurl.appspot.com/random
  33. integer debug = TRUE; // set to TRUE to see debug messages
  34. //////////////////////////////////////////////////////////
  35. // INTERNALS //
  36. //////////////////////////////////////////////////////////
  37. integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
  38. integer LINK_BREEDNAME = 802; // the name of the pet texture from the texture server notecard
  39. key URLRqstKey;
  40. key textureRqstKey;
  41. string newpath ;
  42. // globals to hold the params linked in from the brain
  43. vector colorCode1;
  44. vector colorCode2;
  45. integer sex;
  46. integer shine;
  47. float glow;
  48. float breed;
  49. DEBUG(string msg)
  50. {
  51. if (debug)
  52. llOwnerSay(llGetScriptName() + " : " + msg);
  53. }
  54. key Request(string cmd)
  55. {
  56. DEBUG("Sending:"+newpath+"?"+cmd);
  57. return llHTTPRequest( newpath+"?"+cmd, [HTTP_METHOD, "GET"], "");
  58. }
  59. key TextureRequest()
  60. {
  61. string URL = newpath + "?breed=" + llEscapeURL((string) breed) ;
  62. DEBUG("Sending: "+ URL);
  63. return llHTTPRequest( URL, [HTTP_METHOD, "POST"], "");
  64. }
  65. // change texture of amny prims named texture1 to texture6
  66. TextureIt(list textures)
  67. {
  68. // :texture|Breed Type 2|Body|fa8b0052-3a8d-48ce-ac56-6d14bfb956a9|Wing|dda55c64-46c7-4ed8-88c0-7b159ffa3b24|
  69. integer nPrims = llGetNumberOfPrims();
  70. integer i;
  71. for (i = 0; i <= nPrims; i++)
  72. {
  73. list param = llGetLinkPrimitiveParams(i,[PRIM_NAME]); // name holds the texture number
  74. string primName = llList2String(param,0);
  75. // root is special
  76. if ( i == 1)
  77. primName = "root";
  78. integer where = llListFindList(textures,[primName]);
  79. if (where >= 0)
  80. {
  81. key UUID = (key) llList2String(textures,where+1);
  82. // DEBUG("Set Texture: " + primName + " on prim #" + (string) i);
  83. // apply texture and the other params
  84. llSetLinkPrimitiveParamsFast(i, [PRIM_COLOR, ALL_SIDES, <1,1,1>, 1.0, PRIM_BUMP_SHINY, ALL_SIDES, shine, PRIM_BUMP_NONE, PRIM_GLOW, ALL_SIDES, glow]); // delete the prim texture
  85. llSetLinkTexture(i,UUID,ALL_SIDES); // add this line which sets the texture with no offset or repeat or rotation changes
  86. }
  87. }
  88. }
  89. default
  90. {
  91. state_entry()
  92. {
  93. // not a lot to do
  94. }
  95. on_rez(integer param)
  96. {
  97. llResetScript();
  98. }
  99. link_message(integer who, integer num, string str, key id)
  100. {
  101. // there are two vectors, sent in one packet
  102. if (num == LINK_TEXTURE)
  103. {
  104. DEBUG("received LINK_TEXTURE");
  105. list params = llParseString2List(str,["^"],[]);
  106. colorCode1 = (vector) llList2String(params,0);
  107. colorCode2 = (vector) llList2String(params,1);
  108. sex = (integer) llList2String(params,2);
  109. shine = (integer) llList2String(params,3);
  110. glow = (float) llList2String(params,4);
  111. breed = colorCode1.x; // the breed is based on the Red value of Color 1
  112. URLRqstKey = llHTTPRequest( "http://gridurl.appspot.com/get/"+ llEscapeURL(UUID ), [HTTP_METHOD, "GET"], ""); // find the other object/script
  113. }
  114. }
  115. http_response(key request_id, integer status, list metadata, string body)
  116. {
  117. if (URLRqstKey == request_id)
  118. {
  119. URLRqstKey = NULL_KEY; // the same event sometimes shows up more then once
  120. if(status != 200)
  121. llOwnerSay("The internet is broken! status="+(string)status+" "+body);
  122. else
  123. {
  124. DEBUG(body);
  125. newpath= body;
  126. textureRqstKey = TextureRequest(); // request the object name
  127. }
  128. }
  129. else if (textureRqstKey == request_id)
  130. {
  131. if(status != 200)
  132. llOwnerSay("request failed status="+(string)status+" "+ body);
  133. else {
  134. DEBUG("response:" + body); // report what was returned from request
  135. list textures = llParseString2List(body,["|"],[]);
  136. if (llList2String(textures,0) == "texture")
  137. {
  138. string sName = llList2String(textures,1); // the texture name
  139. llMessageLinked(LINK_SET,LINK_BREEDNAME,sName,"");
  140. textures = llDeleteSubList(textures,1,1); // put it back the old way
  141. TextureIt(textures);
  142. }
  143. }
  144. }
  145. }
  146. }