[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
+ Spoiler
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
(60.68 KiB) Not downloaded yet
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: 2853
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...
Ich mag keine grünen Eier und Schinken, ich mag sie nicht Sam I Am

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: 184
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!
Player of PK, RIP. Creator of the light_tool and motorbike mods. Working on another mod which should be coming soon!

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

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

by texmex » Post

Excellent, been waiting for this!
Mods | Support Mesehub: bc1qluuests9rxmlnvpjrhsnyjg9ucwy6z3r0y3srw

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: 947
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 again? I forgot.

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

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

by texmex » Post

Is there a way to debug with visible rays somehow?
Mods | Support Mesehub: bc1qluuests9rxmlnvpjrhsnyjg9ucwy6z3r0y3srw

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: 1751
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

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

by texmex » Post

Very good, thanks!
Mods | Support Mesehub: bc1qluuests9rxmlnvpjrhsnyjg9ucwy6z3r0y3srw

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

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"…
Mods | Support Mesehub: bc1qluuests9rxmlnvpjrhsnyjg9ucwy6z3r0y3srw

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: 1751
Joined: Mon Jul 11, 2016 21:08
GitHub: tacotexmex
In-game: texmex

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.
Mods | Support Mesehub: bc1qluuests9rxmlnvpjrhsnyjg9ucwy6z3r0y3srw

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: apercy and 3 guests