diff options
author | cheapie <no-email-for-you@example.com> | 2024-08-29 17:20:53 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2024-08-29 17:20:53 -0500 |
commit | e5edbece2bf4a28d4ff4751dc2337561207a9b92 (patch) | |
tree | 5f89334d92f9e42b73ccf8e81924cff5089ab1e9 | |
parent | 571bdaf927040ca08f31dd7ca631db8038b6d356 (diff) | |
download | celevator-e5edbece2bf4a28d4ff4751dc2337561207a9b92.tar celevator-e5edbece2bf4a28d4ff4751dc2337561207a9b92.tar.gz celevator-e5edbece2bf4a28d4ff4751dc2337561207a9b92.tar.bz2 celevator-e5edbece2bf4a28d4ff4751dc2337561207a9b92.tar.xz celevator-e5edbece2bf4a28d4ff4751dc2337561207a9b92.zip |
Constant pressure control for car top inspection
Car will now continue moving if the up/down buttons on the car top box are held, instead of stopping every 1m. When the buttons are released, it will stop at the next multiple of 1m.
-rw-r--r-- | car.lua | 23 | ||||
-rw-r--r-- | controllerfw.lua | 16 | ||||
-rw-r--r-- | drive_entity.lua | 4 |
3 files changed, 39 insertions, 4 deletions
@@ -56,6 +56,18 @@ local function updatecartopbox(pos) entity:set_pos(toppos) end +local held = {} + +minetest.register_globalstep(function() + for k,v in ipairs(held) do + local player = minetest.get_player_by_name(v.name) + if not (player and player:get_player_control()[v.button]) then + table.remove(held,k) + celevator.controller.handlecartopbox(v.pos,v.control.."_release") + end + end +end) + local pieces = { { _position = "000", @@ -330,8 +342,13 @@ local pieces = { "celevator_cabinet_sides.png", }, on_rightclick = function(pos,node,clicker) + local name = clicker:get_player_name() + for _,v in ipairs(held) do + if name == v.name then return end + end local fdir = minetest.fourdir_to_dir(node.param2) local control = disambiguatebutton(pos,fdir,clicker) + if not control then return end local meta = minetest.get_meta(pos) local carid = meta:get_int("carid") if carid == 0 then return end @@ -353,6 +370,12 @@ local pieces = { end end celevator.controller.handlecartopbox(carinfo.controllerpos,control) + table.insert(held,{ + pos = carinfo.controllerpos, + name = name, + button = "place", + control = control, + }) end, after_dig_node = function(pos) local toppos = vector.add(pos,vector.new(0,1.1,0)) diff --git a/controllerfw.lua b/controllerfw.lua index 398aff7..e0bdc22 100644 --- a/controllerfw.lua +++ b/controllerfw.lua @@ -668,7 +668,7 @@ elseif event.type == "cartopbox" then }) drivecmd({ command = "moveto", - pos = math.floor(mem.drive.status.apos)+1, + pos = gettarget(#mem.params.floornames), inspection = true, }) elseif event.control == "down" and mem.carstate == "carinspect" and mem.doorstate == "closed" and mem.drive.status.apos-1 >= 0 then @@ -680,7 +680,19 @@ elseif event.type == "cartopbox" then }) drivecmd({ command = "moveto", - pos = math.floor(mem.drive.status.apos)-1, + pos = 0, + inspection = true, + }) + elseif event.control == "up_release" and mem.carstate == "carinspect" and mem.drive.status.vel > 0 then + drivecmd({ + command = "moveto", + pos = math.ceil(mem.drive.status.apos), + inspection = true, + }) + elseif event.control == "down_release" and mem.carstate == "carinspect" and mem.drive.status.vel < 0 then + drivecmd({ + command = "moveto", + pos = math.floor(mem.drive.status.apos), inspection = true, }) end diff --git a/drive_entity.lua b/drive_entity.lua index f26bf11..ecbabdf 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -541,9 +541,9 @@ function celevator.drives.entity.moveto(pos,target,inspection) local apos = tonumber(meta:get_string("apos")) local vel = tonumber(meta:get_string("vel")) if vel > 0 then - if target < apos+(vel*2) then return end + if target < apos+(vel*2) and not inspection then return end elseif vel < 0 then - if target > apos-(vel*-2) then return end + if target > apos-(vel*-2) and not inspection then return end else return end |