Advertisement
C0BRA

Untitled

Dec 20th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.51 KB | None | 0 0
  1. function ENT:GetWatts(watt)
  2.     local totalwatt = 0
  3.    
  4.     for k,src in pairs(self.PowerSources) do
  5.         totalwatt = totalwatt + src:MaxWatt() /* returns the bandwidth, or the avaibible power if less than bandwidth */
  6.     end
  7.    
  8.     if totalwatt < watt then
  9.         return false
  10.     end
  11.    
  12.     local ret = 0
  13.    
  14.     for k,src in pairs(self.PowerSources) do
  15.         local max = src:MaxWatt()
  16.         local percent = max / totalwatt
  17.        
  18.         local watt_used = watt * percent
  19.        
  20.         self:TakeWatt(watt_used)
  21.         ret = ret + watt_used
  22.     end
  23.    
  24.     return true
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement