]> git.lizzy.rs Git - hangglider.git/blobdiff - init.lua
Add setting to disable using the hangglider and the fast privilege together
[hangglider.git] / init.lua
index b1e06816c4c95e4c77febbc75d7fb719a3a81cd8..60b76e3e287e1355e1c3c828483d50d27abf93c7 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -99,7 +99,7 @@ minetest.register_entity("hangglider:airstopper", { --A one-instant entity that
        end
 })]]
 
-if areas then
+if core.global_exists("areas") then
        hangglider.flak = true
        -- chat command definition essentially copied from areas mod.
        minetest.register_chatcommand("area_flak",{
@@ -124,7 +124,7 @@ if areas then
        })
 end
 
-if minetestd and minetestd.services.physicsctl.enabled then
+if core.global_exists("minetestd") and minetestd.services.physicsctl.enabled then
 minetestd.physicsctl.register_physics_effect("hangglider",
        function(player) -- check
                return hangglider.use[player:get_player_name()]
@@ -136,7 +136,7 @@ minetestd.physicsctl.register_physics_effect("hangglider",
                if vel_y < 0 and vel_y > -3 then
                        phys.speed = (math.abs(vel_y/2) + 0.75)
                elseif vel_y <= -3 then --Cap our gliding movement speed.
-                       phys.speed = phys.speed*2.25
+                       phys.speed = 2.25
                end
                phys.jump = 0
        end,
@@ -172,29 +172,39 @@ hangglider.shot_sound = function (pos)
        })
 end
 
+local function set_fast(name, value)
+       local privs = minetest.get_player_privs(name)
+       privs.fast = value
+       minetest.set_player_privs(name, privs)
+end
+
 local physics_attrs = {"jump", "speed", "gravity"}
 local function apply_physics_override(player, overrides)
-    if player_monoids then
-        for _, attr in pairs(physics_attrs) do
-            if overrides[attr] then
-                player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
-            end
-        end
-    else
-        player:set_physics_override(overrides)
-    end
+       if player_monoids then
+               for _, attr in pairs(physics_attrs) do
+                       if overrides[attr] then
+                               player_monoids[attr]:add_change(player, overrides[attr], "hangglider:glider")
+                       end
+               end
+       else
+               player:set_physics_override(overrides)
+       end
+       if minetest.settings:get_bool("hangglider_no_fast") then
+               set_fast(player:get_player_name(), nil)
+       end
 end
 
 local function remove_physics_override(player, overrides)
-    for _, attr in pairs(physics_attrs) do
-        if overrides[attr] then
-            if player_monoids then
-                player_monoids[attr]:del_change(player, "hangglider:glider")
-            else
-                player:set_physics_override({[attr] = 1})
-            end
-        end
-    end
+       for _, attr in pairs(physics_attrs) do
+               if overrides[attr] then
+                       if core.global_exists("player_monoids") then
+                               player_monoids[attr]:del_change(player, "hangglider:glider")
+                       else
+                               player:set_physics_override({[attr] = 1})
+                       end
+               end
+       end
+       set_fast(player:get_player_name(), true)
 end
 
 local step_v
@@ -239,18 +249,18 @@ minetest.register_entity("hangglider:glider", {
                                        end
                                end
                                if not hangglider.can_fly(pname,pos) then
-                                   if not self.warned then -- warning shot
+                                       if not self.warned then -- warning shot
                                                self.warned = 0
                                                hangglider.shot_sound(pos)
                                                minetest.chat_send_player(pname, "Protected area! You will be shot down in two seconds by anti-aircraft guns!")
-                                   end
-                                   self.warned = self.warned + dtime
-                                   if self.warned > 2 then -- shoot down
+                                       end
+                                       self.warned = self.warned + dtime
+                                       if self.warned > 2 then -- shoot down
                                                player:set_hp(1)
                                                player:get_inventory():remove_item("main", ItemStack("hangglider:hangglider"))
                                                hangglider.shot_sound(pos)
                                                canExist = false
-                                   end
+                                       end
                                end
                                if not canExist then