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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
--This is a test file!
if not nrequire then return end
local reg = nrequire("item.lua")
local pac
if SERVER then
pac = nrequire("core/pac/sv_pac.lua")
end
local skil = nrequire("sh_skillcommon.lua")
skil.RegisterSkill({"Sailing","Paddleing"})
local paddleents = {}
hook.Add("Tick","paddleents",function()
for k,v in pairs(paddleents) do
--Make sure the player is still on the boat
--Find the entity below the player
local tr = util.TraceLine({
start = v:GetPos() + Vector(0,0,20),
endpos = v:GetPos() + Vector(0,0,-20),
filter = v
})
--And Add some velocity to it
if tr.Entity and IsValid(tr.Entity) then
--Move the boat
local oldvel = tr.Entity:GetVelocity()
local eye = v:EyeAngles():Forward()
eye.z = 0
local newvel = oldvel + (eye * 5) * tr.Entity:GetPhysicsObject():GetMass()
k:GetPhysicsObject():SetVelocity(newvel)
print("newvel is", newvel)
v:AddSkill("Paddleing",0.1)
end
--Add skill for the player
--Turn the boat
--local angdif = v:EyeAngles().yaw - k:GetAngles().yaw
--k:GetPhysicsObject():SetAngleVelocity(Angle(0,angdif,0))
end
end)
local items = {
{
Name = "Axe",
Tooltip = "Usefull for cutting down trees",
Shape = {
{true,true},
{true},
{true}
},
Model = "error.mdl",
pacname = "stranded_axe",
onClick = function(self, ply) --Run server side
print("Trying to chop...")
local tr = ply:GetEyeTrace()
print("Mattype:",tr.MatType,"Needed:",MAT_WOOD)
if tr.MatType == MAT_WOOD then
print("Chopping....")
ply:ChopWood()
end
end
},
{
Name = "Pickaxe",
Tooltip = "Maybe you can dig up rocks with this",
Shape = {
{true,true,true},
{false,true},
{false, true},
},
Model = "error.mdl",
pacname = "stranded_pickaxe",
onClick = function(self, ply) --Run server side
print("Trying to pick...")
local tr = ply:GetEyeTrace()
print("Mattype:",tr.MatType,"Needed:",MAT_CONCRETE)
if tr.MatType == MAT_CONCRETE then
print("Chopping....")
ply:MineRock()
end
end
},
{
Name = "Hammer",
Tooltip = "You should be able to build things with this",
Shape = {
{true,true,true},
{false,true},
{false,true},
},
Model = "error.mdl",
pacname = "stranded_hammer",
onClick = function(self,ply)
print("trying to hammer")
local tr = ply:GetEyeTrace()
local tents = {}
local cursor = 0
local firstsucpos = nil
while IsValid(tr.Entity) and tr.Entity != game.GetWorld() and cursor < 4 do
firstsucpos = firstsucpos or tr.HitPos
tents[#tents+1] = tr.Entity
tnents = table.Copy(tents)
tnents[#tnents + 1] = ply
tr = util.TraceLine({
start = tr.HitPos,
endpos = tr.HitPos + ply:EyeAngles():Forward() * 10,
filter = tnents
})
cursor = cursor + 1
end
print("found ents:")
PrintTable(tents)
--See if the player has nails
local nloc = ply:HasItem("Nail")
if nloc then
print("nlock was truthy, hammering...")
ply:RemoveItem(nloc)
local nail = ents.Create("prop_dynamic")
print("Setting pos to:",firstsucpos)
nail:SetPos(firstsucpos)
nail:SetAngles(ply:EyeAngles())
nail:SetModel("models/crossbow_bolt.mdl")
nail:Spawn()
for k,v in pairs(tents) do
for i,j in pairs(tents) do
if v != j then
print("Welding ",j," to ", v)
constraint.Weld(j,v,0,0,100000,true,false)
end
end
end
nail:SetParent(tents[1])
end
end
},
{
Name = "Paddle",
Tooltip = "Row Row Row your boat",
Shape = {
{true},
{true},
{true}
},
Model = "error.mdl",
pacname = "stranded_axe",
onClick = function(self, ply) --Run server side
--If we're current paddleing, stop
if self.paddleing then
print("paddleing ent removed")
paddleents[self.paddleing] = nil
self.paddleing = nil
return
end
--Find the entity below the player
local tr = util.TraceLine({
start = ply:GetPos() + Vector(0,0,20),
endpos = ply:GetPos() + Vector(0,0,-20),
filter = ply
})
--And Add some velocity to it
if tr.Entity and IsValid(tr.Entity) then
print("Paddleing ent added")
self.paddleing = tr.Entity
paddleents[tr.Entity] = ply
end
end
},
}
local base = {}
function base:Serialize()
return ""
end
function base:DeSerialize()
return self
end
function base:DoOnPanel(dmodelpanel)
dmodelpanel:SetModel(self.Model)
end
function base:DoOnEquipPanel(dmodelpanel)
dmodelpanel:SetModel(self.Model)
end
base.Equipable = "Right Hand"
function base:onDropped(ent)
if CLIENT then return end
pac.ApplyPac(ent,self.pacname)
ent:SetAngles(Angle(180,0,0))
ent:SetColor(Color(0,0,0,0))
end
function base:onEquip(ent)
if CLIENT then return end
pac.ApplyPac(ent,self.pacname)
end
function base:onUnEquip(ent)
if CLIENT then return end
pac.RemovePac(ent,self.pacname)
end
for k,v in pairs(items) do
local tbase = table.Copy(base)
for i,j in pairs(v) do tbase[i] = j end
reg.RegisterItem(tbase)
end
|