Python1320

Untitled

Oct 24th, 2010
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. --[[
  2.     SHARED:
  3.         DEFINED:
  4.             ITEM:State = "both/weapon/entity"
  5.    
  6.         MISC:
  7.             ITEM:HOOK:Name(...)
  8.        
  9.         FUNCTIONS:
  10.             ITEM:GetTrace()
  11.             ITEM:GetInventoryInfo()
  12.            
  13.     CLIENT:
  14.         MENU:
  15.             ITEM:AddSimpleOption(name, function, ...)
  16.             ITEM:AddEquipOption()
  17.             ITEM:AddBackpackOption()
  18.             ITEM:AddDropOption()
  19.             ITEM:AddSpacer()
  20.             ITEM:AddCustomOption(function)
  21.             ITEM:CallOption(name, function, ...)
  22.             ITEM:MakeMenu()
  23.             ITEM:GetMenu()
  24.            
  25.         DATA:
  26.             ITEM:CallOnServer(...)
  27.             ITEM:ReceiveUserMessage(...)
  28.            
  29.         HOOKS:
  30.             ITEM:PreDraw()
  31.             ITEM:PostDraw()
  32.            
  33.     SERVER:
  34.         MENU:
  35.             ITEM:AllowOption(name, function)
  36.            
  37.         DATA:
  38.             ITEM:ReceiveFromClient(ply, ...)
  39.             ITEM:SendUserMessage(ply, ...)
  40.    
  41.         HOOKS:
  42.             ITEM:PreBackpack(ply)
  43.             ITEM:OnEquip(ply)
  44.             ITEM:PreDrop(ply)
  45.            
  46.         FUNCTIONS:
  47.             ITEM:SetSate(state)
  48.             ITEM:RemoveActiveItem()
  49.    
  50. ]]
  51.  
  52. items.StartItem("test_gun", nil, "weapon_base", "base_anim") -- Not sure how I should do this (if it's a neat way)
  53.  
  54.     -- The world model is used by entity and weapon
  55.     ITEM.WorldModel = "models/weapons/w_pistol.mdl"
  56.     ITEM.ViewModel = "models/weapons/v_pistol.mdl"
  57.     ITEM.PrintName = "Test Gun!!"
  58.    
  59.     -- "both" means that the item is a weapon when equiped, and an entity when it's on ground
  60.     ITEM.State = "both"
  61.  
  62.     ITEM.Inventory = {
  63.         name = "Test gun",
  64.         info = [[
  65.             Used to test things
  66.         ]],
  67.  
  68.     }
  69.  
  70.     function ITEM:Initialize()
  71.         -- Don't really need this, it's just for constant reloading (I'm runstringing this) so the menu doesn't stack up
  72.         self.DermaMenuOptions = {}
  73.  
  74.         if CLIENT then
  75.            
  76.             self:AddBackpackOption()
  77.             self:AddEquipOption()
  78.            
  79.             self:AddSpacer()
  80.            
  81.             -- First argument is the label in the menu, second is the function name we're going to call when it's selected
  82.             self:AddSimpleOption("Explode", "Explode")
  83.            
  84.             -- This one's for adding custom vgui elements to the menu
  85.             -- We're adding a slider here
  86.             self:AddCustomOption(function(menu)
  87.                 local slider = vgui.Create("DSlider")
  88.                 slider:SetTrapInside(true)
  89.                 slider:SetImage("vgui/slider")
  90.                 slider:SetLockY(0.5)
  91.                 slider:SetSize(100,13)
  92.                 slider:SetSlideX(1)
  93.                 Derma_Hook(slider,"Paint","Paint","NumSlider")
  94.                 slider.TranslateValues=function(p,x,y)
  95.                     self:CallOption("Spawn Random", "MakeEnt", table.Random({"npc_manhack", "npc_rollermine"})) -- You can do anything here, but I want to spam PrimaryAttack for fun.
  96.                     return x,y;
  97.                 end
  98.                 menu:AddPanel(slider)
  99.             end)
  100.  
  101.             self:AddSimpleOption("Fire Primary", "PrimaryAttack")
  102.             self:AddSimpleOption("Fire Secondary", "SecondaryAttack")
  103.         else
  104.             self:AllowOption("Explode", "Explode")
  105.             self:AllowOption("Fire Secondary", "SecondaryAttack")
  106.             self:AllowOption("Fire Primary", "PrimaryAttack")
  107.             self:AllowOption("Spawn Random", "MakeEnt")
  108.  
  109.             -- Only do this if it's not a weapon
  110.             if not self:IsWeapon() then
  111.                 self:SetModel(  self.WorldModel )
  112.                 self:PhysicsInit( SOLID_VPHYSICS )
  113.                 self:SetMoveType( MOVETYPE_VPHYSICS )
  114.                 self:SetSolid( SOLID_VPHYSICS )
  115.                 self:PhysWake()
  116.             end
  117.         end
  118.  
  119.     end
  120.  
  121.     local sound = Sound( "Metal.SawbladeStick" )
  122.  
  123.     if SERVER then
  124.    
  125.        
  126.         function ITEM.HOOK:PlayerSay(player, text)
  127.             self:SendUserMessage(nil, "text", player:Nick() .. ": " .. text)
  128.         end
  129.  
  130.         function ITEM:MakeEnt(class)
  131.             self.Owner:MuzzleFlash()
  132.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  133.  
  134.             local tr = self:GetTrace() -- This returns GetEyeTrace if it's held, and a custom trace if it's not held
  135.  
  136.             local ent = ents.Create( class )
  137.             ent:SetPos( tr.HitPos )
  138.             ent:SetAngles( tr.HitNormal:Angle() )
  139.             ent:Spawn()
  140.             ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
  141.  
  142.             timer.Simple(1, function() ent:Remove() end)
  143.         end
  144.  
  145.         function ITEM:PrimaryAttack()
  146.             self:MakeEnt("npc_manhack")
  147.         end
  148.  
  149.         function ITEM:SecondaryAttack()
  150.             self:MakeEnt("npc_rollermine")
  151.         end
  152.  
  153.         function ITEM:Explode()
  154.             local data = EffectData()
  155.             data:SetOrigin(self:GetPos())
  156.             util.Effect("explosion", data)
  157.             self:Remove()
  158.         end
  159.  
  160.         function ITEM:OnTakeDamage(info)
  161.             info:SetDamageForce(info:GetDamageForce()*1000)
  162.             self:TakePhysicsDamage(info)
  163.             local ply = info:GetAttacker()
  164.             if not ply:IsPlayer() then return end
  165.             self:SendUserMessage(nil, "touch", ply)
  166.         end
  167.  
  168.     else
  169.  
  170.         function ITEM:PrimaryAttack()
  171.             self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  172.             self.Owner:MuzzleFlash()
  173.             self.Owner:SetAnimation( PLAYER_ATTACK1 )
  174.         end
  175.  
  176.         ITEM.SecondaryAttack = ITEM.PrimaryAttack
  177.  
  178.         function ITEM:ReceiveUserMessage(key, value)
  179.             if key == "text" then self.text = value end
  180.             if key == "touch" then chat.AddText(HSVToColor(math.random(360), 1,1), "CAUSE EVERYTIME WE TOUCH "..value:Nick().." GETS THIS FEELING") end
  181.         end
  182.        
  183.         function ITEM.HOOK:HUDPaint()
  184.             if not self.text then return end
  185.             local position = self:GetPos():ToScreen()
  186.             draw.DrawText(self.text, "Default", position.x, position.y, color_white, TEXT_ALIGN_LEFT)
  187.         end
  188.  
  189.         function ITEM:DrawInBackPack(model, position, angles)
  190.             model:SetPos(position + angles:Right() * 7 + angles:Forward() * -4)
  191.             angles:RotateAroundAxis(angles:Right(), 50)
  192.             model:SetAngles(angles)
  193.             model:DrawModel()
  194.         end
  195.  
  196.     end
  197.  
  198. items.EndItem()
  199.  
  200. if SERVER then
  201.  
  202.     items.EasyCreate("test_gun", nero.GetPlayer("caps"))
  203.  
  204. end
Advertisement
Add Comment
Please, Sign In to add comment