aboutsummaryrefslogtreecommitdiff
path: root/gamemode/shared/itemsystem/prayers/preditorinstinct.lua
blob: 8776c26ca52a9e0b1de0e283119b34f1999a0505 (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
90
91
92
93
94
95
96
97
98
--[[
    An example item
]]
local item = {}

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

--Optional, a tooltip to display when hovered over
item.Tooltip = "A prayer to the rouge god to grant you 30% movement when chaseing a wounded target"

--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!
local prayedplayers = {}
if SERVER then
    util.AddNetworkString("art_prayer_preditorinstinct")
    net.Receive("art_prayer_preditorinstinct",function(ln,ply)
        if ply:HasItem(item.Name) then
            prayedplayers[ply] = true
            timer.Simple(60,function()
                prayedplayers[ply] = nil
            end)
        end
    end)
end
function item.GetOptions(self)
    local options = {}
    options["Pray"] = function()
        net.Start("art_prayer_preditorinstinct")
        net.SendToServer()
    end
    return options
end
--called continuously to buff players
local buffedplayers = {}
local function buffplayers()
    for k,v in pairs(prayedplayers) do
        if buffedplayers[k] ~= nil then continue end
        --Find nearby wounded players or npcs
        print("Checking if ", k, "should be buffed")
        local wents = ents.FindInSphere(k:GetPos()+Vector(0,0,64),500)
        for i,j in pairs(wents) do
            print("Checking if ",j, "has taken dammage")
            if k ~= j and j:Health() < j:GetMaxHealth() then
                print("I buffed a player",k, "because ", j ,"has taken dammage")
                k:SetWalkSpeed(k:GetWalkSpeed()*1.3)
                buffedplayers[k] = true
                timer.Simple(60,function()
                    k:SetWalkSpeed(k:GetWalkSpeed()*(1/1.3))
                    buffedplayers[k] = nil
                end)
                goto nextply
            end
        end
        ::nextply::
    end
    timer.Simple(2,buffplayers)
end
buffplayers()

--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.DoOnEqupPanel(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},
}

ART.RegisterItem(item)