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

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

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

by Stix » Post

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
Attachments
screenshot_20190925_142557.png
screenshot_20190925_142557.png (60.68 KiB) Viewed 1426 times
Last edited by Stix on Fri Mar 27, 2020 17:44, edited 23 times in total.
Hey, what can i say? I'm the bad guy.

User avatar
TumeniNodes
Member
Posts: 2941
Joined: Fri Feb 26, 2016 19:49
GitHub: TumeniNodes
IRC: tumeninodes
In-game: TumeniNodes
Location: in the dark recesses of the mind
Contact:

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

by TumeniNodes » Post

Stix wrote:Check attachments: ill probably create a github repo later
Yesssss.... come to the dark side.... They all float down here...
A Wonderful World

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

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

by Stix » Post

Update: Now on ContentDB!
Hey, what can i say? I'm the bad guy.

User avatar
Extex
Member
Posts: 244
Joined: Wed Mar 14, 2018 23:14
GitHub: Extex101
In-game: Extex

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

by Extex » Post

Cool idea!
Creator of jelys_pizzaria and motorbike, and player of persistent kingdoms. RIP

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

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

by texmex » Post

Excellent, been waiting for this!

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

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

by Stix » Post

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
Hey, what can i say? I'm the bad guy.

Chem871
Member
Posts: 999
Joined: Sat Aug 19, 2017 21:49
GitHub: Chemguy99
In-game: Chem Nyx
Location: My Basement's Attic

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

by Chem871 » Post

Nice idea.
What is SCP-055?

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

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

by texmex » Post

Is there a way to debug with visible rays somehow?

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

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

by Stix » Post

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
Hey, what can i say? I'm the bad guy.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

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

by texmex » Post

Very good, thanks!

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

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

by texmex » Post

The particle guide doesn't seem to show when using "Large Sword"…

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

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

by Stix » Post

"particle guide"? im not sure what your referring to, please be more specific.
Hey, what can i say? I'm the bad guy.

User avatar
texmex
Member
Posts: 1753
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: tacotexmex

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

by texmex » Post

Sorry, I expected one type of visual feedback with the commented out line but reading again I understand that it’s a little different.

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

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

by Stix » Post

Update, nothing fancy, just check main descrip.
Hey, what can i say? I'm the bad guy.

Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests