Python1320

Untitled

Nov 16th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.20 KB | None | 0 0
  1. ENT.Type = "anim"
  2. ENT.Base = "base_anim"
  3.  
  4. if SERVER then
  5.  
  6.     function ENT:Initialize()
  7.      
  8.         self.Entity:SetModel( "models/props_gameplay/sign_gameplay01.mdl" )
  9.         self.Entity:PhysicsInit( SOLID_VPHYSICS )
  10.         self.Entity:SetMoveType( MOVETYPE_NONE )
  11.         self.Entity:SetSolid( SOLID_VPHYSICS )
  12.         self.Entity:SetCollisionGroup( COLLISION_GROUP_WORLD )
  13.         self.Entity:DrawShadow( true )
  14.         if SERVER then self:SetUseType(SIMPLE_USE) end
  15.        
  16.         local phys = self:GetPhysicsObject()
  17.         if (phys:IsValid()) then
  18.             phys:Wake()
  19.             //phys:EnableMotion(false)
  20.         end
  21.     end
  22.     local function SignCon( player, command, a )
  23.         local ent = Entity(tonumber(a[1]))
  24.         if player != ent.dt.Owner then return end
  25.         ent.dt.Line1 = tostring(a[2])
  26.         ent.dt.Line2 = tostring(a[3])
  27.         ent.dt.LineCol = Vector(tonumber(a[4]), tonumber(a[5]), tonumber(a[6]))
  28.         ent.dt.BackCol = Vector(tonumber(a[7]), tonumber(a[8]), tonumber(a[9]))
  29.         ent.dt.Spin = tonumber(a[10])
  30.     end
  31.     concommand.Add( "UpdateSign", SignCon )
  32.    
  33. end
  34.  
  35. function ENT:SetupDataTables()
  36.  
  37.     self:DTVar( "String", 0, "Line1" );
  38.     self:DTVar( "String", 1, "Line2" );
  39.     self:DTVar( "Vector", 0, "LineCol" );
  40.     self:DTVar( "Vector", 1, "BackCol" );
  41.     self:DTVar( "Angle", 0, "BeginAngle" );
  42.     self:DTVar( "Int", 0, "Spin" );
  43.     self:DTVar( "Entity", 0, "Owner" );
  44.  
  45. end
  46.  
  47. function ENT:Setup( owner )
  48.     if owner:IsPlayer() == false then return end
  49.     self.dt.Owner = owner
  50.    
  51.     local ply = owner
  52.     local trace = ply:GetEyeTrace()
  53.     local ang = trace.HitNormal:Angle()
  54.    
  55.     self.dt.BeginAngle = ang
  56.     self.dt.LineCol = Vector(255,255,255)
  57.     self.dt.Line1 = "Test 1"
  58.     self.dt.Line2 = "Test 2"
  59.    
  60.     print(ang, type(ang), self.dt.BeginAngle)
  61.    
  62.     self:SetPos( trace.HitPos )
  63.     self:SetAngles( ang )
  64. end
  65.  
  66. function ENT:Think()
  67.     local ang = self.dt.BeginAngle
  68.     ang:RotateAroundAxis( ang:Forward(), self.dt.Spin )
  69.     self:SetAngles(ang)
  70.    
  71.     self:NextThink(CurTime())
  72.     return true
  73. end
  74.  
  75. function ENT:AcceptInput( t, activator )
  76.     if t~="Use" then return end
  77.     local owner=self.dt and IsValid(self.dt.Owner) and self.dt.Owner or self.CPPIGetOwner and IsValid(self:CPPIGetOwner()) and self:CPPIGetOwner()
  78.     if IsValid(owner) then
  79.         if owner~=activator then
  80.             return
  81.         end
  82.     end
  83.     activator:SendLua("Entity("..self:EntIndex().."):ClientUse()")
  84. end
  85.    
  86. if CLIENT then
  87.    
  88.     ENT.Menu = nil
  89.    
  90.     local fontdata = {
  91.     font = "coolvetica",
  92.     size = 100,
  93.     weight = 500,
  94.     antialias = true
  95.     }
  96.     surface.CreateFont( "SignNormal", fontdata )
  97.    
  98.     function ENT:UpdateServer( t1, t2, lcol, bcol, spin )
  99.         print(t1, t2, lcol, bcol, spin)
  100.         LocalPlayer():ConCommand("UpdateSign "..self:EntIndex().." "..t1.." "..t2.." "..lcol.x.." "..lcol.y.." "..lcol.z.." "..bcol.x.." "..bcol.y.." "..bcol.z.." "..spin)
  101.     end
  102.    
  103.     function ENT:ClientUse()
  104.         self.Menu = vgui.Create("DFrame")
  105.         self.Menu:SetSize(350, 200)
  106.         self.Menu:SetPos(ScrW()/2 - 175, ScrH()/2)
  107.         self.Menu:SetTitle("Edit Sign")
  108.         self.Menu:ShowCloseButton(false)
  109.         self.Menu:MakePopup()
  110.          
  111.         local Close = vgui.Create("DButton", self.Menu)
  112.         Close:SetText( "Close" )
  113.         Close:SetPos( self.Menu:GetWide() - 50 , 5 )
  114.         Close:SetSize( 40, 15 )
  115.        
  116.         local Rotate = vgui.Create( "DNumSlider", self.Menu )
  117.         Rotate:SetPos( 10,25 )
  118.         Rotate:SetWide( 360 )
  119.         Rotate:SetText( "Sign Rotation" )
  120.         Rotate:SetMin( 0 )
  121.         Rotate:SetMax( 360 )
  122.         Rotate:SetDecimals( 0 )
  123.         Rotate:SetValue(self.dt.Spin)
  124.         Rotate.OnValueChanged = function(s, val)
  125.             self.dt.Spin = val
  126.         end
  127.        
  128.         local LineColLabel = vgui.Create("DLabel", self.Menu)
  129.         LineColLabel:SetPos(10,60) // Position
  130.         LineColLabel:SetColor(Color(255,255,255,150)) // Color
  131.         LineColLabel:SetFont("DermaDefault")
  132.         LineColLabel:SetText("Set Line Color:") // Text
  133.         LineColLabel:SizeToContents()
  134.        
  135.         local LineCol = vgui.Create( "DColorMixer", self.Menu )
  136.         LineCol:SetPos( 10, 80 )
  137.         LineCol:SetSize( 159, 75 )
  138.         if LineCol.SetPalette != nil then
  139.             LineCol:SetPalette(false)
  140.         end
  141.         LineCol:SetAlphaBar(false)
  142.         LineCol.ValueChanged = function(s, col)
  143.             self.dt.LineCol = Vector(col.r, col.g, col.b)
  144.         end
  145.        
  146.         local dtlc = self.dt.LineCol
  147.        
  148.         LineCol:SetColor(Color(dtlc.x,dtlc.y,dtlc.z))
  149.                
  150.         local BackColLabel = vgui.Create("DLabel", self.Menu)
  151.         BackColLabel:SetPos(180,60) // Position
  152.         BackColLabel:SetColor(Color(255,255,255,150)) // Color
  153.         BackColLabel:SetFont("DermaDefault")
  154.         BackColLabel:SetText("Set Back Color:") // Text
  155.         BackColLabel:SizeToContents()
  156.        
  157.         local BackCol = vgui.Create( "DColorMixer", self.Menu )
  158.         BackCol:SetPos( 180, 80 )
  159.         BackCol:SetSize( 159, 75 )
  160.         if BackCol.SetPalette != nil then
  161.             BackCol:SetPalette(false)
  162.         end
  163.         BackCol:SetAlphaBar(false)
  164.         BackCol:SetAlphaBar(false)
  165.         BackCol.ValueChanged = function(s, col)
  166.             self.dt.BackCol = Vector(col.r, col.g, col.b)
  167.         end
  168.        
  169.         local dtlc2 = self.dt.BackCol
  170.        
  171.         BackCol:SetColor(Color(dtlc2.x,dtlc2.y,dtlc2.z))
  172.        
  173.         local LineTextLabel = vgui.Create("DLabel", self.Menu)
  174.         LineTextLabel:SetPos(10,169) // Position
  175.         LineTextLabel:SetColor(Color(255,255,255,150)) // Color
  176.         LineTextLabel:SetFont("DermaDefault")
  177.         LineTextLabel:SetText("Text 1") // Text
  178.         LineTextLabel:SizeToContents()
  179.        
  180.         local LineText = vgui.Create("DTextEntry", self.Menu)
  181.         LineText:SetPos( 50, 165 )
  182.         LineText:SetSize( 120, 24 )
  183.         LineText:SetText(self.dt.Line1)
  184.         LineText.OnChange = function(s)
  185.             local val = s:GetValue()   
  186.             self.dt.Line1 = val
  187.         end
  188.         LineText.AllowInput = function( s, val )
  189.             if string.len(s:GetValue()) >= 20 then return true end
  190.         end
  191.        
  192.         local Line2TextLabel = vgui.Create("DLabel", self.Menu)
  193.         Line2TextLabel:SetPos(180,169) // Position
  194.         Line2TextLabel:SetColor(Color(255,255,255,150)) // Color
  195.         Line2TextLabel:SetFont("DermaDefault")
  196.         Line2TextLabel:SetText("Text 2") // Text
  197.         Line2TextLabel:SizeToContents()
  198.        
  199.         local Line2Text = vgui.Create("DTextEntry", self.Menu)
  200.         Line2Text:SetPos( 220, 165 )
  201.         Line2Text:SetSize( 120, 24 )
  202.         Line2Text:SetText(self.dt.Line2)
  203.         Line2Text.OnChange = function(s)
  204.             local val = s:GetValue()   
  205.             self.dt.Line2 = val
  206.         end
  207.         Line2Text.AllowInput = function( s, val )
  208.             if string.len(s:GetValue()) >= 20 then return true end
  209.         end
  210.        
  211.         Close.DoClick = function()
  212.             self.Menu:Close()
  213.             self.Menu = nil
  214.             self:UpdateServer( self.dt.Line1, self.dt.Line2, self.dt.LineCol, self.dt.BackCol, self.dt.Spin )
  215.         end
  216.    
  217.     end
  218.    
  219.     function ENT:Draw()
  220.         local scrx, scry = (self:GetPos() - Vector( 64, 0, 12 )):ToScreen().x, (self:GetPos() - Vector( 64, 0, 12 )):ToScreen().y
  221.         local scrx2, scry2 = (self:GetPos() + Vector( 64, 0, 12 )):ToScreen().x, (self:GetPos() + Vector( 64, 0, 12 )):ToScreen().y
  222.    
  223.         self:DrawModel()
  224.        
  225.         local ang = self:GetAngles()
  226.         ang:RotateAroundAxis(ang:Right(), -90)
  227.         ang:RotateAroundAxis(ang:Up(), 90)
  228.        
  229.         local LineCol = Color(self.dt.LineCol.x, self.dt.LineCol.y, self.dt.LineCol.z, 255)
  230.         local BackCol = Color(self.dt.BackCol.x, self.dt.BackCol.y, self.dt.BackCol.z, 255)
  231.        
  232.         cam.Start3D2D( self:GetPos() + self:GetForward() * 2, ang, 0.1 )
  233.             draw.RoundedBox( 0, -330, -100, 660, 200, BackCol )
  234.             draw.DrawText(self.dt.Line1, "SignNormal", 0, -100, LineCol, TEXT_ALIGN_CENTER)
  235.             draw.DrawText(self.dt.Line2, "SignNormal", 0, 0, LineCol, TEXT_ALIGN_CENTER)
  236.         cam.End3D2D()
  237.     end
  238.  
  239. end
Advertisement
Add Comment
Please, Sign In to add comment