Want more features on Pastebin? Sign Up, it's FREE!
Guest

cl_nwvars.lua

By: KatNotDinner on Apr 29th, 2012  |  syntax: Lua  |  size: 13.31 KB  |  views: 61  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*PLUGIN.Name = "Client-side NWVars"
  2. PLUGIN.Description = "Client-side managment of nwvars"
  3. PLUGIN.Author = "KatNotDinner"*/
  4.  
  5. if SERVER then
  6.         AddCSLuaFile()
  7.         return
  8. end
  9.  
  10. local meta1 = FindMetaTable( "Entity" )
  11. local meta2 = FindMetaTable( "Player" )
  12. local bools = {true, false}
  13.  
  14. /*function meta2:SetNWString( str, val, b )
  15.         if !self.NWvars then self.NWvars = {} end
  16.         if !self.NWvars.String[ str ] then self.NWvars.String[ str ] = {} end
  17.         self.NWvars[ str ] = val
  18.     if b then
  19.             net.Start( "StringCL" )
  20.                 net.WriteEntity( self )
  21.                     net.WriteString( str )
  22.                     net.WriteString( val )
  23.             net.SendToServer()
  24.         end
  25. end
  26.  
  27. function meta2:SetNWEntity( str, ent, b )
  28.         if !self.NWvars then self.NWvars = {} end
  29.         if !self.NWvars.Entity[ str ] then self.NWvars.Entity[ str ] = {} end
  30.         self.NWvars.Entity[ str ] = ent
  31.         if b then
  32.             net.Start( "EntityCL" )
  33.                 net.WriteEntity( self )
  34.                     net.WriteString( str )
  35.                     net.WriteEntity( ent )
  36.             net.SendToServer()
  37.         end
  38. end
  39.  
  40. function meta2:SetNWBool( str, bool, b )
  41.         if !self.NWvars then self.NWvars = {} end
  42.         if !self.NWvars.Bool[ str ] then self.NWvars.Bool[ str ] = {} end
  43.         self.NWvars.Bool[ str ] = bool
  44.         if b then
  45.             net.Start( "BoolCL" )
  46.                 net.WriteEntity( self )
  47.                     net.WriteString( str )
  48.                         if bool then   
  49.                                 net.WriteInt( 1 )
  50.                         else
  51.                                 net.WriteInt( 2 )
  52.                         end
  53.             net.SendToServer()
  54.         end
  55. end
  56.  
  57. function meta2:SetNWFloat( str, fl, b )
  58.         if !self.NWvars then self.NWvars = {} end
  59.         if !self.NWvars.Float[ str ] then self.NWvars.Float[ str ] = {} end
  60.         self.NWvars.Float[ str ] = fl
  61.         if b then
  62.             net.Start( "FloatCL" )
  63.                 net.WriteEntity( self )
  64.                     net.WriteString( str )
  65.                     net.WriteFloat( fl )
  66.             net.SendToServer()
  67.         end
  68. end
  69.  
  70. function meta2:SetNWInt( str, int, b )
  71.         if !self.NWvars then self.NWvars = {} end
  72.         if !self.NWvars.Int[ str ] then self.NWvars.Int[ str ] = {} end
  73.         self.NWvars.Int[ str ] = int
  74.         if b then
  75.             net.Start( "IntCL" )
  76.                 net.WriteEntity( self )
  77.                     net.WriteString( str )
  78.                     net.WriteInt( fl )
  79.             net.SendToServer()
  80.         end
  81. end
  82.  
  83. function meta2:SetNWAngle( str, ang, b )
  84.         if !self.NWvars then self.NWvars = {} end
  85.         if !self.NWvars.Angle[ str ] then self.NWvars.Angle[ str ] = {} end
  86.         self.NWvars.Angle[ str ] = ang
  87.         if b then
  88.             net.Start( "AngleCL" )
  89.                 net.WriteEntity( self )
  90.                     net.WriteString( str )
  91.                     net.WriteAngle( ang )
  92.             net.SendToServer()
  93.         end
  94. end
  95.  
  96. function meta2:SetNWVector( str, ang, b )
  97.         if !self.NWvars then self.NWvars = {} end
  98.         if !self.NWvars.Vector[ str ] then self.NWvars.Vector[ str ] = {} end
  99.         self.NWvars.Vector[ str ] = ang
  100.         if b then
  101.             net.Start( "VectorCL" )
  102.                 net.WriteEntity( self )
  103.                     net.WriteString( str )
  104.                     net.WriteVector( ang )
  105.             net.SendToServer()
  106.         end
  107. end
  108.  
  109. function meta2:SetNetworkedVar( str, var, b )
  110.     if type(var) == "string" then
  111.             self:SetNWString( str, var, b )
  112.                 return
  113.         elseif type(var) == "number" then
  114.             if tostring(var):find( "." ) then
  115.                     self:SetNWFloat( str, var, b )
  116.                 else
  117.                     self:SetNWInt( str, var, b )
  118.                 end
  119.         elseif type(var) == "bool" then
  120.             self:SetNWBool( str, var, b )
  121.         elseif var.p and var.y and var.r then
  122.             self:SetNWAngle( str, var, b )
  123.         elseif var.x and var.y and var.z then
  124.             self:SetNWVector( str, var, b )
  125.         elseif IsValid(var) then
  126.             self:SetNWEntity( str, var, b )
  127.         end
  128. end*/
  129.  
  130. function meta1:SetNWString( str, val, b )
  131.         self.NWvars = self.NWvars or {}
  132.         self.NWvars.String = self.NWvars.String or {}
  133.         --self.NWvars.String[ str ] = self.NWvars.String[ str ] or {}
  134.         self.NWvars.String[ str ] = val
  135.     if b then
  136.             net.Start( "StringCL" )
  137.                 net.WriteEntity( self )
  138.                     net.WriteString( str )
  139.                     net.WriteString( val )
  140.             net.SendToServer()
  141.         end
  142. end
  143.  
  144. function meta1:SetNWEntity( str, ent, b )
  145.         self.NWvars = self.NWvars or {}
  146.         self.NWvars.Entity = self.NWvars.Entity or {}
  147.         --self.NWvars.Entity[ str ] = self.NWvars.Entity[ str ] or {}
  148.         self.NWvars.Entity[ str ] = ent
  149.         if b then
  150.             net.Start( "EntityCL" )
  151.                 net.WriteEntity( self )
  152.                     net.WriteString( str )
  153.                     net.WriteEntity( ent )
  154.             net.SendToServer()
  155.         end
  156. end
  157.  
  158. function meta1:SetNWBool( str, bool, b )
  159.         self.NWvars = self.NWvars or {}
  160.         self.NWvars.Bool = self.NWvars.Bool or {}
  161.         --self.NWvars.Bool[ str ] = self.NWvars.Bool[ str ] or {}
  162.         self.NWvars.Bool[ str ] = bool
  163.         if b then
  164.             net.Start( "BoolCL" )
  165.                 net.WriteEntity( self )
  166.                     net.WriteString( str )
  167.                         net.WriteBit( bool )
  168.             net.SendToServer()
  169.         end
  170. end
  171.  
  172. function meta1:SetNWFloat( str, fl, b )
  173.         self.NWvars = self.NWvars or {}
  174.         self.NWvars.Float = self.NWvars.Float or {}
  175.         --self.NWvars.Float[ str ] = self.NWvars.Float[ str ] or {}
  176.         self.NWvars.Float[ str ] = fl
  177.         if b then
  178.             net.Start( "FloatCL" )
  179.                 net.WriteEntity( self )
  180.                     net.WriteString( str )
  181.                     net.WriteFloat( fl )
  182.             net.SendToServer()
  183.         end
  184. end
  185.  
  186. function meta1:SetNWInt( str, int, b )
  187.         self.NWvars = self.NWvars or {}
  188.         self.NWvars.Int = self.NWvars.Int or {}
  189.         --self.NWvars.Int[ str ] = self.NWvars.Int[ str ] or {}
  190.         self.NWvars.Int[ str ] = int
  191.         if b then
  192.             net.Start( "IntCL" )
  193.                 net.WriteEntity( self )
  194.                     net.WriteString( str )
  195.                     net.WriteInt( fl, 32 )
  196.             net.SendToServer()
  197.         end
  198. end
  199.  
  200. function meta1:SetNWAngle( str, ang, b )
  201.         self.NWvars = self.NWvars or {}
  202.         self.NWvars.Angle = self.NWvars.Angle or {}
  203.         --self.NWvars.Angle[ str ] = self.NWvars.Angle[ str ] or {}
  204.         self.NWvars.Angle[ str ] = ang
  205.         if b then
  206.             net.Start( "AngleCL" )
  207.                 net.WriteEntity( self )
  208.                     net.WriteString( str )
  209.                     net.WriteAngle( ang )
  210.             net.SendToServer()
  211.         end
  212. end
  213.  
  214. function meta1:SetNWVector( str, ang, b )
  215.         self.NWvars = self.NWvars or {}
  216.         self.NWvars.Vector = self.NWvars.Vector or {}
  217.         --self.NWvars.Vector[ str ] = self.NWvars.Vector[ str ] or {}
  218.         self.NWvars.Vector[ str ] = vec
  219.         if b then
  220.             net.Start( "VectorCL" )
  221.                 net.WriteEntity( self )
  222.                     net.WriteString( str )
  223.                     net.WriteVector( ang )
  224.             net.SendToServer()
  225.         end
  226. end
  227.  
  228. function meta1:SetNetworkedVar( str, var, b )
  229.     if type(var) == "string" then
  230.             self:SetNWString( str, var, b )
  231.                 return
  232.         elseif type(var) == "number" then
  233.             if tostring(var):find( "." ) then
  234.                     self:SetNWFloat( str, var, b )
  235.                 else
  236.                     self:SetNWInt( str, var, b )
  237.                 end
  238.         elseif type(var) == "bool" then
  239.             self:SetNWBool( str, var, b )
  240.         elseif var.p and var.y and var.r then
  241.             self:SetNWAngle( str, var, b )
  242.         elseif var.x and var.y and var.z then
  243.             self:SetNWVector( str, var, b )
  244.         elseif IsValid(var) then
  245.             self:SetNWEntity( str, var, b )
  246.         end
  247. end
  248.  
  249. function meta1:GetNWBool( str )
  250.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  251.         if !self.NWvars.Bool then return end
  252.     if !self.NWvars.Bool[ str ] then return end
  253.         return self.NWvars.Bool[ str ]
  254. end
  255.  
  256. function meta1:GetNWString( str )
  257.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  258.         if !self.NWvars.String then return end
  259.     if !self.NWvars.String[ str ] then return end
  260.         return self.NWvars.String[ str ]
  261. end
  262.  
  263. function meta1:GetNWAngle( str )
  264.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  265.         if !self.NWvars.Angle then return end
  266.     if !self.NWvars.Angle[ str ] then return end
  267.         return self.NWvars.Angle[ str ]
  268. end
  269.  
  270. function meta1:GetNWVector( str )
  271.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  272.         if !self.NWvars.Vector then return end
  273.     if !self.NWvars.Vector[ str ] then return end
  274.         return self.NWvars.Vector[ str ]
  275. end
  276.  
  277. function meta1:GetNWFloat( str )
  278.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  279.         if !self.NWvars.Float then return end
  280.     if !self.NWvars.Float[ str ] then return end
  281.         return self.NWvars.Float[ str ]
  282. end
  283.  
  284. function meta1:GetNWInt( str )
  285.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  286.         if !self.NWvars.Int then return end
  287.     if !self.NWvars.Int[ str ] then return end
  288.         return self.NWvars.Int[ str ]
  289. end
  290.  
  291. function meta1:GetNWEntity( str )
  292.         if !self.NWvars then Error( "No NWVars for Entity "..self:EntIndex().."!" ) debug.Trace() return end
  293.         if !self.NWvars.Entity then return end
  294.     if !self.NWvars.Entity[ str ] then return end
  295.         return self.NWvars.Entity[ str ]
  296. end
  297.  
  298. function meta1:GetNetworkedVar( str )
  299.     if self.NWvars.Vector[ str ] then
  300.         return self.NWvars.Vector[ str ]
  301.         elseif self.NWvars.Entity[ str ] then
  302.             return self.NWvars.Entity[ str ]
  303.         elseif self.NWvars.String[ str ] then
  304.             return self.NWvars.String[ str ]
  305.         elseif self.NWvars.Float[ str ] then
  306.             return self.NWvars.Float
  307.         elseif self.NWvars.Angle[ str ] then
  308.             return self.NWvars.Angle[ str ]
  309.         elseif self.NWvars.Bool[ str ] then
  310.             return self.NWvars.Bool[ str ]
  311.         end
  312. end
  313. /*
  314. function meta2:GetNWBool( str )
  315.     if !self.NWvars.Bool[ str ] then return end
  316.         return self.NWvars.Bool[ str ]
  317. end
  318.  
  319. function meta2:GetNWString( str )
  320.     if !self.NWvars.String[ str ] then return end
  321.         return self.NWvars.String[ str ]
  322. end
  323.  
  324. function meta2:GetNWAngle( str )
  325.     if !self.NWvars.Angle[ str ] then return end
  326.         return self.NWvars.Angle[ str ]
  327. end
  328.  
  329. function meta2:GetNWVector( str )
  330.     if !self.NWvars.Vector[ str ] then return end
  331.         return self.NWvars.Vector[ str ]
  332. end
  333.  
  334. function meta2:GetNWFloat( str )
  335.     if !self.NWvars.Float[ str ] then return end
  336.         return self.NWvars.Float[ str ]
  337. end
  338.  
  339. function meta2:GetNWInt( str )
  340.     if !self.NWvars.Int[ str ] then return end
  341.         return self.NWvars.Int[ str ]
  342. end
  343.  
  344. function meta2:GetNWEntity( str )
  345.     if !self.NWvars.Entity[ str ] then return end
  346.         return self.NWvars.Entity[ str ]
  347. end
  348.  
  349. function meta2:GetNetworkedVar( str )
  350.     if self.NWvars.Vector[ str ] then
  351.         return self.NWvars.Vector[ str ]
  352.         elseif self.NWvars.Entity[ str ] then
  353.             return self.NWvars.Entity[ str ]
  354.         elseif self.NWvars.String[ str ] then
  355.             return self.NWvars.String[ str ]
  356.         elseif self.NWvars.Float[ str ] then
  357.             return self.NWvars.Float
  358.         elseif self.NWvars.Angle[ str ] then
  359.             return self.NWvars.Angle[ str ]
  360.         elseif self.NWvars.Bool[ str ] then
  361.             return self.NWvars.Bool[ str ]
  362.         end
  363. end*/
  364.  
  365. net.Receive( "Vector", function(m)
  366.         local ent = net.ReadEntity()
  367.         local str = net.ReadString()
  368.         ent.NWvars = ent.NWvars or {}
  369.         ent.NWvars.Vector = ent.NWvars.Vector or {}
  370.         ent.NWvars.Vector[ str ] = ent.NWvars.Vector[ str ] or {}
  371.         ent.NWvars.Vector[ str ] = net.ReadVector()
  372. end)
  373.  
  374. net.Receive( "Angle", function(m)
  375.         local ent = net.ReadEntity()
  376.         local str = net.ReadString()
  377.         ent.NWvars = ent.NWvars or {}
  378.         ent.NWvars.Angle = ent.NWvars.Angle or {}
  379.         ent.NWvars.Angle[ str ] = ent.NWvars.Angle[ str ] or {}
  380.         ent.NWvars.Angle[ str ] = net.ReadAngle()
  381. end)
  382.  
  383. net.Receive( "Float", function(m)
  384.         local ent = net.ReadEntity()
  385.         local str = net.ReadString()
  386.         ent.NWvars = ent.NWvars or {}
  387.         ent.NWvars.Float = ent.NWvars.Float or {}
  388.         ent.NWvars.Float[ str ] = ent.NWvars.Float[ str ] or {}
  389.         ent.NWvars.Float[ str ] = net.ReadFloat()
  390. end)
  391.  
  392. net.Receive( "Int", function(m)
  393.         local ent = net.ReadEntity()
  394.         local str = net.ReadString()
  395.         local int = net.ReadInt( 32 )
  396.         ent.NWvars = ent.NWvars or {}
  397.         ent.NWvars.Int = ent.NWvars.Int or {}
  398.         ent.NWvars.Int[ str ] = ent.NWvars.Int[ str ] or {}
  399.         ent.NWvars.Int[ str ] = int
  400. end)
  401.  
  402. net.Receive( "Bool", function(m)
  403.         local ent = net.ReadEntity()
  404.         local str = net.ReadString()
  405.         local var = net.ReadBit()
  406.         ent.NWvars = ent.NWvars or {}
  407.         ent.NWvars.Bool = ent.NWvars.Bool or {}
  408.         ent.NWvars.Bool[ str ] = ent.NWvars.Bool[ str ] or {}
  409.         ent.NWvars.Bool[ str ] = var
  410. end)
  411.  
  412. net.Receive( "Entity", function(m)
  413.         local ent = net.ReadEntity()
  414.         local str = net.ReadString()
  415.         local ent2 = net.ReadEntity()
  416.         ent.NWvars = ent.NWvars or {}
  417.         ent.NWvars.Entity = ent.NWvars.Entity or {}
  418.         ent.NWvars.Entity[ str ] = ent.NWvars.String[ str ] or {}
  419.         ent.NWvars.Entity[ str ] = ent2
  420. end)
  421.  
  422. net.Receive( "String", function(m)
  423.         local ent = net.ReadEntity()
  424.         local str = net.ReadString()
  425.         local str2 = net.ReadString()
  426.         ent.NWvars = ent.NWvars or {}
  427.         ent.NWvars.String = ent.NWvars.String or {}
  428.         ent.NWvars.String[ str ] = ent.NWvars.String[ str ] or {}
  429.         ent.NWvars.String[ str ] = str2
  430. end)
  431.  
  432. net.Receive( "NWVars", function(um)
  433. local num = net.ReadEntity()
  434. local str = net.ReadTable()
  435. num.NWvars = num.NWvars or {}
  436. num.NWvars = str
  437. end)
  438.  
  439. meta1.SetNWVar = meta1.SetNetworkedVar -- making sure that I override ALL of the nwvar functions
  440. meta1.SetNetworkedInt = meta1.SetNWInt
  441. meta1.SetNetworkedFloat = meta1.SetNWFloat
  442. meta1.SetNetworkedEntity = meta1.SetNWEntity
  443. meta1.SetNetworkedString = meta1.SetNWString
  444. meta1.SetNetworkedBool = meta1.SetNWBool
  445. meta1.SetNetworkedAngle = meta1.SetNWAngle
  446. meta1.SetNetworkedVector = meta1.SetNWVector
  447. /*
  448. _R.Player.SetNWVar = meta2.SetNetworkedVar -- making sure that I override ALL of the nwvar functions
  449. _R.Player.SetNetworkedInt = meta2.SetNWInt
  450. _R.Player.SetNetworkedFloat = meta2.SetNWFloat
  451. _R.Player.SetNetworkedEntity = meta2.SetNWEntity
  452. _R.Player.SetNetworkedString = meta2.SetNWString
  453. _R.Player.SetNetworkedBool = meta2.SetNWBool
  454. _R.Player.SetNetworkedAngle = meta2.SetNWAngle
  455. _R.Player.SetNetworkedVector = meta2.SetNWVector*/
clone this paste RAW Paste Data