summaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/items/medicine.lua
blob: d741b0494b70ba11f9da17f6836fff4fde6d91eb (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
ITEM = {}

ITEM.Name = "Medicine"
ITEM.Description = "Heals you!"
ITEM.Icon = "items/medicine.png"
ITEM.UniqueData = false

if (SERVER) then
  util.AddNetworkString( "gms_usemedicine" )
end

local client_use = function()
  net.Start("gms_usemedicine")
  net.SendToServer()
end

local finisheduseing = function(player)
  player:DecResource( "Medicine", 1 )
  player:SendMessage( "You're feeling a bit better now.", 3, Color( 10, 200, 10, 255 ) )
  player:Heal( 10 )
end

local use_medicine = function(ln, player)
  if ( player:GetResource( "Medicine" ) < 1 ) then
    player:SendMessage( "You need Medicine.", 3, Color( 200, 0, 0, 255 ) )
    return
  end
  local maxhealth = 100
  if player:HasUnlock("Adept_Survivalist") then maxhealth = maxhealth + 50 end
  if player:HasUnlock("Master_Survivalist") then maxhealth = maxhealth + 50 end
  if player:Health() >= maxhealth then
    player:SendMessage( "You feel fine!", 3, Color( 200, 0, 0, 255 ) )
    return
  end
  player:EmitSound( Sound("items/smallmedkit1.wav" ) )
  startProcessGeneric(player,"Patching yourself up",1.5,finisheduseing)
end
net.Receive( "gms_usemedicine", use_medicine)

ITEM.Actions = {}
genericMakeDroppable(ITEM)
ITEM.Actions["Use"] = client_use

GMS.RegisterResource(ITEM)