forked from thunderdog1138/star_wars
Add files via upload
This commit is contained in:
parent
915f82c811
commit
dc9b47dd47
|
@ -0,0 +1,55 @@
|
|||
# POVA
|
||||
|
||||
Pova gives mod makers a set of easy to use functions that safely apply overrides for player speed, jump height and gravity effects.
|
||||
|
||||
## Settings
|
||||
|
||||
'pova_loop' setting is 1.0 by default and will calculate and set overrides once a second for each player, set to 0.5 for every half a second or 0 to disable.
|
||||
|
||||
## Functions
|
||||
|
||||
pova.add_override = function(name, item, def)
|
||||
|
||||
- Adds a named override which can be used to add or subtract from speed, jump and gravity effects. Custom overrides are also used for specific tasks:
|
||||
|
||||
- "default" sets default values for each of the settings to which overrides are added.
|
||||
- "min" provides a minimum level for each of the settings.
|
||||
- "max" provides a maximum level for each of the settings.
|
||||
- "force" overrides all and forces a value for each setting (e.g setting speed to 0 when sleeping in beds)
|
||||
|
||||
- 'def.priority' can be used to set priorities for custom effects, higher numbers get applied (defaults to 50)
|
||||
|
||||
pova.get_override = function(name, item)
|
||||
|
||||
- Returns the table containing {speed, jump, gravity} for an added item.
|
||||
|
||||
pova.del_override = function(name, item)
|
||||
|
||||
- Removes the override settings for the item named.
|
||||
|
||||
pova.do_override(player)
|
||||
|
||||
- Calculates and sets new overrides instantly, this can be used when the 'pova_loop' setting is false.
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
### 0.1
|
||||
|
||||
- Initial Upload
|
||||
|
||||
### 0.2
|
||||
|
||||
- Added pova.do_override(player) to instantly set overrides on list.
|
||||
- Added 'pova_loop' setting in minetest.conf to disable override calc loop
|
||||
|
||||
### 0.3
|
||||
|
||||
- Added custom override names for special functions "default", "min", "max", "force"
|
||||
- Tweaked test axe to use new settings.
|
||||
|
||||
### 0.4
|
||||
|
||||
- 'pova_loop' now contains loop timer in seconds, 0 to disable
|
||||
- Added def.priority setting to add_override to stop unimportant changes
|
||||
- tweak and optimize code
|
|
@ -0,0 +1,196 @@
|
|||
|
||||
-- global
|
||||
pova = {}
|
||||
|
||||
-- local
|
||||
local pova_list = {}
|
||||
local min, max = math.min, math.max
|
||||
|
||||
-- time each override loop runs, 0 to disable
|
||||
local pova_loop = minetest.settings:get_bool("pova_loop") or 1.0
|
||||
|
||||
-- if enabled activate main loop that totals override list on timer
|
||||
if pova_loop > 0 then
|
||||
|
||||
local timer = 0
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
|
||||
timer = timer + dtime
|
||||
|
||||
if timer < pova_loop then
|
||||
return
|
||||
end
|
||||
|
||||
timer = 0
|
||||
|
||||
-- loop through players and apply overrides
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
pova.do_override(player)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
-- global functions
|
||||
pova.add_override = function(name, item, def)
|
||||
|
||||
-- nil check
|
||||
if not name or not item then return end
|
||||
|
||||
-- priority defaults to 50 when not included
|
||||
def.priority = tonumber(def.priority) or 50
|
||||
|
||||
-- if same item is assigned with lower priority then change ignored
|
||||
if pova_list[name][item]
|
||||
and pova_list[name][item].priority
|
||||
and pova_list[name][item].priority > def.priority then
|
||||
return
|
||||
end
|
||||
|
||||
pova_list[name][item] = def
|
||||
end
|
||||
|
||||
pova.get_override = function(name, item)
|
||||
return pova_list[name][item]
|
||||
end
|
||||
|
||||
pova.del_override = function(name, item)
|
||||
pova_list[name][item] = nil
|
||||
end
|
||||
|
||||
pova.do_override = function(player)
|
||||
|
||||
local name = player:get_player_name()
|
||||
|
||||
-- somehow player list is missing
|
||||
if not pova_list[name] then
|
||||
return
|
||||
end
|
||||
|
||||
-- set base defaults
|
||||
local speed, jump, gravity = 1, 1, 1
|
||||
|
||||
-- check for new defaults
|
||||
if pova_list[name]["default"] then
|
||||
speed = pova_list[name]["default"].speed or 1
|
||||
jump = pova_list[name]["default"].jump or 1
|
||||
gravity = pova_list[name]["default"].gravity or 1
|
||||
end
|
||||
|
||||
-- loop through list of named overrides
|
||||
for id, var in pairs(pova_list[name]) do
|
||||
|
||||
-- skip any custom names
|
||||
if var
|
||||
and id ~= "default"
|
||||
and id ~= "min"
|
||||
and id ~= "max"
|
||||
and id ~= "force" then
|
||||
|
||||
-- add any additional changes
|
||||
speed = speed + (pova_list[name][id].speed or 0)
|
||||
jump = jump + (pova_list[name][id].jump or 0)
|
||||
gravity = gravity + (pova_list[name][id].gravity or 0)
|
||||
end
|
||||
end
|
||||
|
||||
-- make sure total doesn't go below minimum values
|
||||
if pova_list[name]["min"] then
|
||||
speed = max(pova_list[name]["min"].speed or 0, speed)
|
||||
jump = max(pova_list[name]["min"].jump or 0, jump)
|
||||
gravity = max(pova_list[name]["min"].gravity or 0, gravity)
|
||||
end
|
||||
|
||||
-- make sure total doesn't go above maximum values
|
||||
if pova_list[name]["max"] then
|
||||
speed = min(pova_list[name]["max"].speed or speed, speed)
|
||||
jump = min(pova_list[name]["max"].jump or jump, jump)
|
||||
gravity = min(pova_list[name]["max"].gravity or gravity, gravity)
|
||||
end
|
||||
|
||||
-- force values (for things like sleeping in bed when speed is 0)
|
||||
if pova_list[name]["force"] then
|
||||
speed = pova_list[name]["force"].speed or speed
|
||||
jump = pova_list[name]["force"].jump or jump
|
||||
gravity = pova_list[name]["force"].gravity or gravity
|
||||
end
|
||||
|
||||
-- for testing only
|
||||
if name == "singleplayer" then
|
||||
print ("speed: " .. speed .. " / jump: " .. jump .. " / gravity: " .. gravity)
|
||||
end
|
||||
|
||||
-- set new overrides
|
||||
player:set_physics_override(speed, jump, gravity)
|
||||
end
|
||||
|
||||
|
||||
-- set player table on join
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
pova_list[ player:get_player_name() ] = {}
|
||||
pova.do_override(player)
|
||||
end)
|
||||
|
||||
-- reset player table on respawn
|
||||
minetest.register_on_respawnplayer(function(player)
|
||||
pova_list[ player:get_player_name() ] = {}
|
||||
pova.do_override(player)
|
||||
end)
|
||||
|
||||
-- blank player table on leave
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
pova_list[ player:get_player_name() ] = nil
|
||||
end)
|
||||
|
||||
|
||||
-- axe tool to showcase features
|
||||
minetest.register_craftitem("pova:axe", {
|
||||
description = "Test Axe (left to apply, right to remove effects)",
|
||||
inventory_image = "default_tool_steelaxe.png",
|
||||
|
||||
on_use = function(itemstack, user, pointed_thing)
|
||||
|
||||
local name = user:get_player_name()
|
||||
|
||||
-- set new defaults
|
||||
pova.add_override(name, "default", {speed = 2, jump = 3, gravity = 1})
|
||||
|
||||
-- define changes that are added onto defaults
|
||||
pova.add_override(name, "test", {speed = 1, jump = -1, gravity = 0.5})
|
||||
|
||||
--= speed is now 3, jump is 2 and gravity is 1.5
|
||||
|
||||
-- set new minimum for jump
|
||||
pova.add_override(name, "min", {jump = 3})
|
||||
|
||||
-- add new maximum for speed
|
||||
pova.add_override(name, "max", {speed = 2})
|
||||
|
||||
-- add force value for gravity
|
||||
pova.add_override(name, "force", {gravity = 1.2})
|
||||
|
||||
--= speed is now max 2, jump is min 3 and gravity forced to 1.2
|
||||
|
||||
-- this wont get applied because priority is lower than 50
|
||||
pova.add_override(name, "force", {speed = 8, priority = 10})
|
||||
|
||||
-- apply override
|
||||
pova.do_override(user)
|
||||
end,
|
||||
|
||||
on_place = function(itemstack, user, pointed_thing)
|
||||
|
||||
local name = user:get_player_name()
|
||||
|
||||
-- remove changes
|
||||
pova.del_override(name, "min")
|
||||
pova.del_override(name, "max")
|
||||
pova.del_override(name, "force")
|
||||
pova.del_override(name, "test")
|
||||
pova.del_override(name, "default")
|
||||
|
||||
-- apply override
|
||||
pova.do_override(user)
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 TenPlus1
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1 @@
|
|||
name = pova
|
|
@ -0,0 +1,2 @@
|
|||
# POVA recalc loop in seconds (0 to disable)
|
||||
pova_loop (POVA loop number in seconds) float 1.0
|
Loading…
Reference in New Issue