Chronos_Ouroboros

Hacky hacks

Oct 12th, 2016
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. Oh god, this is so hacky
  2. ===================== DECORATE =====================
  3. actor boolean : inventory {
  4. inventory.maxAmount 1
  5. inventory.interHubAmount 1
  6.  
  7. +inventory.undroppable -inventory.invBar
  8. }
  9.  
  10. actor AlreadyRunningYaDerp : boolean { }
  11. actor HerpDerpScriptExecutor : customInventory {
  12. inventory.maxAmount 1
  13.  
  14. +inventory.autoActivate +inventory.quiet
  15.  
  16. states {
  17. Spawn:
  18. WHOOPS:
  19. TNT1 A 0
  20. stop
  21. Use:
  22. TNT1 A 0 A_JumpIfInventory ("AlreadyRunningYaDerp", 1, "WHOOPS")
  23. TNT1 A 0 ACS_NamedExecuteAlways ("IAMASCRIPT")
  24. TNT1 A 0 A_GiveInventory ("AlreadyRunningYaDerp", 1)
  25. stop
  26. }
  27. }
  28.  
  29. ======================== ACS ========================
  30. Function int ScaleValue (int x, int fromMin, int fromMax, int toMin, int toMax) {
  31. return (x - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
  32. }
  33.  
  34. Function int Clamp (int x, int min, int max) {
  35. if (min > max) { // XOR SWAPS YAY
  36. min ^= max;
  37. max ^= min;
  38. min ^= max;
  39. }
  40.  
  41. if (x > max) return max;
  42. else if (x < min) return min;
  43. else return x;
  44. }
  45.  
  46. Script "IRUNSCRIPTS" OPEN {
  47. while (TRUE) {
  48. for (int i = 0; i < 9999; i++) // The proper way would be to actually loop from -32768 to 32767, but that'd lag badly. Even looping from 0 to 9999 can lag a bit if you have a very slow computer
  49. GiveInventory ("HerpDerpScriptExecutor", 1);
  50.  
  51. Delay (35 * 5); // Delay/Sleep/Wait for 5 seconds
  52. }
  53. }
  54.  
  55. Script "IAMASCRIPT" (void) {
  56. int oldSpeed = GetActorProperty (0, APROP_Speed); // Get the actor's speed, and store it in a separate variable
  57. int maxHealth = GetActorProperty (0, APROP_SpawnHealth); // Get the actor's spawnHealth (Usually their "max" health)
  58. int healthP; // This will be used to store the current health percentage
  59. while (TRUE) {
  60. healthP = (ScaleValue (Clamp (GetActorProperty (0, APROP_Health), 0, maxHealth), 0, maxHealth, 0, 100) << 16) / 100; // Yay fixed point and bitshifts
  61.  
  62. SetActorProperty (0, APROP_Speed, oldSpeed * healthP); // Scales the speed by the health percentage
  63.  
  64. Delay (1); // Delay for one tic. This is necessary so the script doesn't get terminated for being a runaway script
  65. }
  66. }
Add Comment
Please, Sign In to add comment