Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Oh god, this is so hacky
- ===================== DECORATE =====================
- actor boolean : inventory {
- inventory.maxAmount 1
- inventory.interHubAmount 1
- +inventory.undroppable -inventory.invBar
- }
- actor AlreadyRunningYaDerp : boolean { }
- actor HerpDerpScriptExecutor : customInventory {
- inventory.maxAmount 1
- +inventory.autoActivate +inventory.quiet
- states {
- Spawn:
- WHOOPS:
- TNT1 A 0
- stop
- Use:
- TNT1 A 0 A_JumpIfInventory ("AlreadyRunningYaDerp", 1, "WHOOPS")
- TNT1 A 0 ACS_NamedExecuteAlways ("IAMASCRIPT")
- TNT1 A 0 A_GiveInventory ("AlreadyRunningYaDerp", 1)
- stop
- }
- }
- ======================== ACS ========================
- Function int ScaleValue (int x, int fromMin, int fromMax, int toMin, int toMax) {
- return (x - fromMin) * (toMax - toMin) / (fromMax - fromMin) + toMin;
- }
- Function int Clamp (int x, int min, int max) {
- if (min > max) { // XOR SWAPS YAY
- min ^= max;
- max ^= min;
- min ^= max;
- }
- if (x > max) return max;
- else if (x < min) return min;
- else return x;
- }
- Script "IRUNSCRIPTS" OPEN {
- while (TRUE) {
- 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
- GiveInventory ("HerpDerpScriptExecutor", 1);
- Delay (35 * 5); // Delay/Sleep/Wait for 5 seconds
- }
- }
- Script "IAMASCRIPT" (void) {
- int oldSpeed = GetActorProperty (0, APROP_Speed); // Get the actor's speed, and store it in a separate variable
- int maxHealth = GetActorProperty (0, APROP_SpawnHealth); // Get the actor's spawnHealth (Usually their "max" health)
- int healthP; // This will be used to store the current health percentage
- while (TRUE) {
- healthP = (ScaleValue (Clamp (GetActorProperty (0, APROP_Health), 0, maxHealth), 0, maxHealth, 0, 100) << 16) / 100; // Yay fixed point and bitshifts
- SetActorProperty (0, APROP_Speed, oldSpeed * healthP); // Scales the speed by the health percentage
- Delay (1); // Delay for one tic. This is necessary so the script doesn't get terminated for being a runaway script
- }
- }
Add Comment
Please, Sign In to add comment