... and wanted to add a laser sound when the weapon is used. That is now working with the following code:
Code: Select all
minetest.register_tool("laser_mod:red_sword", {
...
on_use = function()
minetest.sound_play("laser_mod")
end,
...
})
Code: Select all
minetest.register_tool("laser_mod:red_sword", {
...
on_use = function()
minetest.sound_play("laser_mod")
end,
...
})
Code: Select all
after_use = function(itemstack, user, node, digparams)
If a craftitem is to be used then it'll be very tricky to get the damage amount if there are more damage groups than just 'fleshy'...Krock wrote:on_use overrides the normal function of tools. Use a craftitem and add the wear manually or use (as above said) the after_use function.
I've been looking through other lua examples, trying to understand how to use the function but not quite sure how to implement it. I've been doing lots of trial and error, but I have been unable to get it to work. Do you have an example? Or can point me to documentation? Thanks.HeroOfTheWinds wrote:Hmm, it may not be the same, but try using:If the problem persists, you must handle the punching code manually by doing operations on the pointed_thing passed by the function.Code: Select all
after_use = function(itemstack, user, node, digparams)
Code: Select all
minetest.register_tool("laser_mod:red_sword", {
...
on_use = function()
minetest.sound_play("laser_mod")
end,
after_use = function(itemstack, user, node, digparams)
what to do here?
end,
...
})
Ok, I tried this, and it works! The only downside is that the sound doesn't play if you punch nothing. Is there a way to make the sound play on every swing?4aiman wrote:You are to put sound_play into AFTER_use and DO NOT use on_use :)
Thanks for the suggestion. I am looking through docs to try and find how to use this. Maybe this will be my ticket...4aiman wrote:Why not use get_player_controls() ?
You get the controls and if a LMB was "pressed" and your player:get_wielded_item():get_name == <name of your sword> then play your sound. ;)
*Names of the functions I've mentioned are not 100% exact.
Code: Select all
after_use = function(itemstack, user, node, digparams)
minetest.sound_play("laser_mod")
itemstack:add_wear(digparams.wear)
return itemstack
end
Code: Select all
on_use = function(itemstack, user, pointed_thing)
print("on_use, play sound")
minetest.sound_play("laser_mod")
return nil
end,
after_use = function(itemstack, user, node, digparams)
print("after_use, use sword")
itemstack:add_wear(digparams.wear)
return itemstack
end,
It is now working using get_player_controls(). Thanks everyone for your input. Mod here: viewtopic.php?f=9&t=106424aiman wrote:Why not use get_player_controls() ?
You get the controls and if a LMB was "pressed" and your player:get_wielded_item():get_name == <name of your sword> then play your sound. ;)
*Names of the functions I've mentioned are not 100% exact.
Users browsing this forum: No registered users and 7 guests