diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2017-08-31 12:51:07 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2017-08-31 12:51:07 +0200 |
commit | 6053422cf292995b2a004ca0a21c640505ef32bb (patch) | |
tree | 30a04ec4a7b6cc62eee2047d4247265c943ead57 | |
parent | 3c432041f27a9566c8e0fd911a9c5e34fcb74241 (diff) |
Added faregates
-rw-r--r-- | README | 7 | ||||
-rw-r--r-- | depends.txt | 1 | ||||
-rw-r--r-- | faregate.lua | 81 | ||||
-rw-r--r-- | init.lua | 30 |
4 files changed, 112 insertions, 7 deletions
@@ -1 +1,6 @@ -This mod adds a farebox that emmits a mesecons signal whenever a payment is accepted.
\ No newline at end of file +This mod adds a farebox that emmits a mesecons signal whenever a payment is accepted. + +It also adds faregates that open when a payment is received and close +when they receive a mesecons signal, i.e. from a pressure pad right +behind them that verifies that the player has passed through the +faregate.
\ No newline at end of file diff --git a/depends.txt b/depends.txt index 2768bc1..e8b1ab6 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ mesecons default +doors diff --git a/faregate.lua b/faregate.lua new file mode 100644 index 0000000..a065002 --- /dev/null +++ b/faregate.lua @@ -0,0 +1,81 @@ +-- Faregates +-- Copyright (c) 2017 Gabriel Pérez-Cerezo, see LICENSE file for more details. +-- Nodeboxes generated with NodeBoxEditor. + +minetest.register_node("farebox:faregate", { + tiles = { + "default_steel_block.png" + }, + drawtype = "nodebox", + paramtype = "light", + description = "Faregate", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.4375, -0.4375, 0.5, 0.4375}, -- NodeBox3 + {0.4375, -0.5, -0.4375, 0.5, 0.5, 0.4375}, -- NodeBox5 + {-0.4375, -0.5, -0.0625, -0.0625, 0.6875, 0}, -- NodeBox6 + {0.0625, -0.5, -0.0625, 0.4375, 0.6875, 0}, -- NodeBox7 + } + }, + mesecons = { + effector = { + rules = mesecon.rules.default, + action_on = function (pos, node) + farebox.open_faregate(pos) + minetest.after(1, farebox.close_faregate, pos) + end, + }}, + can_dig = can_dig, + after_place_node = function(pos, player, _) + local meta = minetest.get_meta(pos) + local player_name = player:get_player_name() + + meta:set_string("owner", player_name) + meta:set_string("infotext", "Owned by "..player_name) + + local inv = meta:get_inventory() + inv:set_size("request", 1) + inv:set_size("main", 32) + end, + groups = {cracky=3}, + on_rightclick = function(pos, node, player, itemstack, pointed_thing) + farebox.show_formspec(pos, player) + end, + +}) + +minetest.register_node("farebox:faregate_open", { + tiles = { + "default_steel_block.png" + }, + description = "Open Faregate", + mesecons = { + effector = { + rules = mesecon.rules.default, + action_on = function (pos, node) + farebox.close_faregate(pos) + end, + }}, + groups = {not_in_creative_inventory = 1, cracky=3}, + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.4375, -0.4375, 0.5, 0.4375}, -- NodeBox3 + {0.4375, -0.5, -0.4375, 0.5, 0.5, 0.4375}, -- NodeBox5 + {-0.4375, -0.5, -0.0625, -0.375, 0.6875, 0.3125}, -- NodeBox6 + {0.375, -0.5, -0.0625, 0.4375, 0.6875, 0.3125}, -- NodeBox7 + } + }, + drop = "farebox:faregate" +}) + +minetest.register_craft({output = "farebox:faregate", + recipe = { + + + {"farebox:farebox", "doors:door_steel"}, + } +}) @@ -35,6 +35,17 @@ farebox.rules = {{x=0, y=-2, z=0}, {x=0, y=2, z=0}} +function farebox.open_faregate(pos) + minetest.swap_node(pos, {name="farebox:faregate_open"}) + minetest.sound_play("doors_steel_door_open", + {pos = pos, gain = 0.3, max_hear_distance = 10}) +end +function farebox.close_faregate(pos) + minetest.swap_node(pos, {name="farebox:faregate"}) + minetest.sound_play("doors_steel_door_close", + {pos = pos, gain = 0.3, max_hear_distance = 10}) +end + minetest.register_on_player_receive_fields(function(player, form, pressed) if string.sub(form,1,string.len("farebox:")) == "farebox:" then @@ -44,6 +55,7 @@ minetest.register_on_player_receive_fields(function(player, form, pressed) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local pname = player:get_player_name() + local nodename = minetest.get_node(pos).name local open = false if pressed.buy then if pinv:contains_item("main", inv:get_stack("request",1)) and inv:room_for_item("main", inv:get_stack("request",1)) then @@ -59,13 +71,17 @@ minetest.register_on_player_receive_fields(function(player, form, pressed) minetest.chat_send_player(pname, "Owner's inventory is full") end end - if pressed.open or open then + if pressed.open or open then minetest.chat_send_player(pname, "Payment accepted.") - mesecon.receptor_on(pos,farebox.rules) - minetest.after(1, function (_) - mesecon.receptor_off(pos,farebox.rules) - - end) + if nodename == "farebox:farebox" then + mesecon.receptor_on(pos,farebox.rules) + minetest.after(1, function (_) + mesecon.receptor_off(pos,farebox.rules) + + end) + elseif nodename == "farebox:faregate" then + farebox.open_faregate(pos) + end minetest.close_formspec(pname, form) end end @@ -116,3 +132,5 @@ minetest.register_craft({output = "farebox:farebox", {"group:wood", "mesecons:mesecon", "group:wood"}, } }) +local modpath = minetest.get_modpath("farebox") +dofile(modpath .. "/faregate.lua") |