Added faregates

master
Gabriel Pérez-Cerezo 2017-08-31 12:51:07 +02:00
parent 3c432041f2
commit 6053422cf2
No known key found for this signature in database
GPG Key ID: 90422B01A46D0B3E
4 changed files with 112 additions and 7 deletions

7
README
View File

@ -1 +1,6 @@
This mod adds a farebox that emmits a mesecons signal whenever a payment is accepted.
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.

View File

@ -1,2 +1,3 @@
mesecons
default
doors

81
faregate.lua Normal file
View File

@ -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"},
}
})

View File

@ -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")