Damage weapons on hitting person or mob?

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

Damage weapons on hitting person or mob?

by mcfan » Tue Apr 01, 2014 12:40

Since for some reason I can't post on Mod releases I'm posting this here.

Is there a mod or some code that I can add to the default to make it so when one hits a person or mob it damages the weapon? I saw in the castle mod the battleaxe and it gets damaged when you hit a mob but I don't know about hitting a person.
Love MINECRAFT... will settle for Minetest
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Tue Apr 01, 2014 12:49

.esu uoy dom eht no sdneped sbom gnittiH .reyalp htiw ti od ot )sloot eht gnidirrevo ebyam tpecxe( yaw on si erehT
 

Amaz
Member
 
Posts: 328
Joined: Wed May 08, 2013 08:26
GitHub: Amaz1
IRC: Amaz
In-game: Amaz

by Amaz » Tue Apr 01, 2014 13:24

PilzAdam wrote:.esu uoy dom eht no sdneped sbom gnittiH .reyalp htiw ti od ot )sloot eht gnidirrevo ebyam tpecxe( yaw on si erehT

Is there any way to do it with your simple mobs mod?
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Tue Apr 01, 2014 14:46

Why are you speaking in german piltzadam. I can't understand you.
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Tue Apr 01, 2014 14:56

In simple mobs I added the following code to the on_punch function to add wear to tools/weapons

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local weapon = hitter:get_wielded_item()
            if weapon:get_definition().tool_capabilities ~= nil then
                local wear = ( weapon:get_definition().tool_capabilities.full_punch_interval / 75 ) * 65535
                weapon:add_wear(wear)
                hitter:set_wielded_item(weapon)
            end


My logic was the better weapons have a lower full punch interval so with this formula the better weapons wear slower. I didn't want to dig into groupcaps to get the number of uses.
 

User avatar
Linxx
Member
 
Posts: 401
Joined: Wed May 16, 2012 00:37

by Linxx » Tue Apr 01, 2014 16:00

mcfan wrote:Why are you speaking in german piltzadam. I can't understand you.

read from right to left
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Tue Apr 01, 2014 16:39

Lol - that is HARD!
Love MINECRAFT... will settle for Minetest
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 12:07

brandonreese where do I add this code?
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Wed Apr 02, 2014 17:53

If you are using simple mobs, in api.lua, just below

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
on_punch = function(self, hitter)


Somewhere around line 480, I've modded my simple mobs so I don't know the exact line number.
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 18:44

Can I add this to the player.lua to?
Love MINECRAFT... will settle for Minetest
 

User avatar
minermoder27
Member
 
Posts: 127
Joined: Wed Nov 20, 2013 23:24
GitHub: ZNixian
In-game: minermoder27

by minermoder27 » Wed Apr 02, 2014 19:38

player.lua is all about a player's skin and model. No punching code involved.
My best mods:
Buildtest
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Wed Apr 02, 2014 21:28

Too bad. So is there no way to make it so when I hit someone it will damage the weapon?
Love MINECRAFT... will settle for Minetest
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

by BrandonReese » Thu Apr 03, 2014 02:12

You could add an on_use function to each weapon but I wouldn't advise that.
 

User avatar
mcfan
Member
 
Posts: 120
Joined: Wed Mar 26, 2014 15:02

by mcfan » Thu Apr 03, 2014 11:32

Why wouldn't you?
Love MINECRAFT... will settle for Minetest
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 7 guests

cron