Page 1 of 1

[MOD] Melee weapons api! Uses raycasting! [w_api][git][v2+]

Posted: Wed Sep 25, 2019 03:12
by Stix
Image
Notice: You will need MT 5.1.0 or newer to run this mod
This is my attempt at improving combat mechanics via raycasting.

This mod provides an api to easily add melee weapons like the following:

Code: Select all

w_api.register_weapon("w_api:sword", {
    description = "Large Sword", --item description
    inventory_image = "w_api_sword.png", --inventory image
    primary_use = {
       ent_bl = true, --if true multiple rays in the same swing cant 'hit' the same ent
       crit_mp = 1.5, --value for damage to be multiplied by when the user gets a critical hit
       kb_mp = 2, --value for knockback vector to be multiplied by
       swing_delay = 0.3, --delay till start of swing [in seconds]
       slash_dir = 0, --direction of weapon slash, "right" is left -> right, "left" is right -> left
       dmg = 2, --the amount of damage to deal to the target object
       delay = 0.1, --delay between each raycast [in seconds]
       depth = 1, --how many ents any individual raycast can damage
       range = 4, --range of weapon [in meters]
       spread = 10, --offset between rays [in degrees]
       amount = 4 --amount of total raycasts on either side of the center ray, set to 1 for only the center ray
    }
})
Spoiler
Break-down of all the current features:
Since 1.0.0:
  • Knockback for entities and players per raycast, knockback is calculated by the hitters lookdir multiplied by the magnitude of the players velocity --todo, make knockback for each ray calculated by its dir
  • Directional-slashes
  • Customizable 'swing-arcs'
  • Swing-delay per-weapon
  • Swing-time per-weapon
  • Option to be able to damage several mobs deep into a crowd
Since 2.0.0:
  • Critical hits and settable multiplier
  • Entity blacklisting
  • Settable knockback multiplier
  • New more logical names for some variables
  • Partial secondary attack support
Since 2.0.1:
  • Updated for complete secondary attack support since engine issue is fixed (ik im late)
  • Fixed forum post documentation (wasn't up to date)
  • Fixes?
Spoiler
  • Would have finished this sooner if i hadn't procrastinated --check
  • Crappy texture for example sword --check
  • Commented out debug statements left in --check
Licensing:
Everything is licensed under MIT

Credits:
Special thanks to UMTD users Warr1024 --for helping me with some fancy-pants vector math to get me started and GreenDimond --for coming up with a solution to prevent sword spamming

Dependencies:
None!

Downloads:
Github Repo

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][v1]

Posted: Wed Sep 25, 2019 04:54
by TumeniNodes
Stix wrote:Check attachments: ill probably create a github repo later
Yesssss.... come to the dark side.... They all float down here...

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Wed Sep 25, 2019 18:51
by Stix
Update: Now on ContentDB!

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Wed Sep 25, 2019 21:55
by Extex
Cool idea!

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Wed Sep 25, 2019 22:24
by texmex
Excellent, been waiting for this!

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Thu Sep 26, 2019 21:21
by Stix
Update time!:
Changes:
  • IMPORTANT!: a potential memory leak was fixed, be sure to update your copies!
  • added entity blacklisting, when set to true this means multiple rays from a single sword swing cannot hit the same entity, in order to only deal the specified damage to each entity intersected by a ray
  • added knockback multiplier, change this to increase/decrease knockback per-weapon
  • added critical-hits! When a ray deals damage to a mob when the swinger has a downwards velocity, the hit is considered a critical hit and damage is the weapons damage multiplied by the critical hit multiplier
  • changed the name of some variables to be more self-explanatory and made all weapon-specific values go inside the table
  • added support for secondary attacks! unfortunately this isnt completely usable yet due to lacking a item-def on_rmb callback that runs no matter what the pointed_thing is, but the support is there via major restructuring of the api
I will update the OT and add a new ContentDB release soonish, for now you can get the latest code at the git repo

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Sat Sep 28, 2019 13:34
by Chem871
Nice idea.

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Mon Oct 07, 2019 20:43
by texmex
Is there a way to debug with visible rays somehow?

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Wed Oct 09, 2019 00:52
by Stix
Sorry for the late reply, but yeah. if you check the api code you'll see there's a commented out line for spawning particles at the intersection point of each ray, that is what i used

EDIT: https://github.com/Cahrs/w_api/blob/master/api.lua#L80

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Wed Oct 09, 2019 04:55
by texmex
Very good, thanks!

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Sat Oct 12, 2019 11:44
by texmex
The particle guide doesn't seem to show when using "Large Sword"…

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Sun Oct 13, 2019 18:35
by Stix
"particle guide"? im not sure what your referring to, please be more specific.

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Sun Oct 13, 2019 20:01
by texmex
Sorry, I expected one type of visual feedback with the commented out line but reading again I understand that it’s a little different.

Re: [MOD] Melee weapons api! Uses raycasting! [w_api][git][v

Posted: Thu Mar 26, 2020 21:23
by Stix
Update, nothing fancy, just check main descrip.