Advertisement
Chronos_Ouroboros

Untitled

Jul 12th, 2015
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function int clamp (int x, int min, int max) {
  2. int realMin = min;
  3. int realMax = max;
  4.  
  5. if (min > max) {
  6. realMax = min;
  7. realMin = max;
  8. }
  9.  
  10. if (x > realMax)
  11. return realMax;
  12. else if (x < realMin)
  13. return realMin;
  14. else
  15. return x;
  16. }
  17.  
  18. function int scaleValue (int x, int fromMin, int fromMax, int toMin, int toMax) {
  19. return (x - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
  20. }
  21.  
  22. function fixed scaleValueFixed (fixed x, fixed fromMin, fixed fromMax, fixed toMin, fixed toMax) {
  23. return fixedDiv (fixedMul (x - fromMin, toMax - toMin), fromMax - fromMin) + toMin;
  24. }
  25.  
  26. script "S7_RecoilPitch" (fixed offset) { // Called like this in code: TNT1 A 0 acs_namedExecuteAlways ("S7_RecoilPitch", 0, 0.5 * 65535)
  27. fixed oldPitch = getActorPitch (0);
  28. fixed scaledoffset = scaleValueFixed (offset, -90.0, 90.0, -0.25, 0.25);
  29. fixed newPitch = clamp (oldPitch - scaledoffset, -0.25, 0.25);
  30.  
  31. setActorPitch (0, newPitch);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement