Switched from entity model to real fly privs

master
Joachim Stolberg 2017-09-24 12:20:43 +02:00
parent 0377480edd
commit a12eff34d2
7 changed files with 49 additions and 46 deletions

View File

@ -1,5 +1,5 @@
# Tower Crane Mod V0.10
In order to simplify the construction of buildings, the crane forms a construction area in which the player can fly (similar to fly privs).
# Tower Crane Mod V0.12
In order to simplify the construction of buildings, the crane forms a construction area in which the player gets fly privs.
Browse on: ![GitHub](https://github.com/joe7575/Minetest-Towercrane)
@ -21,17 +21,7 @@ The owner of the crane gets automatically area protection over the complete cons
If there is not enough free space for the crane mast/arm or the potential construction area of the
crane intersects a protected area from another player, the crane will not be build.
* Right-click the crane switch block to place the hook in front of the crane mast
* Enter the hook by right-clicking the hook
* "Fly" within the working area (height, width) by means of the (default) controls
- Move mouse: Look around
- W, A, S, D: Move
- Space: move up
- Shift: move down
* Leave the hook by right-clicking the hook or right-clicking the crane switch node
* Right-click the crane switch block to switch to fly privs. The player will be placed in front of the crane.
* To remove the crane, destroy the base block.
**Hint:** The protection area of the crane will also be removed.

View File

@ -7,8 +7,5 @@ towercrane.max_width = tonumber(minetest.setting_get("towercrane_max_width")) or
-- Crane rope lenght in block (max_height .. max_height+x)
towercrane.rope_length = tonumber(minetest.setting_get("towercrane_rope_length")) or 24
-- Gain factor for the crane sound (0.0 to 1)
towercrane.gain = tonumber(minetest.setting_get("towercrane_gain")) or 1
-- Recipe available (true/false)
towercrane.recipe = tonumber(minetest.setting_get("towercrane_recipe")) or true

View File

@ -1 +1 @@
To simplify the construction of buildings, the crane forms a working area, in which the player can fly.
To simplify the construction of buildings, the crane forms a working area, in which the player gets fly privs.

View File

@ -3,7 +3,7 @@
Tower Crane Mod
===============
v0.11 by JoSt
v0.12 by JoSt
Copyright (C) 2017 Joachim Stolberg
LGPLv2.1+
@ -102,31 +102,27 @@ end
--## Tower Crane Hook (player)
--##################################################################################################
-- give/take player fly privs
-- give/take player the necessary privs/physics
local function fly_privs(player, enable)
local privs = minetest.get_player_privs(player:get_player_name())
local physics = player:get_physics_override()
if privs then
print("vorher", minetest.privs_to_string(privs))
if enable == true then
if privs["fast"] then
player:set_attribute("store_fast", "1")
else
player:set_attribute("store_fast", "0")
end
player:set_attribute("store_fast", minetest.serialize(privs["fast"]))
player:set_attribute("store_fly", minetest.serialize(privs["fly"]))
player:set_attribute("store_speed", minetest.serialize(physics.speed))
privs["fly"] = true
privs["fast"] = nil
physics.speed = 0.5
else
privs["fly"] = nil
if player:get_attribute("store_fast") == "1" then
privs["fast"] = true
else
privs["fast"] = nil
end
physics.speed = 1
privs["fast"] = minetest.deserialize(player:get_attribute("store_fast"))
privs["fly"] = minetest.deserialize(player:get_attribute("store_fly"))
physics.speed = minetest.deserialize(player:get_attribute("store_speed"))
end
player:set_physics_override(physics)
minetest.set_player_privs(player:get_player_name(), privs)
print("nachher", minetest.privs_to_string(privs))
end
end
@ -146,10 +142,17 @@ local function control_player(pos, pos1, pos2, player)
if pl_pos.z < pos1.z then pl_pos.z = pos1.z; correction = true end
if pl_pos.z > pos2.z then pl_pos.z = pos2.z; correction = true end
if correction == true then
player:setpos(pl_pos)
if minetest.get_node(pl_pos).name == "air" then
player:setpos(pl_pos)
else
local last_pos = minetest.string_to_pos(meta:get_string("last_known_pos"))
player:setpos(last_pos)
end
else -- store last known correct position
meta:set_string("last_known_pos", minetest.pos_to_string(pl_pos))
end
minetest.after(2, control_player, pos, pos1, pos2, player)
minetest.after(1, control_player, pos, pos1, pos2, player)
end
end
else
@ -169,10 +172,11 @@ local function place_hook(pos, dir, player, pos1, pos2)
pos.x = pos.x + dir.x
pos.z = pos.z + dir.z
player:setpos(pos)
meta:set_string("last_known_pos", minetest.pos_to_string(pos))
-- set privs
fly_privs(player, true)
-- control player every 2 sec.
minetest.after(2, control_player, switch_pos, pos1, pos2, player)
-- control player every second
minetest.after(1, control_player, switch_pos, pos1, pos2, player)
end
end
@ -242,7 +246,7 @@ end
----------------------------------------------------------------------------------------------------
local function check_space(pos, dir, height, width)
local remove = function(pos, node_name, tArg)
if minetest.get_node_or_nil(pos).name ~= "air" then
if minetest.get_node(pos).name ~= "air" then
tArg.res = false
end
end
@ -276,8 +280,8 @@ end
----------------------------------------------------------------------------------------------------
local function remove_crane(pos, dir, height, width)
local remove = function(pos, node_name, tArg)
if minetest.get_node_or_nil(pos).name == node_name or
minetest.get_node_or_nil(pos).name == "towercrane:mast_ctrl_on" then
if minetest.get_node(pos).name == node_name or
minetest.get_node(pos).name == "towercrane:mast_ctrl_on" then
minetest.remove_node(pos)
end
end
@ -398,10 +402,17 @@ minetest.register_node("towercrane:base", {
-- evaluate user input (height, width), destroyed old crane and build a new one with
-- the given size
on_receive_fields = function(pos, formname, fields, player)
local switch_pos = {x=pos.x, y=pos.y+1, z=pos.z}
if fields.size == nil then
return
end
local meta = minetest.get_meta(pos)
local meta = minetest.get_meta(switch_pos)
local running = meta:get_int("running")
if running == 1 then
return
end
meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
local dir = minetest.string_to_pos(meta:get_string("dir"))
local height = meta:get_int("height")
@ -418,7 +429,7 @@ minetest.register_node("towercrane:base", {
if dir ~= nil and height ~= nil and width ~= nil then
remove_crane_data(pos)
remove_area(id, owner)
--remove_crane(table.copy(pos), dir, height, width)
remove_crane(table.copy(pos), dir, height, width)
remove_hook(pos, player)
end
@ -446,16 +457,24 @@ minetest.register_node("towercrane:base", {
else
chat(owner, "Too less distance to your other crane(s)!")
end
else
chat(owner, "Invalid input!")
end
end,
can_dig = function(pos, player)
local switch_pos = {x=pos.x, y=pos.y+1, z=pos.z}
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if player:get_player_name() == owner then
return true
if player:get_player_name() ~= owner then
return false
end
return false
meta = minetest.get_meta(switch_pos)
local running = meta:get_int("running")
if running == 1 then
return false
end
return true
end,
-- remove mast and arm if base gets destroyed

View File

@ -9,9 +9,6 @@ towercrane_max_width (maximum crane width) int 24
# can be placed on buildings and the hook still reaches the ground.
towercrane_rope_length (crane rope lenght) int 24
# Gain factor for the crane sound (0.0 to 1)
towercrane_gain (sound gain factor) float 1
# Recipe available (true/false)
towercrane_recipe (recipe available) bool true

BIN
sounds/crane.ogg Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 350 KiB

After

Width:  |  Height:  |  Size: 341 KiB