[Mod]Player knockback[punchback]

Post Reply
User avatar
LMD
Member
Posts: 1397
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

[Mod]Player knockback[punchback]

by LMD » Post

Player knockback
This (small) mod adds player knockback. Written for Magic-CTF by LMD. It does not use mover entities for several reasons, but instead player:move_to. The main task of this mod is to use player:move_to properly and not to move players into solid blocks. If there are errors, please let me know on GitHub.

API :
There are 6 global variables concerning punchback which can be modified from other mods. How they work can be seen in the commented source.

License : GPLv3

Depends : None

Download/Source(GitHub) : https://github.com/appgurueu/punchback

Code:

Code: Select all

PUNCHBACK_STEPS=5 --Punchback simulation accuracy
DEFAULT_PUNCHBACK=0.2 --Default punchback strenght in blocks - used when tool hasnt got punchback capability
PUNCHBACK_RELOAD=1 --Punchback=factor*tool punchback*time from last punch, reload is factor
PUNCHBACK_MAX=3 --beyond 3 s time from last punch there's no difference
PLAYER_SIZE=0.6 --Player collisionbox simulation size in percent, eg 0.6 means 60 percent of real size

local factor=1

minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
    local orig=vector.multiply(hitter:get_look_dir(),(pcall(tool_capabilities.punchback) or DEFAULT_PUNCHBACK) * math.min(PUNCHBACK_RELOAD*time_from_last_punch,PUNCHBACK_MAX)) --Calc punchback vector * strength
    local mult=vector.divide(vector.normalize(orig),PUNCHBACK_STEPS) --Divide by steps
    local pos=player:get_pos() --Player pos
    for i=0,math.ceil(vector.length(orig)*PUNCHBACK_STEPS) do --Simulation
        local d=PLAYER_SIZE
        for _,y in pairs({-1*d,0,1*d}) do
            for _,x in pairs({-0.5*d,0,0.5*d}) do
                for _,z in pairs({-0.5*d,0,0.5*d}) do
                    local v=vector.add(vector.add(pos,{x=x,y=y,z=z}),mult)
                    local floor={x=math.floor(v.x*factor+0.5)/factor,y=math.floor(v.y*factor+0.5)/factor,z=math.floor(v.z*factor+0.5)/factor}
                    if not (minetest.get_node(floor).walkable==true) then --Stop moving when colliding with solid node
                        goto overjump
                    end
                end
            end
        end
        pos=vector.add(pos,mult)
    end
    ::overjump::
    player:moveto(pos) --Actual punchback
end)
Last edited by LMD on Thu Nov 08, 2018 19:56, edited 3 times in total.
My stuff: Projects - Mods - Website

User avatar
Stix
Member
Posts: 1385
Joined: Fri Aug 04, 2017 14:19
IRC: nil
In-game: Stix [+alts]
Location: USA

Re: [MOD][API][TINY][SERVER][PVP]Player punchback[punchback]

by Stix » Post

First of all it should be called "knockback" not "punchback", and second a demonstration video would be nice :P.
Hey, what can i say? I'm the bad guy.

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][PVP]Player punchback[punchback]

by entuland » Post

Stix wrote:First of all it should be called "knockback" not "punchback", and second a demonstration video would be nice :P.
Yep, a "punchback" mod should be one where you puch a node and the node punches back at you :P

LMD: nice mod in any case, improves fighting mechanics nicely :)

User avatar
LMD
Member
Posts: 1397
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by LMD » Post

thanks :) does it work properly ? didn't test it that much...
My stuff: Projects - Mods - Website

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by entuland » Post

LMD wrote:thanks :) does it work properly ? didn't test it that much...
ehehehe, you just asked for this mod to be moved to the released mods section of the forum and you didn't extensively test it?

User avatar
LMD
Member
Posts: 1397
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by LMD » Post

well, extensive testing would require multiplayer ? and i havent got that many people around me whose time i can waste.
My stuff: Projects - Mods - Website

entuland
Member
Posts: 123
Joined: Wed May 09, 2018 15:47
GitHub: entuland
IRC: entuland
In-game: entuland

Re: [MOD][API][TINY][SERVER][GIT]Player knockback[punchback]

by entuland » Post

LMD wrote:well, extensive testing would require multiplayer ? and i havent got that many people around me whose time i can waste.
Not a multiplayer myself, but I guess you would need to test it on a live server, considering the scope of your mod.

You could still run multiple instances of MT locally and connect to the same server to test it on your own without wasting anyone else's time. Just punch one of your alter-egos running on a different instance and test everything out.

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: [Mod]Player knockback[punchback]

by Joseph16 » Post

is this mod still being worked on or maintained?
Testin' mines since 1989

User avatar
LMD
Member
Posts: 1397
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: [Mod]Player knockback[punchback]

by LMD » Post

Probably not. I will eventually decide to do an upgrade for 5.0
My stuff: Projects - Mods - Website

User avatar
Joseph16
Member
Posts: 310
Joined: Tue Dec 06, 2016 05:35
In-game: smb3

Re: [Mod]Player knockback[punchback]

by Joseph16 » Post

I installed it, but when I hit a player no knockback occurs. Whats the deal banana peel?
Testin' mines since 1989

User avatar
FreeGamers
Member
Posts: 650
Joined: Sat May 25, 2019 00:15
GitHub: is proprietary I use NotABug
Location: United States
Contact:

Re: [Mod]Player knockback[punchback]

by FreeGamers » Post

LMD wrote:Probably not. I will eventually decide to do an upgrade for 5.0
It crashes my server on 5.0.1 during any hit from a mob.
FreeGamers.org has moved to MeseCraft.net | FreeGamers on this forum is now MeseCraft

User avatar
LMD
Member
Posts: 1397
Joined: Sat Apr 08, 2017 08:16
GitHub: appgurueu
IRC: appguru[eu]
In-game: LMD
Location: Germany
Contact:

Re: [Mod]Player knockback[punchback]

by LMD » Post

I should've sayed that it has not been upgraded yet to 5.0.1, but your bug probably is easy to fix...
My stuff: Projects - Mods - Website

Post Reply

Who is online

Users browsing this forum: No registered users and 37 guests