Advertisement
bob82604

Bin control script.

Apr 21st, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. list options = ["Add","Get","Close","-"];
  2. integer dialogChannel;
  3. integer listenHandle;
  4. string dialogInfo = "\nPlease make a choice.";
  5. key ToucherID;
  6.  
  7. integer pLid;
  8. integer pLevel;
  9.  
  10. integer dir = 1;
  11.  
  12. integer level;
  13.  
  14. setPrimNumbers()
  15. {
  16. integer i;
  17.  
  18. for (i=1;i<=llGetNumberOfPrims();i++)
  19. {
  20. if (llGetLinkName(i) == "lid")
  21. {
  22. pLid = i;
  23. }
  24. else if (llGetLinkName(i) == "level")
  25. {
  26. pLevel = i;
  27. }
  28. }
  29. }
  30.  
  31. default
  32. {
  33. state_entry()
  34. {
  35. rotation rot;
  36. //rotation d90 = llEuler2Rot(<0,0,90>*DEG_TO_RAD);
  37. vector e90 = <0,0,90>*DEG_TO_RAD;
  38. rotation d90 = llEuler2Rot(e90);
  39.  
  40. dir=1;
  41. level=0;
  42. setPrimNumbers();
  43. dialogChannel = -1 - (integer)("0x" + llGetSubString( (string) llGetKey(), -7, -1) );
  44. list params = llGetLinkPrimitiveParams(pLid,[PRIM_ROT_LOCAL]);
  45. rot = llList2Rot(params,0);
  46. vector vec = llRot2Euler(rot);
  47. vector vec90 = llRot2Euler(d90);
  48. rot = llEuler2Rot(<vec.x, vec.y, vec90.z>);
  49. llSetLinkPrimitiveParamsFast(pLid,[PRIM_ROT_LOCAL,rot]);
  50. }
  51.  
  52. touch_start(integer num_total)
  53. {
  54. if(llDetectedLinkNumber(0) == pLid)
  55. {
  56. dir *= -1;
  57. list params = llGetLinkPrimitiveParams(pLid,[PRIM_ROT_LOCAL]);
  58. rotation rot = llList2Rot(params,0);
  59. llSetLinkPrimitiveParamsFast(pLid,[PRIM_ROT_LOCAL,llEuler2Rot(<0, 0, dir * PI_BY_TWO>) * rot]);
  60. }
  61. else
  62. {
  63. ToucherID = llDetectedKey(0);
  64. llListenRemove(listenHandle);
  65. listenHandle = llListen(dialogChannel,"",ToucherID,"");
  66. llDialog(ToucherID,dialogInfo,options,dialogChannel);
  67. }
  68. }
  69.  
  70. listen(integer channel, string name, key id, string message)
  71. {
  72. if (message == "Add")
  73. {
  74. if (level < 10)
  75. {
  76. level +=1;
  77. list params = llGetLinkPrimitiveParams(pLevel,[PRIM_POS_LOCAL]);
  78. vector loc = llList2Vector(params,0);
  79. loc.z += 0.1275;
  80. llSetLinkPrimitiveParams(pLevel,[PRIM_POS_LOCAL,loc]);
  81. llSay(0,"Your bin is now at "+level*10+"%\n");
  82. }
  83. else
  84. {
  85. llSay(0,"Your bin is full.\n");
  86. }
  87. }
  88. else if (message == "Get")
  89. {
  90. if (level > 0)
  91. {
  92. level -=1;
  93. list params = llGetLinkPrimitiveParams(pLevel,[PRIM_POS_LOCAL]);
  94. vector loc = llList2Vector(params,0);
  95. loc.z -= 0.1275;
  96. llSetLinkPrimitiveParams(pLevel,[PRIM_POS_LOCAL,loc]);
  97. llSay(0,"Your bin is now at "+level*10+"%\n");
  98. }
  99. else
  100. {
  101. llSay(0,"Your bin is empty.\n");
  102. }
  103. }
  104. else if (message == "-")
  105. {
  106. llDialog(ToucherID, dialogInfo, options, dialogChannel);
  107. return;
  108. }
  109. else
  110. {
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement