Compare commits

..

2 commits

Author SHA1 Message Date
philipmi
d05b22e38d Adapt playerplus mod 2021-06-03 16:46:57 +02:00
philipmi
6cedcc7b84 Add playerplus mod 2021-06-03 15:19:35 +02:00
8 changed files with 375 additions and 0 deletions

View file

@ -0,0 +1,63 @@
PlayerPlus mod for minetest
This mod lets the player move faster when walking on ice, slows down the player
when walking on snow, makes touching a cactus hurt and suffocates player when
their head is inside a solid node... enjoy!
https://forum.minetest.net/viewtopic.php?t=10090&p=153667
- 0.1 - Initial release
- 0.2 - 3d_armor mod compatibility
- 0.3 - Optimized code
- 0.4 - Added suffocation when inside nodes
- 0.5 - Slow down when walking in water
- 0.6 - Code tidy and tweak, increased damage by cactus and suffocation
- 0.7 - Added global 'playerplus' table to hold node names gathered around player
- 0.8 - Player knock-back added
- 0.9 - 'on_walk_over' function support added for nodes
- 1.0 - Update to newer functions, requires Minetest 0.4.16 and above to run
- 1.1 - Added support for player_monoids mod (thanks tacotexmex)
- 1.2 - Added POVA support, tweaked code slightly
- 1.3 - Add setting under Advanced to enable older sneak glitch movement
- 1.4 - Add minetest 5.0 check for knockback y_offset
- 1.5 - Use Minetext 5.x functions for proper player knockback
API:
Every second the mod checks which node the player is standing on, which node is
at foot and head level and stores inside a global table to be used by mods:
- playerplus[name].nod_stand
- playerplus[name].nod_feet
- playerplus[name].nod_head
Older Sneak-glitch:
When enabled this allows players to use the old sneak glitch movement that lets
you climb sneak ladders and jump double blocks when using sneak+jump,
old_sneak = false
Player Knock-back:
This feature is enabled by default and can be turned off by adding this line to
your minetest.conf file:
player_knockback = false
Knock-back is determined by tool strength or a specific 'knockback' value which
can be added to the tool damage_groups itself. A player with the privelage
'no_knockback' will not be affected when it's enabled.
Node 'on_walk_over' function:
When added to a node definition the function will be called whenever a player
walks on top of the node e.g.
on_walk_over = function(pos, node, player)
print ("---", node.name, player:get_player_name() )
end

View file

@ -0,0 +1 @@
Add speed effects, suffocation and cactus damage to players.

View file

@ -0,0 +1,282 @@
--[[
walking on ice makes player walk faster,
stepping through snow slows player down,
touching a cactus hurts player,
suffocation when head is inside solid node,
player knock-back effects when punched.
PlayerPlus by TenPlus1
]]
playerplus = {}
-- detect minetest 5.0
local mt50 = minetest.registered_nodes["default:permafrost"]
-- get node but use fallback for nil or unknown
local node_ok = function(pos, fallback)
fallback = fallback or "air"
local node = minetest.get_node_or_nil(pos)
if node and minetest.registered_nodes[node.name] then
return node.name
end
return fallback
end
local time = 0
minetest.register_globalstep(function(dtime)
time = time + dtime
-- every 1 second
if time < 1 then
return
end
-- reset time for next check
time = 0
-- define locals outside loop
local name, pos, ndef, def, nslow, nfast, prop
-- get list of players
local players = minetest.get_connected_players()
-- loop through players
for _,player in pairs(players) do
-- who am I?
name = player:get_player_name()
if name and playerplus[name] then
-- where am I?
pos = player:get_pos()
-- what is around me?
playerplus[name].nod_stand = node_ok({
x = pos.x, y = pos.y - 0.1, z = pos.z})
-- Does the node below me have an on_walk_over function set?
ndef = minetest.registered_nodes[playerplus[name].nod_stand]
if ndef and ndef.on_walk_over then
ndef.on_walk_over(pos, ndef, player)
end
prop = player:get_properties()
-- node at eye level
playerplus[name].nod_head = node_ok({
x = pos.x, y = pos.y + prop.eye_height, z = pos.z})
-- node at foot level
playerplus[name].nod_feet = node_ok({
x = pos.x, y = pos.y + 0.2, z = pos.z})
-- are we standing on any nodes that speed player up?
nfast = nil
if playerplus[name].nod_stand == "default:ice" then
nfast = true
end
-- are we standing on any nodes that slow player down?
nslow = nil
if playerplus[name].nod_stand == "default:snow"
or playerplus[name].nod_stand == "default:snowblock" then
nslow = true
end
-- apply speed changes
if nfast and not playerplus[name].nfast then
physics.set(name, "playerplus:nfast", {speed = 1.2})
playerplus[name].nfast = true
elseif not nfast and playerplus[name].nfast then
physics.remove(name, "playerplus:nfast")
playerplus[name].nfast = nil
end
-- apply slowdown changes
if nslow and not playerplus[name].nslow then
physics.set(name, "playerplus:nslow", {speed = 0.85})
playerplus[name].nslow = true
elseif not nslow and playerplus[name].nslow then
physics.remove(name, "playerplus:nslow")
playerplus[name].nslow = nil
end
-- Is player suffocating inside a normal node without no_clip privs?
local ndef = minetest.registered_nodes[playerplus[name].nod_head]
if not ctf_match.is_in_build_time()
and ndef.walkable == true
and ndef.drowning == 0
and ndef.damage_per_second <= 0
and ndef.groups.disable_suffocation ~= 1
and ndef.drawtype == "normal"
and not minetest.check_player_privs(name, {noclip = true}) then
if player:get_hp() > 0 then
player:set_hp(player:get_hp() - 2)
end
end
-- am I near a cactus?
local near = minetest.find_node_near(pos, 1, "default:cactus")
if near then
-- am I touching the cactus? if so it hurts
for _,object in pairs(minetest.get_objects_inside_radius(near, 1.1)) do
if object:get_hp() > 0 then
object:set_hp(object:get_hp() - 2)
end
end
end
end -- END if name
end
end)
-- check for old sneak_glitch setting
local old_sneak = minetest.settings:get_bool("old_sneak")
-- set to blank on join (for 3rd party mods)
minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
playerplus[name] = {}
playerplus[name].nod_head = ""
playerplus[name].nod_feet = ""
playerplus[name].nod_stand = ""
-- apply old sneak glitch if enabled
if old_sneak then
player:set_physics_override({new_move = false, sneak_glitch = true})
end
end)
-- clear when player leaves
minetest.register_on_leaveplayer(function(player)
playerplus[ player:get_player_name() ] = nil
end)
-- add privelage to disable knock-back
minetest.register_privilege("no_knockback", {
description = "Disables player knock-back effect",
give_to_singleplayer = false})
-- is player knock-back effect enabled?
if minetest.settings:get_bool("player_knockback") == true then
-- player knock-back function
local punchy = function(
player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
-- disable knockback during build time
if ctf_match.is_in_build_time() then return end
-- check if player and hitter are in the same team
if ctf.player(player:get_player_name()).team == ctf.player(hitter:get_player_name()).team then
return
end
if not dir then return end
-- check if player has 'no_knockback' privelage
local privs = minetest.get_player_privs(player:get_player_name())
if privs["no_knockback"] then
return
end
local damage = 0
-- get tool damage
if tool_capabilities then
local armor = player:get_armor_groups() or {}
local tmp
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
tmp = time_from_last_punch / (tool_capabilities.full_punch_interval or 1.4)
if tmp < 0 then
tmp = 0.0
elseif tmp > 1 then
tmp = 1.0
end
damage = damage + (tool_capabilities.damage_groups[group] or 0) * tmp
-- limit knockback
if damage > 8 then
damage = 8
end
end
-- disable knockback for swords
if tool_capabilities.damage_groups["sword"] then
damage = 0
end
-- check for knockback value
if tool_capabilities.damage_groups["knockback"] then
damage = tool_capabilities.damage_groups["knockback"]
end
end
-- END tool damage
-- print ("---", player:get_player_name(), damage)
-- knock back player
player:add_velocity({
x = dir.x * (damage * 2),
y = -1,
z = dir.z * (damage * 2)
})
end
minetest.register_on_punchplayer(punchy)
end -- END if
minetest.register_tool("playerplus:stick", {
description = "KB Stick",
inventory_image = "default_stick.png",
wield_image = "default_stick.png",
tool_capabilities = {
full_punch_interval = 1.4,
damage_groups = {fleshy = 0, knockback = 11},
},
})
--[[
minetest.override_item("default:mese", {
on_walk_over = function(pos, node, player)
print ("---", node.name, player:get_player_name() )
end
})
]]

View file

@ -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.

View file

@ -0,0 +1,4 @@
name = playerplus
depends = ctf_match, physics, ctf
optional_depends = default
description = Add speed effects, suffocation and cactus damage to players.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

@ -0,0 +1,4 @@
# If enabled players are knocked back when hit by mobs or other players
player_knockback (Player knockback) bool false
# If enabled the players use the old sneak glitch and movements
old_sneak (Use old sneak glitch) bool false

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B