@@ -219,51 +219,55 @@ function ctf_modebase.player.give_initial_stuff(player)
219
219
inv :set_list (" main" , new )
220
220
end
221
221
222
- minetest .register_on_item_pickup (function (itemstack , picker )
223
- if ctf_modebase .current_mode and ctf_teams .get (picker ) then
224
- local mode = ctf_modebase :get_current_mode ()
225
- for name , func in pairs (mode .initial_stuff_item_levels ) do
226
- local priority = func (itemstack )
227
-
228
- if priority then
229
- local inv = picker :get_inventory ()
230
- for i = 1 , 8 do -- loop through the top row of the player's inv
231
- local compare = inv :get_stack (" main" , i )
232
-
233
- if not mode .is_bound_item or not mode .is_bound_item (picker , compare :get_name ()) then
234
- local cprio = func (compare )
235
-
236
- if cprio and cprio < priority then
237
- local item , typ = simplify_for_saved_stuff (compare :get_name ())
238
- minetest .log (dump (item ).. dump (typ ))
239
- inv :set_stack (" main" , i , itemstack )
240
-
241
- if item == " sword" and typ == " stone" and
242
- ctf_settings .get (picker , " auto_trash_stone_swords" ) == " true" then
243
- return ItemStack (" " )
244
- end
245
-
246
- if item ~= " sword" and typ == " stone" and
247
- ctf_settings .get (picker , " auto_trash_stone_tools" ) == " true" then
248
- return ItemStack (" " )
249
- else
250
- local result = inv :add_item (" main" , compare ):get_count ()
222
+ if minetest .register_on_item_pickup then
223
+ minetest .register_on_item_pickup (function (itemstack , picker )
224
+ if ctf_modebase .current_mode and ctf_teams .get (picker ) then
225
+ local mode = ctf_modebase :get_current_mode ()
226
+ for name , func in pairs (mode .initial_stuff_item_levels ) do
227
+ local priority = func (itemstack )
228
+
229
+ if priority then
230
+ local inv = picker :get_inventory ()
231
+ for i = 1 , 8 do -- loop through the top row of the player's inv
232
+ local compare = inv :get_stack (" main" , i )
233
+
234
+ if not mode .is_bound_item or not mode .is_bound_item (picker , compare :get_name ()) then
235
+ local cprio = func (compare )
236
+
237
+ if cprio and cprio < priority then
238
+ local item , typ = simplify_for_saved_stuff (compare :get_name ())
239
+ minetest .log (dump (item ).. dump (typ ))
240
+ inv :set_stack (" main" , i , itemstack )
241
+
242
+ if item == " sword" and typ == " stone" and
243
+ ctf_settings .get (picker , " auto_trash_stone_swords" ) == " true" then
244
+ return ItemStack (" " )
245
+ end
251
246
252
- if result == 0 then
247
+ if item ~= " sword" and typ == " stone" and
248
+ ctf_settings .get (picker , " auto_trash_stone_tools" ) == " true" then
253
249
return ItemStack (" " )
254
250
else
255
- compare :set_count (result )
256
- return compare
251
+ local result = inv :add_item (" main" , compare ):get_count ()
252
+
253
+ if result == 0 then
254
+ return ItemStack (" " )
255
+ else
256
+ compare :set_count (result )
257
+ return compare
258
+ end
257
259
end
258
260
end
259
261
end
260
262
end
263
+ break -- We already found a place for it, don't check for one held by a different item type
261
264
end
262
- break -- We already found a place for it, don't check for one held by a different item type
263
265
end
264
266
end
265
- end
266
- end )
267
+ end )
268
+ else
269
+ minetest .log (" error" , " You aren't using the latest version of Minetest, auto-trashing and auto-sort won't work" )
270
+ end
267
271
268
272
function ctf_modebase .player .empty_inv (player )
269
273
player :get_inventory ():set_list (" main" , {})
0 commit comments