forked from AiTechEye/smartshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.lua
743 lines (662 loc) · 25.1 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
local follow_market_trends = minetest.settings:get_bool("money_market_trends") and
minetest.global_exists("money") == true
local shopsign = {}
local user = {}
local tmp = {}
local dir = {{x=0,y=0,z=-1},{x=-1,y=0,z=0},{x=0,y=0,z=1},{x=1,y=0,z=0}}
local dpos = {
{{x=0.2,y=0.2,z=0},{x=-0.2,y=0.2,z=0},{x=0.2,y=-0.2,z=0},{x=-0.2,y=-0.2,z=0}},
{{x=0,y=0.2,z=0.2},{x=0,y=0.2,z=-0.2},{x=0,y=-0.2,z=0.2},{x=0,y=-0.2,z=-0.2}},
{{x=-0.2,y=0.2,z=0},{x=0.2,y=0.2,z=0},{x=-0.2,y=-0.2,z=0},{x=0.2,y=-0.2,z=0}},
{{x=0,y=0.2,z=-0.2},{x=0,y=0.2,z=0.2},{x=0,y=-0.2,z=-0.2},{x=0,y=-0.2,z=0.2}}
}
minetest.register_craft({
output = "shopsign:shop",
recipe = {
{"default:chest_locked", "default:chest_locked", "default:chest_locked"},
{"default:sign_wall_wood", "default:chest_locked", "default:sign_wall_wood"},
{"default:sign_wall_wood", "default:torch", "default:sign_wall_wood"},
}
})
minetest.register_craft({
output = "shopsign:shop_metal",
recipe = {
{"default:chest_locked", "default:chest_locked", "default:chest_locked"},
{"default:sign_wall_steel", "default:chest_locked", "default:sign_wall_steel"},
{"default:sign_wall_steel", "default:torch", "default:sign_wall_steel"},
}
})
minetest.register_craft({
output = "shopsign:display_case",
recipe = {
{"default:steel_ingot", "default:glass", "default:steel_ingot"},
{"default:glass", "default:chest_locked", "default:glass"},
{"default:steel_ingot", "default:glass", "default:steel_ingot"},
}
})
local function is_creative(pname)
return minetest.check_player_privs(pname, {creative=true}) or minetest.check_player_privs(pname, {give=true})
end
local update_info = function(pos)
local meta=minetest.get_meta(pos)
local inv = meta:get_inventory()
local owner=meta:get_string("owner")
local gve=0
if meta:get_int("type")==0 then
meta:set_string("infotext","Admin Shop")
return false
end
local name=""
local count=0
local stuff={}
for i=1,4,1 do
stuff["count" ..i]=inv:get_stack("give" .. i,1):get_count()
stuff["name" ..i]=inv:get_stack("give" .. i,1):get_name()
stuff["stock" ..i]=gve*stuff["count" ..i]
stuff["buy" ..i]=0
for ii=1,32,1 do
name=inv:get_stack("main",ii):get_name()
count=inv:get_stack("main",ii):get_count()
if name==stuff["name" ..i] then
stuff["stock" ..i]=stuff["stock" ..i]+count
end
end
local nstr=(stuff["stock" ..i]/stuff["count" ..i]) ..""
nstr=nstr.split(nstr, ".")
stuff["buy" ..i]=tonumber(nstr[1])
if stuff["name" ..i]=="" or stuff["buy" ..i]==0 then
stuff["buy" ..i]=""
stuff["name" ..i]=""
else
if string.find(stuff["name" ..i],":")~=nil then
stuff["name" ..i]=stuff["name" ..i].split(stuff["name" ..i],":")[2]
end
stuff["buy" ..i]="(" ..stuff["buy" ..i] ..") "
stuff["name" ..i]=stuff["name" ..i] .."\n"
end
end
meta:set_string("infotext",
owner .."'s Shop:\n"
.. stuff.buy1 .. stuff.name1
.. stuff.buy2 .. stuff.name2
.. stuff.buy3 .. stuff.name3
.. stuff.buy4 .. stuff.name4
)
end
local update_entity = function(pos, stat)
--clear
local spos=minetest.pos_to_string(pos)
for _, ob in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
if ob and ob:get_luaentity() and ob:get_luaentity().shopsign and ob:get_luaentity().pos==spos then
ob:remove()
end
end
if stat=="clear" then return end
--update
local meta=minetest.get_meta(pos)
local inv = meta:get_inventory()
local node=minetest.get_node(pos)
local dp = dir[node.param2+1]
if not dp then return end
pos.x = pos.x + dp.x*0.01
pos.y = pos.y + dp.y*6.5/16
pos.z = pos.z + dp.z*0.01
for i=1,4,1 do
local item=inv:get_stack("give" .. i,1):get_name()
local pos2=dpos[node.param2+1][i]
if item~="" then
tmp.item=item
tmp.pos=spos
local e = minetest.add_entity({x=pos.x+pos2.x,y=pos.y+pos2.y,z=pos.z+pos2.z},"shopsign:item")
e:set_yaw(math.pi*2 - node.param2 * math.pi/2)
end
end
end
local showform = function(pos,player,re)
local meta=minetest.get_meta(pos)
local creative=meta:get_int("creative")
local inv = meta:get_inventory()
local gui=""
local spos=pos.x .. "," .. pos.y .. "," .. pos.z
local uname=player:get_player_name()
local owner=meta:get_string("owner")==uname
if minetest.check_player_privs(uname, {protection_bypass=true}) then owner=true end
if re then owner=false end
user[uname]=pos
if owner then
if meta:get_int("type") == 0
and not (minetest.check_player_privs(uname, {creative=true})
or minetest.check_player_privs(uname, {give=true})) then
meta:set_int("creative",0)
meta:set_int("type",1)
creative=0
end
gui=""
.."size[8,10]"
.."button_exit[6,0;1.8,1;customer;Customer]"
.."label[0,0.2;Sell:]"
.."label[0,1.2;Price:]"
.."list[nodemeta:" .. spos .. ";give1;1,0;1,1;]"
.."list[nodemeta:" .. spos .. ";pay1;1,1;1,1;]"
.."list[nodemeta:" .. spos .. ";give2;2,0;1,1;]"
.."list[nodemeta:" .. spos .. ";pay2;2,1;1,1;]"
.."list[nodemeta:" .. spos .. ";give3;3,0;1,1;]"
.."list[nodemeta:" .. spos .. ";pay3;3,1;1,1;]"
.."list[nodemeta:" .. spos .. ";give4;4,0;1,1;]"
.."list[nodemeta:" .. spos .. ";pay4;4,1;1,1;]"
if creative==1 then
gui = gui .."button[6,1;2.2,1;toggle_unlimited;Toggle Limit]"
end
gui=gui
.."list[nodemeta:" .. spos .. ";main;0,2;8,4;]"
.."list[current_player;main;0,6.2;8,4;]"
.."listring[nodemeta:" .. spos .. ";main]"
.."listring[current_player;main]"
else
gui=""
.."size[8,6]"
.."list[current_player;main;0,2.2;8,4;]"
.."label[0,0.2;Item:]"
.."label[0,1.2;Price:]"
.."list[nodemeta:" .. spos .. ";give1;2,0;1,1;]"
.."item_image_button[2,1;1,1;".. inv:get_stack("pay1",1):get_name() ..";buy1;\n\n\b\b\b\b\b" .. inv:get_stack("pay1",1):get_count() .."]"
.."list[nodemeta:" .. spos .. ";give2;3,0;1,1;]"
.."item_image_button[3,1;1,1;".. inv:get_stack("pay2",1):get_name() ..";buy2;\n\n\b\b\b\b\b" .. inv:get_stack("pay2",1):get_count() .."]"
.."list[nodemeta:" .. spos .. ";give3;4,0;1,1;]"
.."item_image_button[4,1;1,1;".. inv:get_stack("pay3",1):get_name() ..";buy3;\n\n\b\b\b\b\b" .. inv:get_stack("pay3",1):get_count() .."]"
.."list[nodemeta:" .. spos .. ";give4;5,0;1,1;]"
.."item_image_button[5,1;1,1;".. inv:get_stack("pay4",1):get_name() ..";buy4;\n\n\b\b\b\b\b" .. inv:get_stack("pay4",1):get_count() .."]"
end
minetest.after((0.2), function(gui)
return minetest.show_formspec(player:get_player_name(), "shopsign:showform",gui)
end, gui)
end
local receive_fields = function(player, pressed)
local pname = player:get_player_name()
local pos = user[pname]
if not pos then
return
end
if pressed.customer then
return showform(pos, player, true)
elseif pressed.toggle_unlimited then
local meta = minetest.get_meta(pos)
if not is_creative(pname) then
meta:set_int("type", 1)
meta:set_int("creative", 0)
minetest.chat_send_player(pname, "You are not allowed to make a creative shop!")
return
end
local pname = player:get_player_name()
if meta:get_int("type") == 0 then
meta:set_int("type", 1)
minetest.chat_send_player(pname, "Unlimited stock disabled")
else
meta:set_int("type", 0)
minetest.chat_send_player(pname, "Unlimited stock enabled")
end
elseif not pressed.quit then
local n = 1
for i = 1, 4, 1 do
n = i
if pressed["buy" .. i] then break end
end
local meta=minetest.get_meta(pos)
local sign_type=meta:get_int("type")
local sellall=meta:get_int("sellall")
local inv=meta:get_inventory()
local pinv=player:get_inventory()
local pname=player:get_player_name()
local check_storage
if pressed["buy" .. n] then
local name=inv:get_stack("give" .. n,1):get_name()
local stack=name .." ".. inv:get_stack("give" .. n,1):get_count()
local pay=inv:get_stack("pay" .. n,1):get_name() .." ".. inv:get_stack("pay" .. n,1):get_count()
local stack_to_use="main"
if name~="" then
if not pinv:room_for_item("main", stack) then
minetest.chat_send_player(pname, "Error: Your inventory is full, exchange aborted.")
return
elseif not pinv:contains_item("main", pay) then
minetest.chat_send_player(pname, "Error: You dont have enough in your inventory to buy this, exchange aborted.")
return
elseif sign_type==1 and inv:room_for_item("main", pay)==false then
minetest.chat_send_player(pname, "Error: The owners stock is full, cant receive, exchange aborted.")
return
else
if inv:contains_item("main", stack) then
elseif sellall==1 and inv:contains_item("give" .. n, stack) then
stack_to_use="give" .. n
else
minetest.chat_send_player(pname, "Error: The owners stock is end.")
check_storage=1
end
if not check_storage then
for i=0,32,1 do
if pinv:get_stack("main", i):get_name()==inv:get_stack("pay" .. n,1):get_name() and pinv:get_stack("main",i):get_wear()>0 then
minetest.chat_send_player(pname, "Error: your item is used")
return
end
end
minetest.after(0.2, function(inv, pinv)
local rastack = inv:remove_item(stack_to_use, stack)
pinv:remove_item("main", pay)
pinv:add_item("main", rastack)
if sign_type==1 then inv:add_item("main", pay) end
if sign_type==0 then inv:add_item("main", rastack) end
end, inv, pinv)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", pname .." paid ".. pay.. " for " .. stack
.. " from Shopsign owned by " .. shopsign_owner .. " at " .. minetest.pos_to_string(pos))
if follow_market_trends then
money_api.economic_indicator(pname, pay, stack, pos, shopsign_owner)
end
end
end
end
end
else
update_info(pos)
update_entity(pos,"update")
user[player:get_player_name()]=nil
end
end
minetest.register_on_player_receive_fields(function(player, form, pressed)
if form == "shopsign:showform" then
receive_fields(player,pressed)
end
end)
minetest.register_entity("shopsign:item",{
hp_max = 100,
visual = "wielditem",
visual_size = { x = 0.20 , y = 0.20},
collisionbox = {0,0,0,0,0,0},
physical = false,
textures = {"air"},
shopsign = true,
type = "",
immortal = true,
on_activate = function(self, staticdata)
if tmp.item ~= nil then
self.item=tmp.item
self.pos=tmp.pos
tmp={}
else
if staticdata ~= nil and staticdata ~= "" then
local data = staticdata:split(';')
if data and data[1] and data[2] then
self.item = data[1]
self.pos = data[2]
end
end
end
if self.item ~= nil then
self.object:set_properties({textures={self.item}})
else
self.object:remove()
end
end,
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
minetest.log("action", "[shopsign] Player "..puncher:get_player_name().." punched shopsign entity")
return
end,
get_staticdata = function(self)
if self.item ~= nil and self.pos ~= nil then
return self.item .. ';' .. self.pos
end
return ""
end,
})
minetest.register_node("shopsign:shop", {
description = "Wooden Shop Sign",
tiles = {
"shopsign_wood_updn.png",
"shopsign_wood_updn.png",
"shopsign_wood_side.png",
"shopsign_wood_side.png",
"shopsign_wood_back.png",
"shopsign_wood_face.png"},
groups = {choppy = 1, oddly_breakable_by_hand = 1},
drawtype="nodebox",
node_box = {type="fixed",fixed={-0.5,-0.5,-0.0,0.5,0.5,0.5}},
paramtype2="facedir",
paramtype = "light",
sunlight_propagates = true,
light_source = 10,
after_place_node = function(pos, placer)
local meta=minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name())
meta:set_string("infotext", "Shop by: " .. placer:get_player_name())
meta:set_int("type",1)
meta:set_int("sellall",1)
if is_creative(placer:get_player_name()) then
meta:set_int("creative",1)
meta:set_int("type",0)
meta:set_int("sellall",0)
end
end,
on_construct = function(pos)
local meta=minetest.get_meta(pos)
meta:set_int("state", 0)
meta:get_inventory():set_size("main", 32)
meta:get_inventory():set_size("give1", 1)
meta:get_inventory():set_size("pay1", 1)
meta:get_inventory():set_size("give2", 1)
meta:get_inventory():set_size("pay2", 1)
meta:get_inventory():set_size("give3", 1)
meta:get_inventory():set_size("pay3", 1)
meta:get_inventory():set_size("give4", 1)
meta:get_inventory():set_size("pay4", 1)
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
showform(pos,player)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_wear()==0 and (minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true})) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
return 0
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
local inv = meta:get_inventory()
local from_stack = inv:get_stack(from_list, from_index)
local to_stack = inv:get_stack(to_list, to_index)
minetest.log("action", player:get_player_name()..
" moves "..from_stack:get_name().." "..from_stack:get_count().. " "..from_list..
" to "..to_stack:get_name().." "..to_stack:get_count().." "..to_list..
" inside Shopsign owned by " .. shopsign_owner .. " at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" puts "..itemstack:get_name().." "..itemstack:get_count()..
" into slot "..listname..
" in Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" takes "..itemstack:get_name().." "..itemstack:get_count()..
" from slot "..listname..
" from Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
can_dig = function(pos, player)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
if ((meta:get_string("owner") == player:get_player_name()
or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
and inv:is_empty("main")
and inv:is_empty("pay1")
and inv:is_empty("pay2")
and inv:is_empty("pay3")
and inv:is_empty("pay4")
and inv:is_empty("give1")
and inv:is_empty("give2")
and inv:is_empty("give3")
and inv:is_empty("give4"))
or meta:get_string("owner")=="" then
update_entity(pos,"clear")
return true
end
end,
})
minetest.register_node("shopsign:shop_metal", {
description = "Metal Shop Sign",
tiles = {
"shopsign_metal_updn.png",
"shopsign_metal_updn.png",
"shopsign_metal_side.png",
"shopsign_metal_side.png",
"shopsign_metal_back.png",
"shopsign_metal_face.png"},
groups = {choppy = 1, oddly_breakable_by_hand = 1},
drawtype="nodebox",
node_box = {type="fixed",fixed={-0.5,-0.5,-0.0,0.5,0.5,0.5}},
paramtype2="facedir",
paramtype = "light",
sunlight_propagates = true,
light_source = 10,
after_place_node = function(pos, placer)
local meta=minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name())
meta:set_string("infotext", "Shop by: " .. placer:get_player_name())
meta:set_int("type",1)
meta:set_int("sellall",1)
if is_creative(placer:get_player_name()) then
meta:set_int("creative",1)
meta:set_int("type",0)
meta:set_int("sellall",0)
end
end,
on_construct = function(pos)
local meta=minetest.get_meta(pos)
meta:set_int("state", 0)
meta:get_inventory():set_size("main", 32)
meta:get_inventory():set_size("give1", 1)
meta:get_inventory():set_size("pay1", 1)
meta:get_inventory():set_size("give2", 1)
meta:get_inventory():set_size("pay2", 1)
meta:get_inventory():set_size("give3", 1)
meta:get_inventory():set_size("pay3", 1)
meta:get_inventory():set_size("give4", 1)
meta:get_inventory():set_size("pay4", 1)
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
showform(pos,player)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_wear()==0 and (minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true})) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
return 0
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
local inv = meta:get_inventory()
local from_stack = inv:get_stack(from_list, from_index)
local to_stack = inv:get_stack(to_list, to_index)
minetest.log("action", player:get_player_name()..
" moves "..from_stack:get_name().." "..from_stack:get_count().. " "..from_list..
" to "..to_stack:get_name().." "..to_stack:get_count().." "..to_list..
" inside Shopsign owned by " .. shopsign_owner .. " at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" puts "..itemstack:get_name().." "..itemstack:get_count()..
" into slot "..listname..
" in Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" takes "..itemstack:get_name().." "..itemstack:get_count()..
" from slot "..listname..
" from Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
can_dig = function(pos, player)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
if ((meta:get_string("owner") == player:get_player_name()
or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
and inv:is_empty("main")
and inv:is_empty("pay1")
and inv:is_empty("pay2")
and inv:is_empty("pay3")
and inv:is_empty("pay4")
and inv:is_empty("give1")
and inv:is_empty("give2")
and inv:is_empty("give3")
and inv:is_empty("give4"))
or meta:get_string("owner")=="" then
update_entity(pos,"clear")
return true
end
end,
})
minetest.register_node("shopsign:display_case", {
description = "Shop Display Case",
drawtype="glasslike_framed",
paramtype = "light",
paramtype2 = "glasslikeliquidlevel",
legacy_wallmounted = true,
legacy_facedir_simple = true,
is_ground_content = false,
sunlight_propagates = true,
light_source = 7,
use_texture_alpha = "blend",
tiles = {
{
name = "shopsign_display_inner.png",
backface_culling = true,
scale = 1
},
{
name = "shopsign_display_outer.png",
backface_culling = false,
scale = 1,
},
},
special_tiles = {"shopsign_display_carpet.png"},
groups = {choppy = 1, oddly_breakable_by_hand = 1},
after_place_node = function(pos, placer)
local newparam2 = minetest.dir_to_facedir(placer:get_look_dir())
minetest.swap_node(pos, {name = "shopsign:display_case", param2 = newparam2})
local meta=minetest.get_meta(pos)
meta:set_string("owner",placer:get_player_name())
meta:set_string("infotext", "Shop by: " .. placer:get_player_name())
meta:set_int("type",1)
meta:set_int("sellall",1)
if is_creative(placer:get_player_name()) then
meta:set_int("creative",1)
meta:set_int("type",0)
meta:set_int("sellall",0)
end
end,
on_construct = function(pos)
local meta=minetest.get_meta(pos)
meta:set_int("state", 0)
meta:get_inventory():set_size("main", 32)
meta:get_inventory():set_size("give1", 1)
meta:get_inventory():set_size("pay1", 1)
meta:get_inventory():set_size("give2", 1)
meta:get_inventory():set_size("pay2", 1)
meta:get_inventory():set_size("give3", 1)
meta:get_inventory():set_size("pay3", 1)
meta:get_inventory():set_size("give4", 1)
meta:get_inventory():set_size("pay4", 1)
end,
on_punch = function(pos, node, puncher, pointed_thing)
if puncher:is_player() and
minetest.get_meta(pos):get_string("owner") == puncher:get_player_name() then
if node.param2 >= 3 then
minetest.swap_node(pos, {name = "shopsign:display_case", param2 = 0})
else
minetest.swap_node(pos, {name = "shopsign:display_case", param2 = node.param2+1})
end
update_entity(pos,"update")
end
end,
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
showform(pos,player)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if stack:get_wear()==0 and (minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true})) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.get_meta(pos):get_string("owner")==player:get_player_name() or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}) then
stack:set_count(math.min(stack:get_count(), 99))
return stack:get_count()
end
return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
return 0
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
local inv = meta:get_inventory()
local from_stack = inv:get_stack(from_list, from_index)
local to_stack = inv:get_stack(to_list, to_index)
minetest.log("action", player:get_player_name()..
" moves "..from_stack:get_name().." "..from_stack:get_count().. " "..from_list..
" to "..to_stack:get_name().." "..to_stack:get_count().." "..to_list..
" inside Shopsign owned by " .. shopsign_owner .. " at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" puts "..itemstack:get_name().." "..itemstack:get_count()..
" into slot "..listname..
" in Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, itemstack, player)
local meta = minetest.get_meta(pos)
local shopsign_owner = meta:get_string("owner")
minetest.log("action", player:get_player_name() ..
" takes "..itemstack:get_name().." "..itemstack:get_count()..
" from slot "..listname..
" from Shopsign owned by "..shopsign_owner..
" at "..minetest.pos_to_string(pos))
end,
can_dig = function(pos, player)
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
if ((meta:get_string("owner") == player:get_player_name()
or minetest.check_player_privs(player:get_player_name(), {protection_bypass=true}))
and inv:is_empty("main")
and inv:is_empty("pay1")
and inv:is_empty("pay2")
and inv:is_empty("pay3")
and inv:is_empty("pay4")
and inv:is_empty("give1")
and inv:is_empty("give2")
and inv:is_empty("give3")
and inv:is_empty("give4"))
or meta:get_string("owner")=="" then
update_entity(pos,"clear")
return true
end
end,
})
minetest.register_alias("smartshop:shop", "shopsign:shop")