Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- SHARED:
- DEFINED:
- ITEM:State = "both/weapon/entity"
- MISC:
- ITEM:HOOK:Name(...)
- FUNCTIONS:
- ITEM:GetTrace()
- ITEM:GetInventoryInfo()
- CLIENT:
- MENU:
- ITEM:AddSimpleOption(name, function, ...)
- ITEM:AddEquipOption()
- ITEM:AddBackpackOption()
- ITEM:AddDropOption()
- ITEM:AddSpacer()
- ITEM:AddCustomOption(function)
- ITEM:CallOption(name, function, ...)
- ITEM:MakeMenu()
- ITEM:GetMenu()
- DATA:
- ITEM:CallOnServer(...)
- ITEM:ReceiveUserMessage(...)
- HOOKS:
- ITEM:PreDraw()
- ITEM:PostDraw()
- SERVER:
- MENU:
- ITEM:AllowOption(name, function)
- DATA:
- ITEM:ReceiveFromClient(ply, ...)
- ITEM:SendUserMessage(ply, ...)
- HOOKS:
- ITEM:PreBackpack(ply)
- ITEM:OnEquip(ply)
- ITEM:PreDrop(ply)
- FUNCTIONS:
- ITEM:SetSate(state)
- ITEM:RemoveActiveItem()
- ]]
- items.StartItem("test_gun", nil, "weapon_base", "base_anim") -- Not sure how I should do this (if it's a neat way)
- -- The world model is used by entity and weapon
- ITEM.WorldModel = "models/weapons/w_pistol.mdl"
- ITEM.ViewModel = "models/weapons/v_pistol.mdl"
- ITEM.PrintName = "Test Gun!!"
- -- "both" means that the item is a weapon when equiped, and an entity when it's on ground
- ITEM.State = "both"
- ITEM.Inventory = {
- name = "Test gun",
- info = [[
- Used to test things
- ]],
- }
- function ITEM:Initialize()
- -- Don't really need this, it's just for constant reloading (I'm runstringing this) so the menu doesn't stack up
- self.DermaMenuOptions = {}
- if CLIENT then
- self:AddBackpackOption()
- self:AddEquipOption()
- self:AddSpacer()
- -- First argument is the label in the menu, second is the function name we're going to call when it's selected
- self:AddSimpleOption("Explode", "Explode")
- -- This one's for adding custom vgui elements to the menu
- -- We're adding a slider here
- self:AddCustomOption(function(menu)
- local slider = vgui.Create("DSlider")
- slider:SetTrapInside(true)
- slider:SetImage("vgui/slider")
- slider:SetLockY(0.5)
- slider:SetSize(100,13)
- slider:SetSlideX(1)
- Derma_Hook(slider,"Paint","Paint","NumSlider")
- slider.TranslateValues=function(p,x,y)
- self:CallOption("Spawn Random", "MakeEnt", table.Random({"npc_manhack", "npc_rollermine"})) -- You can do anything here, but I want to spam PrimaryAttack for fun.
- return x,y;
- end
- menu:AddPanel(slider)
- end)
- self:AddSimpleOption("Fire Primary", "PrimaryAttack")
- self:AddSimpleOption("Fire Secondary", "SecondaryAttack")
- else
- self:AllowOption("Explode", "Explode")
- self:AllowOption("Fire Secondary", "SecondaryAttack")
- self:AllowOption("Fire Primary", "PrimaryAttack")
- self:AllowOption("Spawn Random", "MakeEnt")
- -- Only do this if it's not a weapon
- if not self:IsWeapon() then
- self:SetModel( self.WorldModel )
- self:PhysicsInit( SOLID_VPHYSICS )
- self:SetMoveType( MOVETYPE_VPHYSICS )
- self:SetSolid( SOLID_VPHYSICS )
- self:PhysWake()
- end
- end
- end
- local sound = Sound( "Metal.SawbladeStick" )
- if SERVER then
- function ITEM.HOOK:PlayerSay(player, text)
- self:SendUserMessage(nil, "text", player:Nick() .. ": " .. text)
- end
- function ITEM:MakeEnt(class)
- self.Owner:MuzzleFlash()
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- local tr = self:GetTrace() -- This returns GetEyeTrace if it's held, and a custom trace if it's not held
- local ent = ents.Create( class )
- ent:SetPos( tr.HitPos )
- ent:SetAngles( tr.HitNormal:Angle() )
- ent:Spawn()
- ent:SetCollisionGroup(COLLISION_GROUP_WEAPON)
- timer.Simple(1, function() ent:Remove() end)
- end
- function ITEM:PrimaryAttack()
- self:MakeEnt("npc_manhack")
- end
- function ITEM:SecondaryAttack()
- self:MakeEnt("npc_rollermine")
- end
- function ITEM:Explode()
- local data = EffectData()
- data:SetOrigin(self:GetPos())
- util.Effect("explosion", data)
- self:Remove()
- end
- function ITEM:OnTakeDamage(info)
- info:SetDamageForce(info:GetDamageForce()*1000)
- self:TakePhysicsDamage(info)
- local ply = info:GetAttacker()
- if not ply:IsPlayer() then return end
- self:SendUserMessage(nil, "touch", ply)
- end
- else
- function ITEM:PrimaryAttack()
- self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
- self.Owner:MuzzleFlash()
- self.Owner:SetAnimation( PLAYER_ATTACK1 )
- end
- ITEM.SecondaryAttack = ITEM.PrimaryAttack
- function ITEM:ReceiveUserMessage(key, value)
- if key == "text" then self.text = value end
- if key == "touch" then chat.AddText(HSVToColor(math.random(360), 1,1), "CAUSE EVERYTIME WE TOUCH "..value:Nick().." GETS THIS FEELING") end
- end
- function ITEM.HOOK:HUDPaint()
- if not self.text then return end
- local position = self:GetPos():ToScreen()
- draw.DrawText(self.text, "Default", position.x, position.y, color_white, TEXT_ALIGN_LEFT)
- end
- function ITEM:DrawInBackPack(model, position, angles)
- model:SetPos(position + angles:Right() * 7 + angles:Forward() * -4)
- angles:RotateAroundAxis(angles:Right(), 50)
- model:SetAngles(angles)
- model:DrawModel()
- end
- end
- items.EndItem()
- if SERVER then
- items.EasyCreate("test_gun", nero.GetPlayer("caps"))
- end
Advertisement
Add Comment
Please, Sign In to add comment