Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. function LegoFreightvehicleSpeedCheck(%this, %obj)
  2. {
  3.  
  4. if(!isObject(%obj))
  5. return;
  6.  
  7. %vehicle = %obj;
  8.  
  9.  
  10. %slot = 0; //Play the sound in the driver's spot
  11. %speed = vectorLen(%obj.getVelocity());
  12. if(!%vehicle.oldSpeed)
  13. %vehicle.oldSpeed = %speed;
  14.  
  15. //Braking is not working currently
  16. if(%vehicle.oldSpeed)
  17. {
  18. if((%vehicle.oldSpeed - %speed) > 1) //Braking rate of speed in 500MS
  19. %applyBrakes = true;
  20.  
  21. if((%vehicle.oldSpeed - %speed) < 1)
  22. %applyBrakes = false;
  23. }
  24.  
  25. if(%speed < 0) //Keeps throwing random negative numbers when train is at dead stop
  26. %speed = 0;
  27.  
  28. %vehicle.oldSpeed = %speed;
  29. commandtoclient(%vehicle.getControllingClient(),'bottomprint', mFloor(%speed * 2) @"<font:impact:25><color:FFFFFF> BPS", 1);
  30.  
  31. //We use else if's so that it will find a true statement then skip the rest
  32. if(%speed < 2) {
  33. %vehicle.stopAudio(%slot);
  34. }
  35.  
  36. else if(%speed < 10)
  37. %vehicle.playAudio(%slot, throttle0Sound);
  38.  
  39. else if(%speed < 15)
  40. %vehicle.playAudio(%slot, throttle1Sound);
  41.  
  42. else if(%speed < 30)
  43. %vehicle.playAudio(%slot, throttle2Sound);
  44.  
  45. else if(%speed < 45)
  46. %vehicle.playAudio(%slot, throttle3Sound);
  47.  
  48. else if(%speed < 60)
  49. %vehicle.playAudio(%slot, throttle4Sound);
  50.  
  51. else if(%speed < 80)
  52. %vehicle.playAudio(%slot, throttle5Sound);
  53.  
  54. else if(%speed < 90)
  55. %vehicle.playAudio(%slot, throttle6Sound);
  56.  
  57.  
  58.  
  59. if(%applyBrakes)
  60. %vehicle.playAudio(1, squealSound);
  61. if(!%applyBrakes)
  62. %vehicle.stopAudio(1);
  63.  
  64.  
  65.  
  66.  
  67. // Correct Axis
  68.  
  69. %fullPos = %vehicle.getPosition();
  70.  
  71. %actualPos = getWord(%vehicle.getPosition(), %vehicle.axisOfCorrection);
  72. %dif = mAbs(%actualPos - %vehicle.AutoCorrectPos);
  73.  
  74. if(%dif > 0.02)
  75. {
  76.  
  77. // Make Correction
  78.  
  79. if(%vehicle.axisOfCorrection == 0)
  80. {
  81. // Correcting the X axis
  82.  
  83. %x = %vehicle.AutoCorrectPos;
  84. %y = getWord(%fullPos, 1);
  85. %z = getWord(%fullPos, 2);
  86.  
  87. %vehicle.setTransform(%x SPC %y SPC %z SPC %obj.AutoCorrectRot);
  88. }
  89.  
  90. if(%vehicle.axisOfCorrection == 1)
  91. {
  92. // Correcting the Y axis
  93.  
  94. %x = getWord(%fullPos, 0);
  95. %y = %vehicle.AutoCorrectPos;
  96. %z = getWord(%fullPos, 2);
  97.  
  98. %vehicle.setTransform(%x SPC %y SPC %z SPC %obj.AutoCorrectRot);
  99. }
  100. }
  101.  
  102.  
  103.  
  104. schedule(500,0,"LegoFreightvehicleSpeedCheck",%this,%obj);
  105. }
  106.  
  107. function LegoFreightvehicle::onadd(%this, %obj)
  108. {
  109.  
  110. parent::onadd(%this,%obj);
  111. LegoFreightvehicleSpeedCheck(%this, %obj);
  112.  
  113. schedule(100,0,"TrainAutoCorrect_GetData",%this,%obj);
  114. }
  115.  
  116.  
  117. function axisToEuler(%axis)
  118. {
  119. %angleOver2 = getWord(%axis,3) * 0.5;
  120. %angleOver2 = -%angleOver2;
  121. %sinThetaOver2 = mSin(%angleOver2);
  122. %cosThetaOver2 = mCos(%angleOver2);
  123. %q0 = %cosThetaOver2;
  124. %q1 = getWord(%axis,0) * %sinThetaOver2;
  125. %q2 = getWord(%axis,1) * %sinThetaOver2;
  126. %q3 = getWord(%axis,2) * %sinThetaOver2;
  127. %q0q0 = %q0 * %q0;
  128. %q1q2 = %q1 * %q2;
  129. %q0q3 = %q0 * %q3;
  130. %q1q3 = %q1 * %q3;
  131. %q0q2 = %q0 * %q2;
  132. %q2q2 = %q2 * %q2;
  133. %q2q3 = %q2 * %q3;
  134. %q0q1 = %q0 * %q1;
  135. %q3q3 = %q3 * %q3;
  136. %m13 = 2.0 * (%q1q3 - %q0q2);
  137. %m21 = 2.0 * (%q1q2 - %q0q3);
  138. %m22 = 2.0 * %q0q0 - 1.0 + 2.0 * %q2q2;
  139. %m23 = 2.0 * (%q2q3 + %q0q1);
  140. %m33 = 2.0 * %q0q0 - 1.0 + 2.0 * %q3q3;
  141. return mRadToDeg(mAsin(%m23)) SPC mRadToDeg(mAtan(-%m13, %m33)) SPC mRadToDeg(mAtan(-%m21, %m22));
  142. }
  143.  
  144. function TrainAutoCorrect_GetData(%this, %obj)
  145. {
  146.  
  147. %spawnBrick = %obj.spawnBrick;
  148. %spawnBrickTransform = %spawnBrick.getTransform();
  149. %spawnBrickRotation = getWords(%spawnBrickTransform, 3, 6);
  150. %spawnBrickEuler = axisToEuler(%spawnBrickRotation);
  151. %zRot = mFloor(mAbs(getWord(%spawnBrickEuler, 2)));
  152.  
  153. if(%zRot == 90)
  154. %obj.axisOfCorrection = 1;
  155. else
  156. %obj.axisOfCorrection = 0;
  157.  
  158.  
  159. %obj.AutoCorrectRot = %spawnBrickRotation;
  160. %obj.AutoCorrectPos = getWord(%spawnBrickTransform, %obj.axisOfCorrection);
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement