sshikamaru

Factorio - Gestion destruction fluide

Dec 7th, 2025
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. -- Paramètres
  2. local chlore_min_pct = 50
  3. local chlore_max_pct = 95
  4. local hydrogene_min_pct = 50
  5. local hydrogene_max_pct = 95
  6. local hysteresis = 10
  7. local seuil = 90
  8.  
  9. -- Valeurs max réelles
  10. local chlore_max = 200000
  11. local hydrogene_max = 200000
  12.  
  13. -- Lecture des fluides
  14. local chlore = red['kr-chlorine'] or 0
  15. local hydrogene  = green['kr-hydrogen'] or 0
  16.  
  17. -- Pourcentages
  18. local chlore_pct = (chlore / chlore_max) * 100
  19. local hydrogene_pct = (hydrogene / hydrogene_max) * 100
  20.  
  21. -- Initialisation si nécessaire
  22. if a == nil then a = 2 end
  23. if b == nil then b = 2 end
  24.  
  25. -- --- Fluide1 (chlore)
  26. if chlore_pct > chlore_max_pct and hydrogene_pct < hydrogene_min_pct then
  27.     a = 1
  28. elseif a == 1 then
  29.     if chlore_pct < (chlore_max_pct - hysteresis) or hydrogene_pct > seuil then
  30.         a = 2
  31.     end
  32. end
  33.  
  34. -- --- Fluide2 (hydrogène)
  35. if hydrogene_pct > hydrogene_max_pct and chlore_pct < chlore_min_pct then
  36.     b = 1
  37. elseif b == 1 then
  38.     if hydrogene_pct < (hydrogene_max_pct - hysteresis) or chlore_pct > seuil then
  39.         b = 2
  40.     end
  41. end
  42.  
  43. -- --- Réactivation possible
  44. -- même si a ou b était actif avant, on peut les réactiver si conditions présentes
  45. if a == 2 and chlore_pct > chlore_max_pct and hydrogene_pct < hydrogene_min_pct then
  46.     a = 1
  47. end
  48. if b == 2 and hydrogene_pct > hydrogene_max_pct and chlore_pct < chlore_min_pct then
  49.     b = 1
  50. end
  51.  
  52. -- Sorties
  53. out['signal-A'] = a
  54. out['signal-B'] = b
Advertisement
Add Comment
Please, Sign In to add comment