Advertisement
Guest User

printColorAll.lua

a guest
Jul 17th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. util.AddNetworkString("wire_expression2_printColorAll")
  2. local print_delay = CreateConVar( "wire_expression2_printColorAll_delay", 0.1, {FCVAR_ARCHIVE} )
  3.  
  4. local printColor_types = {
  5.     number = tostring,
  6.     string = tostring,
  7.     Vector = function(v) return Color(v[1],v[2],v[3]) end,
  8.     table = function(tbl)
  9.         for i,v in pairs(tbl) do
  10.             if type(i) ~= "number" then return "" end
  11.             if type(v) ~= "number" then return "" end
  12.             if i < 1 or i > 4 then return "" end
  13.         end
  14.         return Color(tbl[1] or 0, tbl[2] or 0,tbl[3] or 0,tbl[4])
  15.     end,
  16.     Player = function(e) return IsValid(e) and e:IsPlayer() and e or "" end,
  17. }
  18.  
  19. local function printColorAllArray(chip, ply, arr)
  20.     if (not IsValid(ply)) then return; end
  21.  
  22.     local send_array = {}
  23.  
  24.     for i,tp in ipairs_map(arr,type) do
  25.         if printColor_types[tp] then
  26.             send_array[i] = printColor_types[tp](arr[i])
  27.         else
  28.             send_array[i] = ""
  29.         end
  30.     end
  31.  
  32.     send_array.chip = chip
  33.     send_array.sender = ply
  34.     --//datastream12.StreamToClients(player.GetAll( ), "wire_expression2_printColorAll", send_array)
  35.    
  36.     net.Start("wire_expression2_printColorAll")
  37.         net.WriteEntity(chip)
  38.         net.WriteTable(send_array)
  39.     net.Broadcast()
  40. end
  41. __e2setcost(5)
  42. e2function void printColorAll(array arr)
  43.     local ply = self.player
  44.     local lastprint = ply.lastPrint or 0
  45.     if lastprint < CurTime( ) then
  46.         ply.lastPrint = CurTime( ) + print_delay:GetInt()
  47.         printColorAllArray(self.entity, ply, arr)
  48.     end
  49. end
  50. __e2setcost(5)
  51. e2function void printColorAll(...)
  52.     local ply = self.player
  53.     local lastprint = ply.lastPrint or 0
  54.     if lastprint < CurTime( ) then
  55.         ply.lastPrint = CurTime( ) + print_delay:GetInt()
  56.         local arr = { ... }
  57.         printColorAllArray(self.entity, ply, arr)
  58.     end
  59. end
  60.  
  61. __e2setcost(2)
  62. e2function number printColorAllReady()
  63.     local ply = self.player
  64.     if ply.lastPrint < CurTime( ) then
  65.         return 1
  66.     else
  67.         return 0
  68.     end
  69. end
  70.  
  71. e2function number printColorAllDelay()
  72.     return print_delay:GetInt()
  73. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement