forked from AiTechEye/smartshop
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow transferring ownership of petz
- Loading branch information
1 parent
58fbd0b
commit c29f710
Showing
7 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
-- petz has its own mechanism for "selling" petz; this allows transferring ownership of animals put in shops | ||
|
||
local function set_owner(petstack, new_owner_name) | ||
local meta = petstack:get_meta() | ||
local serialized_data = meta:get("staticdata") | ||
if not serialized_data then | ||
return | ||
end | ||
|
||
local data = minetest.deserialize(serialized_data) | ||
|
||
if not (data and data.memory) then | ||
return | ||
end | ||
|
||
if (data.memory.owner or "") ~= "" then | ||
data.memory.owner = new_owner_name | ||
meta:set_string("staticdata", minetest.serialize(data)) | ||
end | ||
end | ||
|
||
local function is_petz(itemstack) | ||
local name = itemstack:get_name() | ||
return name:match("^petz:.*_set$") | ||
end | ||
|
||
smartshop.api.register_transaction_transform(function(player, shop, i, shop_removed, player_removed) | ||
if is_petz(shop_removed) then | ||
set_owner(shop_removed, player:get_player_name()) | ||
end | ||
if is_petz(player_removed) then | ||
set_owner(player_removed, shop:get_owner()) | ||
end | ||
return shop_removed, player_removed | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
name = smartshop | ||
description = A smarter and easier shop | ||
optional_depends = currency, default, mesecons, mesecons_mvps, pipeworks, tubelib | ||
optional_depends = currency, default, mesecons, mesecons_mvps, petz, pipeworks, tubelib |