aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/utility/flashlight.lua
blob: 6b0a40c084f81f0254dd68bd7c89af9cbf16d5f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
    An example item
]]
do return end
local item = {}

--Required, a name, all item names must be unique
item.Name = "Flashlight"

--Optional, a tooltip to display when hovered over
item.Tooltip = "An old axe, probably good for fighting."

--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
item.Serialize = function(self)
    print("Trying to serailize!")
    return ""
end

--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
item.DeSerialize = function(self,string)
    print("Trying to deserialize!")
    return self
end

--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something server side, you'll need to use the net library. Remember that items are in the shared domain, so you can define what it does in the same file!
function item.GetOptions(self)
    local options = {}
    options["test"] = function() print("You pressed test!") end
    options["toste"] = function() print("You pressed toste!") end
    return options
end

--Optional. Something run once when this item is drawn in a backpack
function item.DoOnPanel(dimagebutton)
    dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
end

--Optional. Something run once when this item is drawn in an equiped slot
function item.DoOnEquipPanel(dimagebutton)
    print("called with panel:",panel)
    dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
end

--Optional. Called continuously, use if you need the item to display different stuff at different tiems in the backpack.
function item.Paint(self,width,height)
    draw.RoundedBox(4, 0,0,width,height,Color(0,100,0))
end

--Optional. Called continuously, use if you need the item to display different stuff at different tiems when equiped.
function item.PaintEquiped(self,width,height)
    draw.RoundedBox(4, 0,0,width,height,Color(0,100,0))
end

--Required, the shape of this item in a backpack.
item.Shape = {
    {true,true},
}

--Optional, If this item can be equiped in any player slots, put them here.
item.Equipable = "Left"

--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right
local lastontime = {}
item.onClick = function(self,owner)
    if CLIENT then return end
    if lastontime[owner] then return end
    lastontime[owner] = true
    timer.Simple(5,function()
        lastontime[owner] = nil
    end)
    owner:Flashlight( not owner:FlashlightIsOn() )
end

--Optional, if we should do something special on equip(like draw the PAC for this weapon). See ART.ApplyPAC in /gamemode/shared/sh_pac.lua
item.onEquip = function(self,who)
    if CLIENT then return end
    who:AllowFlashlight(true)
end

--Optional, if we should do something speical on unequip(like setting PAC back to normal). Sett ART.RemovePAC in /gamemode/shared/sh_pac.lua
item.onUnEquip = function(self,who)
    if CLIENT then return end
    who:Flashlight(false)
    who:AllowFlashlight(false)
end


--Don't forget to register the item!
nrequire("item.lua").RegisterItem(item)