Python1320

Untitled

Jul 19th, 2010
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. items.StartWeapon("guntest")
  2.  
  3.     ITEM.Base = "weapon_base"
  4.      
  5.     function ITEM:Initialize()
  6.         self.DermaMenuOptions = {} -- Don't really need this, it's just for constant reloading so the menu doesn't stack
  7.        
  8.         if SERVER then
  9.             self:AllowOption("Explode", "Explode")
  10.             self:AllowOption("Fire Secondary", "SecondaryAttack")
  11.             self:AllowOption("Fire Primary", "PrimaryAttack")
  12.         else               
  13.             self:AddSimpleOption("Explode", "Explode") -- First argument is the label in the menu, second is the function name
  14.            
  15.             self:AddSpacer()
  16.            
  17.             self:AddCustomOption(function(menu) -- This one's for adding custom vgui elements to the menu
  18.                 local slider = vgui.Create("DSlider");
  19.                 slider:SetTrapInside(true);
  20.                 slider:SetImage("vgui/slider");
  21.                 slider:SetLockY(0.5);
  22.                 slider:SetSize(100,13);
  23.                 slider:SetSlideX(1);
  24.                 Derma_Hook(slider,"Paint","Paint","NumSlider");
  25.                 slider.TranslateValues=function(p,x,y)
  26.                     self:CallOption("Fire Primary", "PrimaryAttack")
  27.                     return x,y;
  28.                 end
  29.                 menu:AddPanel(slider)
  30.             end)
  31.            
  32.             self:AddSimpleOption("Fire Primary", "PrimaryAttack")
  33.             self:AddSimpleOption("Fire Secondary", "SecondaryAttack")
  34.         end
  35.        
  36.     end
  37.    
  38.     local sound = Sound( "Metal.SawbladeStick" )
  39.    
  40.     function ITEM:MakeEnt(class)
  41.         local tr = self:GetTrace()
  42.      
  43.         self:EmitSound( sound )
  44.      
  45.         local ent = ents.Create( class )
  46.         ent:SetPos( tr.HitPos )
  47.         ent:SetAngles( tr.HitNormal:Angle() )
  48.         ent:Spawn()
  49.  
  50.         timer.Simple(1, function() ent:Remove() end)
  51.     end
  52.    
  53.     if SERVER then
  54.    
  55.         function ITEM.HOOK:PlayerSay(player, text) -- I know there's a clientside chat hook. I'm only doing this to show UserMessages
  56.             self:SendUserMessage("text", player:Nick() .. ": " .. text)
  57.         end
  58.        
  59.     else
  60.    
  61.         function ITEM:ReceiveUserMessage(key, value)
  62.             self[key] = value
  63.         end
  64.        
  65.         function ITEM.HOOK:HUDPaint()
  66.             if not self.text then return end
  67.             local position = self:GetPos():ToScreen()
  68.             draw.DrawText(self.text, "Default", position.x, position.y, color_white, TEXT_ALIGN_LEFT)
  69.         end
  70.        
  71.     end
  72.    
  73.     function ITEM:PrimaryAttack()
  74.         self:MakeEnt("npc_manhack")
  75.     end
  76.      
  77.     function ITEM:SecondaryAttack()
  78.         self:MakeEnt("npc_rollermine")
  79.     end
  80.    
  81.     function ITEM:Explode()
  82.         local data = EffectData()
  83.         data:SetOrigin(self:GetPos())
  84.         util.Effect("explosion", data)
  85.         self:Remove()
  86.     end
  87.    
  88. items.EndWeapon()
Add Comment
Please, Sign In to add comment