mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-11-15 23:30:19 +01:00
Add wait rail
This commit is contained in:
parent
e4edb96d30
commit
2e01d8f421
|
@ -273,13 +273,22 @@ function cart_entity:on_step(dtime)
|
|||
acc = nil
|
||||
|
||||
local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration")
|
||||
if acc_meta == "halt" and not self.punched then
|
||||
if (acc_meta == "halt" or acc_meta:sub(1, 5) == "wait:") and not self.punched then
|
||||
-- Stop rail
|
||||
vel = {x=0, y=0, z=0}
|
||||
acc = false
|
||||
pos = vector.round(pos)
|
||||
update.pos = true
|
||||
update.vel = true
|
||||
if acc_meta:sub(1, 5) == "wait:" then
|
||||
local wait_time = tonumber(acc_meta:sub(6))
|
||||
if wait_time then
|
||||
minetest.after(wait_time, function()
|
||||
boost_cart:boost_rail(pos, 0.5)
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", acc_meta)
|
||||
end)
|
||||
end
|
||||
end
|
||||
end
|
||||
if acc == nil then
|
||||
-- Meta speed modifier
|
||||
|
|
67
rails.lua
67
rails.lua
|
@ -144,3 +144,70 @@ minetest.register_craft({
|
|||
output = "boost_cart:startstoprail 2",
|
||||
recipe = {"carts:powerrail", "carts:brakerail"},
|
||||
})
|
||||
|
||||
boost_cart.player_formspecs = {}
|
||||
|
||||
boost_cart:register_rail("boost_cart:waitrail", {
|
||||
description = "Wait rail",
|
||||
tiles = {
|
||||
"carts_rail_straight_wt.png", "carts_rail_curved_wt.png",
|
||||
"carts_rail_t_junction_wt.png", "carts_rail_crossing_wt.png"
|
||||
},
|
||||
groups = boost_cart:get_rail_groups(),
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
if not mesecon then
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("cart_acceleration", "wait:5")
|
||||
meta:set_string("cart_acceleration_backup", "wait:5")
|
||||
meta:set_string("infotext", "Wait time: 5 seconds.")
|
||||
|
||||
-- Show formspec to change the value.
|
||||
local player_name = placer:get_player_name()
|
||||
boost_cart.player_formspecs[player_name] = pos
|
||||
minetest.show_formspec(player_name, "boost_cart:waitrail", "field[time;Wait time (in seconds):;5]")
|
||||
end
|
||||
end,
|
||||
mesecons = {
|
||||
effector = {
|
||||
action_on = function(pos, node)
|
||||
boost_cart:boost_rail(pos, 0.5)
|
||||
end,
|
||||
action_off = function(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("cart_acceleration", meta:get_string("cart_acceleration_backup"))
|
||||
end,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
local player_name = player:get_player_name()
|
||||
if not player_name or formname ~= "boost_cart:waitrail" then
|
||||
return false
|
||||
end
|
||||
if fields.time then
|
||||
local num = tonumber(fields.time)
|
||||
if not num then
|
||||
minetest.chat_send_player(player_name, "Value must be a number; defaulting to 5 seconds.")
|
||||
return false
|
||||
end
|
||||
if num <= 0 then
|
||||
minetest.chat_send_player(player_name, "Value must be greater than 0; defaulting to 5 seconds.")
|
||||
return false
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(boost_cart.player_formspecs[player_name])
|
||||
meta:set_string("cart_acceleration", "wait:" .. num)
|
||||
meta:set_string("cart_acceleration_backup", "wait:" .. num)
|
||||
meta:set_string("infotext", "Wait time: " .. num .. " seconds.")
|
||||
minetest.chat_send_player(player_name, "Wait rail time set to " .. num .. " seconds.")
|
||||
else
|
||||
minetest.chat_send_player(player_name, "No value given; defaulting to 5 seconds.")
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "boost_cart:waitrail 3",
|
||||
recipe = {"carts:brakerail", "carts:powerrail", "carts:brakerail"},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user