-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
220 lines (170 loc) · 6.74 KB
/
init.lua
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
211
212
213
214
215
216
217
218
219
220
----------------------------------------------------
-- GLOVES FOR STEALING, (C) rnd 2016
local stealt = {};
local thiefxp = {};
minetest.register_tool("thief:gloves", {
description = "thief gloves",
inventory_image = "stealgloves.png",
tool_capabilities = {
full_punch_interval = 2,
},
on_use = function(itemstack, user, pointed_thing)
local player1 = user;
local name = player1:get_player_name();
if not pointed_thing.type == "object" then return end
local player2 = pointed_thing.ref;
thiefxp[name] = thiefxp[name] or 0
local pjump = player1:get_player_control().jump
if not player2 then
if not pjump then -- CLOAK
local t = minetest.get_gametime();
if not stealt[name] then stealt[name]={t,0,"",{},t-20}; end -- time, state, target name, target position, cloak time
local data = stealt[name];
if (t - data[5])<20 then
minetest.chat_send_player(name,"#THIEF: wait " .. 20 -(t-data[5]) .. " s before cloaking ");
return
end
data[5]=t;
local ncolor = player1:get_nametag_attributes().color;
player1:set_nametag_attributes({color = "0x0"});
local cloaktime = 7+14*thiefxp[name]/10;
if cloaktime>19 then cloaktime = 19 end
minetest.chat_send_player(name,"#THIEF: cloak engaged for " .. math.floor(10*cloaktime)/10 .. " s");
minetest.after(cloaktime, function() -- decloak
player1:set_nametag_attributes({color = ncolor})
minetest.chat_send_player(name,"#THIEF: decloaking");
end)
end
return
end
if not player2:is_player() then return end
if pjump then -- SLOW
if thiefxp[name]<1 then
minetest.chat_send_player(name,"#THIEF: you need at least 1 xp to use slow.");
return
end
local speed0 = player2:get_physics_override().speed;
if speed0<0.8 then return end -- normal player speed
player2:set_physics_override({speed=0.33*speed0});
minetest.chat_send_player(name,"#THIEF: target slowed down for 10 s");
minetest.after(10, function() player2:set_physics_override({speed=speed0}); end)
return
end
local pos1 = player1:getpos();
local pos2 = player2:getpos();
local t = minetest.get_gametime();
if not stealt[name] then stealt[name]={t,0,"",{},t}; end -- time, state, target name, target position, cloak time
local data = stealt[name];
local v = {x=pos2.x-pos1.x,y=pos2.y-pos1.y,z=pos2.z-pos1.z};
local vm = math.sqrt(v.x^2+v.y^2+v.z^2);
if vm~=0 then v.x=v.x/vm; v.y=v.y/vm; v.z=v.z/vm end
local caught = false;
if data[2]==0 then -- init
local dir2 = player2:get_look_dir();
if v.x*dir2.x+v.z*dir2.z<=0.5 then caught = true end
if not caught then
minetest.chat_send_player(name,"#STEALING: attempting to steal. Stand behind player, wait for 5s and then use gloves again.")
data[3] = player2:get_player_name();
data[4] = pos2;
data[1] = t;
data[2]=1;
end
elseif data[2] == 1 then -- stealing second step
local pos20 = data[4];
if (pos20.x-pos2.x)^2 +(pos20.z-pos2.z)^2>4 then
--if pos20.x~=pos2.x or pos20.z~=pos2.z then
minetest.chat_send_player(name,"#STEALING: aborting. target moved.")
data[2]=0
return
end
if t-data[1]<5 then return end -- too soon
if t-data[1]>10 then data[2]=0 return end -- timeout
data[2]=0
local dir2 = player2:get_look_dir();
if v.x*dir2.x+v.z*dir2.z<=0.5 then caught = true end
if not caught then -- display inventory of items from target hands
local selected = 1;
local inv = player2:get_inventory();
local textlist = "";
for i = 1,8 do
textlist = textlist .. inv:get_stack("main", i):get_name() ..",";
end
local form = "size [3,2.5]"..
"label[0,-0.4;Select item to steal]"..
"textlist[0,0;2.8,2.6;craft;" .. textlist .. ";" .. selected .."]";
minetest.show_formspec(name, "stealform", form)
--local sel = tonumber(string.sub(fields.craft,5)) or 1
else
local xp = thiefxp[name];
xp=xp-0.5; if xp<0 then xp = 0 end
thiefxp[name]=xp;
minetest.chat_send_all("#THIEF "..name .. " tried to steal from " .. data[3] .. " but was caught. Lost -0.5 xp.")
end
end
end,
on_rightclick = function(self, clicker)
local name = clicker:get_player_name() or "";
minetest.chat_send_player(name, "#THIEF: you have " .. thiefxp[name] .. " thief experience. Cloaktime can be 19s when xp = 8.5 ")
end,
})
-- STEALING: final step
minetest.register_on_player_receive_fields(
function(player, formname, fields)
if formname == "stealform" then
if fields.craft then
if string.sub(fields.craft,1,3)=="DCL" then
local sel = tonumber(string.sub(fields.craft,5));
if not sel then return end
local name = player:get_player_name();
local data= stealt[name];
if not data then return end
data[2]=0
local tname = data[3];
local player2 = minetest.get_player_by_name(tname);
if not player2 then return end
local pos1 = player:getpos();
local pos2 = player2:getpos();
local v = {x=pos2.x-pos1.x,y=pos2.y-pos1.y,z=pos2.z-pos1.z};
local pos20 = data[4];
if (pos20.x-pos2.x)^2 +(pos20.z-pos2.z)^2>4 then
local text = "stealing aborted. target moved too far";
local form = "size [6,2] textarea[0,0;6.5,3.5;stealform1;THIEF;".. text.."]"
minetest.show_formspec(name, "stealfom1", form)
return
end
local privs = minetest.get_player_privs(tname);
if privs.privs then return end -- no stealing from admin
local tinv = player2:get_inventory();
local inv = player:get_inventory();
local txp = thiefxp[tname]; -- steal xp from victim
if not txp then txp = 0.1 elseif txp<0.1 then txp = 0.1 end
thiefxp[tname] = txp - 0.1;
local item = tinv:get_stack("main", sel):get_name();
if item == "" then return end
local dir2 = player2:get_look_dir();
if v.x*dir2.x+v.z*dir2.z<=0.5 then
minetest.chat_send_all("#THIEF: " .. name .. " has been caught trying to steal " .. item .. " from " .. tname)
local xp = thiefxp[name];
xp=xp-0.5; if xp<0 then xp = 0 end
thiefxp[name]=xp;
return
end
tinv:remove_item("main", ItemStack(item));
inv:add_item("main",ItemStack(item));
thiefxp[name] = thiefxp[name] + 0.1;
local text = "#THIEF: successfuly stole " .. item;
minetest.after(15, function() minetest.chat_send_all("#THIEF: someone has been robbed of " .. item .. " +0.1 xp for thief. ") end);
local form = "size [6,2] textarea[0,0;6.5,3.5;stealform1;THIEF;".. text.."]"
minetest.show_formspec(name, "stealfom1", form)
end
end
end
end
)
minetest.register_craft({
output = "thief:gloves",
recipe = {
{"default:diamondblock","default:goldblock","wool:white"},
}
})
---------------------------------------------