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

User avatar
LMD
Member
 
Posts: 528
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

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

by LMD » Wed Jun 20, 2018 17:06

Player punchback
This (small) mod adds player punchback. 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

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 Jun 21, 2018 10:09, edited 2 times in total.
 

User avatar
Stix
Member
 
Posts: 1119
Joined: Fri Aug 04, 2017 14:19
Location: USA
IRC: Stix + Stix_
In-game: Stix

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

by Stix » Wed Jun 20, 2018 18:50

First of all it should be called "knockback" not "punchback", and second a demonstration video would be nice :P.
Ignore this.
Need to know something? "Google it" --GreenDimond
Next release of your favorite game? "Bugfixes" --Wuzzy
[OLD]The new Minetest-offtopic can be found here: https://minetestoftopic.createaforum.com/index.php
 

entuland
Member
 
Posts: 109
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 » Fri Jun 22, 2018 10:43

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: 528
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo
 

entuland
Member
 
Posts: 109
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 » Fri Jun 22, 2018 11:41

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: 528
Joined: Sat Apr 08, 2017 08:16
Location: Somewhere over the Rainbow : Bonn, Germany
GitHub: appgurueu
In-game: LMD + PRO_LMD + Limo

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

by LMD » Fri Jun 22, 2018 12:56

well, extensive testing would require multiplayer ? and i havent got that many people around me whose time i can waste.
 

entuland
Member
 
Posts: 109
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 » Fri Jun 22, 2018 13:38

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.
 


Return to WIP Mods



Who is online

Users browsing this forum: No registered users and 9 guests