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
|
--[[
This entity gives townies things to do
]]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include("shared.lua")
util.AddNetworkString("art_requestmodel")
util.AddNetworkString("art_informmodel")
util.AddNetworkString("art_requestpickup")
function ENT:Initialize()
self:SetModel(self.Model or "models/error.mdl")
assert(self.Item ~= nil, "Attempted to drop something without .Item set!")
self.ItemName = self.Item.Name
self.ItemData = self.Item.Data
if self.Item.onDropped then
self:SetColor(Color(0,0,0,0))
local od = self.Item.onDropped
if od ~= nil then
timer.Simple(1,function()
if self and self.Item then
od(self.Item,self)
end
end)
end
end
self:DrawShadow(false)
self:SetMoveType(MOVETYPE_NONE)
self:SetSolid(SOLID_NONE)
self:SetCollisionGroup(COLLISION_GROUP_INTERACTIVE)
end
--A client is near enough to draw the item, tell them what to draw.
net.Receive("art_requestmodel",function(len,pl)
print(pl," requested a model")
local ei = net.ReadUInt(16)
local e = Entity(ei)
assert(e.Model ~= nil,"Attempted to request model for non-art_droppeditem entity")
net.Start("art_informmodel")
net.WriteUInt(ei,16)
net.WriteString(e.Model)
net.Send(pl)
end)
net.Receive("art_requestpickup",function(len,pl)
local ei = net.ReadUInt(16)
local e = Entity(ei)
print("Got request to pick up", e)
local ep = e:GetPos()
print("got ep pos")
local plp = pl:GetPos()
print("got pl pos")
local d = ep:Distance(plp)
print("Got distance")
if d < 30 then
print("Inside if statement")
local i = ART.GetItemByName(e.ItemName):DeSerialize(e.ItemData)
print("Created item")
if pl:GiveItem(i) then
print("In if")
e:Remove()
end
print("Removed item")
else
print("Player not close enough!")
end
end)
function ENT:Use(activator, caller, usetype)
print("a",activator,"c",caller,"u",usetype)
end
print("Remove the concommand in art_droppeditem/init.lua")
concommand.Add("dropmellon",function(ply,cmd,args)
local e = ents.Create("art_droppeditem")
e.Model = "models/props_junk/Rock001a.mdl"
e.Item = ART.GetItemByName("Watermelon")
local hitpos = ply:GetEyeTrace().HitPos + Vector(0,0,10)
print("Traceresult was")
PrintTable(ply:GetEyeTrace())
print("Hitpos was", hitpos)
e:SetPos(hitpos)
e:Spawn()
end)
|