Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bitchange
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
bitchange
Commits
20fcf0a0
Commit
20fcf0a0
authored
10 years ago
by
SmallJoker
Browse files
Options
Downloads
Patches
Plain Diff
HAAAANDS
parent
5761f2d9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
shop.lua
+58
-52
58 additions, 52 deletions
shop.lua
with
58 additions
and
52 deletions
shop.lua
+
58
−
52
View file @
20fcf0a0
...
...
@@ -8,7 +8,7 @@ local exchange_shop = {}
local
function
get_exchange_shop_formspec
(
number
,
pos
,
title
)
local
formspec
=
""
local
name
=
"nodemeta:"
..
pos
.
x
..
","
..
pos
.
y
..
","
..
pos
.
z
if
(
number
==
1
)
then
if
number
==
1
then
-- customer
formspec
=
(
"size[8,9;]"
..
"label[0,0;Exchange shop]"
..
...
...
@@ -21,12 +21,12 @@ local function get_exchange_shop_formspec(number,pos,title)
"label[0.7,3.8;(Remove me!)]"
..
"list["
..
name
..
";cust_ej;3,3.5;4,1;]"
..
"list[current_player;main;0,5;8,4;]"
)
elseif
(
number
==
2
or
number
==
3
)
then
elseif
number
==
2
or
number
==
3
then
-- owner
formspec
=
(
"size[11,10;]"
..
"label[0.
2
,0.1;Title:]"
..
"label[0.
3
,0.1;Title:]"
..
"field[1.5,0.5;3,0.5;title;;"
..
title
..
"]"
..
"button[4,0.2;1,0.5;set_title;Set]"
..
"button[4
.1
,0.2
4
;1,0.5;set_title;Set]"
..
"label[0,0.7;You need:]"
..
"list["
..
name
..
";cust_ow;0,1.2;2,2;]"
..
"label[3,0.7;You give:]"
..
...
...
@@ -35,7 +35,7 @@ local function get_exchange_shop_formspec(number,pos,title)
"list["
..
name
..
";custm_ej;0,4;4,1;]"
..
"label[6,0;You are viewing:]"
..
"label[6,0.3;(Click to switch)]"
)
if
(
number
==
2
)
then
if
number
==
2
then
formspec
=
(
formspec
..
"button[8.5,0.2;2.5,0.5;vstock;Customers stock]"
..
"list["
..
name
..
";custm;6,1;5,4;]"
)
else
...
...
@@ -50,8 +50,8 @@ local function get_exchange_shop_formspec(number,pos,title)
end
local
function
get_exchange_shop_tube_config
(
mode
)
if
(
bitchange_exchangeshop_pipeworks
)
then
if
(
mode
==
1
)
then
if
bitchange_exchangeshop_pipeworks
then
if
mode
==
1
then
return
{
choppy
=
2
,
oddly_breakable_by_hand
=
2
,
tubedevice
=
1
,
tubedevice_receiver
=
1
}
else
return
{
...
...
@@ -70,7 +70,7 @@ local function get_exchange_shop_tube_config(mode)
}
end
else
if
(
mode
==
1
)
then
if
mode
==
1
then
return
{
choppy
=
2
,
oddly_breakable_by_hand
=
2
}
else
return
{
...
...
@@ -87,7 +87,7 @@ local function get_exchange_shop_tube_config(mode)
end
minetest
.
register_on_player_receive_fields
(
function
(
sender
,
formname
,
fields
)
if
(
formname
~=
"bitchange:shop_formspec"
)
then
if
formname
~=
"bitchange:shop_formspec"
then
return
end
local
player_name
=
sender
:
get_player_name
()
...
...
@@ -95,14 +95,14 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
local
meta
=
minetest
.
get_meta
(
pos
)
local
title
=
meta
:
get_string
(
"title"
)
or
""
local
shop_owner
=
meta
:
get_string
(
"owner"
)
if
(
fields
.
quit
)
then
if
fields
.
quit
then
exchange_shop
[
player_name
]
=
nil
return
end
if
(
fields
.
set_title
)
then
if
(
fields
.
title
and
title
~=
fields
.
title
)
then
if
(
fields
.
title
~=
""
)
then
if
fields
.
set_title
then
if
fields
.
title
and
title
~=
fields
.
title
then
if
fields
.
title
~=
""
then
meta
:
set_string
(
"infotext"
,
"'"
..
fields
.
title
..
"' (owned by "
..
shop_owner
..
")"
)
else
meta
:
set_string
(
"infotext"
,
"Exchange shop (owned by "
..
shop_owner
..
")"
)
...
...
@@ -111,7 +111,7 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
end
end
if
(
fields
.
exchange
)
then
if
fields
.
exchange
then
local
shop_inv
=
meta
:
get_inventory
()
if
shop_inv
:
is_empty
(
"cust_ow"
)
and
shop_inv
:
is_empty
(
"cust_og"
)
then
return
...
...
@@ -128,87 +128,87 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
--?shop configured well
for
i1
,
item1
in
pairs
(
cust_ow
)
do
for
i2
,
item2
in
pairs
(
cust_ow
)
do
if
(
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
)
then
if
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
then
cust_ow_legal
=
false
--break
end
end
if
(
not
cust_ow_legal
)
then
if
not
cust_ow_legal
then
break
end
end
if
(
not
cust_ow_legal
)
then
if
not
cust_ow_legal
then
err_msg
=
"The 'Owner needs' field can not contain multiple times the same items, contact the shop owner."
end
if
(
err_msg
==
""
)
then
--?shop configured well
if
err_msg
==
""
then
--?shop configured well
for
i1
,
item1
in
pairs
(
cust_og
)
do
for
i2
,
item2
in
pairs
(
cust_og
)
do
if
(
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
)
then
if
item1
:
get_name
()
==
item2
:
get_name
()
and
i1
~=
i2
and
item1
:
get_name
()
~=
""
then
cust_og_legal
=
false
break
end
end
if
(
not
cust_og_legal
)
then
if
not
cust_og_legal
then
break
end
end
if
(
not
cust_og_legal
)
then
if
not
cust_og_legal
then
err_msg
=
"The 'Owner gives' field can not contain multiple times the same items, contact the shop owner."
end
end
if
(
err_msg
==
""
)
then
--?shop has space
if
err_msg
==
""
then
--?shop has space
local
shop_has_space
=
true
for
i
,
item
in
pairs
(
cust_ow
)
do
if
(
not
shop_inv
:
room_for_item
(
"custm"
,
item
)
)
then
if
not
shop_inv
:
room_for_item
(
"custm"
,
item
)
then
shop_has_space
=
false
break
end
end
if
(
not
shop_has_space
)
then
if
not
shop_has_space
then
err_msg
=
"The stock in the shop is full."
end
end
if
(
err_msg
==
""
)
then
--?shop has items
if
err_msg
==
""
then
--?shop has items
local
shop_has_items
=
true
for
i
,
item
in
pairs
(
cust_og
)
do
if
(
not
shop_inv
:
contains_item
(
"stock"
,
item
)
)
then
if
not
shop_inv
:
contains_item
(
"stock"
,
item
)
then
shop_has_items
=
false
break
end
end
if
(
not
shop_has_items
)
then
if
not
shop_has_items
then
err_msg
=
"The shop is empty and can not give you anything."
end
end
if
(
err_msg
==
""
)
then
--?player has space
if
err_msg
==
""
then
--?player has space
local
player_has_space
=
true
for
i
,
item
in
pairs
(
cust_og
)
do
if
(
not
player_inv
:
room_for_item
(
"main"
,
item
)
)
then
if
not
player_inv
:
room_for_item
(
"main"
,
item
)
then
player_has_space
=
false
break
end
end
if
(
not
player_has_space
)
then
if
not
player_has_space
then
err_msg
=
"You do not have the space in your inventory."
end
end
if
(
err_msg
==
""
)
then
--?player has items
if
err_msg
==
""
then
--?player has items
local
player_has_items
=
true
for
i
,
item
in
pairs
(
cust_ow
)
do
if
(
not
player_inv
:
contains_item
(
"main"
,
item
)
)
then
if
not
player_inv
:
contains_item
(
"main"
,
item
)
then
player_has_items
=
false
break
end
end
if
(
not
player_has_items
)
then
if
not
player_has_items
then
err_msg
=
"You do not have the needed items."
end
end
if
(
err_msg
==
""
)
then
--?exchange
if
err_msg
==
""
then
--?exchange
local
fully_exchanged
=
true
for
i
,
item
in
pairs
(
cust_ow
)
do
player_inv
:
remove_item
(
"main"
,
item
)
--player inv. to stock else to eject fields
if
(
shop_inv
:
room_for_item
(
"custm"
,
item
)
)
then
if
shop_inv
:
room_for_item
(
"custm"
,
item
)
then
shop_inv
:
add_item
(
"custm"
,
item
)
else
shop_inv
:
add_item
(
"custm_ej"
,
item
)
...
...
@@ -217,24 +217,30 @@ minetest.register_on_player_receive_fields(function(sender, formname, fields)
end
for
i
,
item
in
pairs
(
cust_og
)
do
shop_inv
:
remove_item
(
"stock"
,
item
)
--stock to player inv. else to eject fields
if
(
player_inv
:
room_for_item
(
"main"
,
item
)
)
then
if
player_inv
:
room_for_item
(
"main"
,
item
)
then
player_inv
:
add_item
(
"main"
,
item
)
else
shop_inv
:
add_item
(
"cust_ej"
,
item
)
fully_exchanged
=
false
end
end
if
(
not
fully_exchanged
)
then
if
not
fully_exchanged
then
err_msg
=
"Fatal error! Stocks are overflowing somewhere!"
end
end
if
(
err_msg
~=
""
)
then
if
err_msg
~=
""
then
minetest
.
chat_send_player
(
player_name
,
"Exchange shop: "
..
err_msg
)
end
elseif
(
fields
.
vstock
and
bitchange_has_access
(
shop_owner
,
player_name
)
and
not
fields
.
quit
)
then
minetest
.
show_formspec
(
sender
:
get_player_name
(),
"bitchange:shop_formspec"
,
get_exchange_shop_formspec
(
3
,
pos
,
title
))
elseif
(
fields
.
vcustm
and
bitchange_has_access
(
shop_owner
,
player_name
)
and
not
fields
.
quit
)
then
minetest
.
show_formspec
(
sender
:
get_player_name
(),
"bitchange:shop_formspec"
,
get_exchange_shop_formspec
(
2
,
pos
,
title
))
elseif
bitchange_has_access
(
shop_owner
,
player_name
)
then
local
num
=
0
if
fields
.
vcustm
then
num
=
2
elseif
fields
.
vstock
then
num
=
3
else
return
end
minetest
.
show_formspec
(
player_name
,
"bitchange:shop_formspec"
,
get_exchange_shop_formspec
(
num
,
pos
,
title
))
end
end
)
...
...
@@ -269,14 +275,13 @@ minetest.register_node("bitchange:shop", {
can_dig
=
function
(
pos
,
player
)
local
meta
=
minetest
.
get_meta
(
pos
);
local
inv
=
meta
:
get_inventory
()
if
(
inv
:
is_empty
(
"stock"
)
and
inv
:
is_empty
(
"custm"
)
and
if
(
inv
:
is_empty
(
"stock"
)
and
inv
:
is_empty
(
"custm"
)
and
inv
:
is_empty
(
"custm_ej"
)
and
inv
:
is_empty
(
"cust_ow"
)
and
inv
:
is_empty
(
"cust_og"
)
and
inv
:
is_empty
(
"cust_ej"
))
then
return
true
else
minetest
.
chat_send_player
(
player
:
get_player_name
(),
"Can not dig exchange shop, one or multiple stocks are in use."
)
return
false
end
minetest
.
chat_send_player
(
player
:
get_player_name
(),
"Can not dig exchange shop, one or multiple stocks are in use."
)
return
false
end
,
on_rightclick
=
function
(
pos
,
node
,
clicker
,
itemstack
)
local
meta
=
minetest
.
get_meta
(
pos
)
...
...
@@ -284,7 +289,7 @@ minetest.register_node("bitchange:shop", {
local
view
=
0
exchange_shop
[
player_name
]
=
pos
if
player_name
==
meta
:
get_string
(
"owner"
)
then
if
(
clicker
:
get_player_control
().
aux1
)
then
if
clicker
:
get_player_control
().
aux1
then
view
=
1
else
view
=
2
...
...
@@ -310,7 +315,8 @@ minetest.register_node("bitchange:shop", {
return
0
end
local
meta
=
minetest
.
get_meta
(
pos
)
if
(
bitchange_has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
and
(
listname
~=
"cust_ej"
)
and
(
listname
~=
"custm_ej"
))
then
if
bitchange_has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
and
listname
~=
"cust_ej"
and
listname
~=
"custm_ej"
then
return
stack
:
get_count
()
end
return
0
...
...
@@ -320,7 +326,7 @@ minetest.register_node("bitchange:shop", {
return
stack
:
get_count
()
end
local
meta
=
minetest
.
get_meta
(
pos
)
if
(
bitchange_has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
or
(
listname
==
"cust_ej"
))
then
if
bitchange_has_access
(
meta
:
get_string
(
"owner"
),
player
:
get_player_name
())
or
listname
==
"cust_ej"
then
return
stack
:
get_count
()
end
return
0
...
...
@@ -328,9 +334,9 @@ minetest.register_node("bitchange:shop", {
})
minetest
.
register_craft
({
output
=
'
bitchange:shop
'
,
output
=
"
bitchange:shop
"
,
recipe
=
{
{
'
default:sign_wall
'
},
{
'
default:chest_locked
'
},
{
"
default:sign_wall
"
},
{
"
default:chest_locked
"
},
}
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment