I have scripted a very rudimentary returning axe (should be easy to modify to a hammer). By rudimentary I mean it currently teleports back into the thrower's hand... With a bit more work I'm sure I can add a projectile of the axe flying back etc.
It makes use of the party hook - onAttack to determine the thrower of the weapon and a monster hook - onProjectileHit to determine what the projectile was, and when to return it.
add this hook to a clone of the party... probably in
init.lua
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion,weapon)
return party_script.weaponCheck(champion,weapon)
end,
}
add this script to your
monsters.lua file to clone every monster listed and add the onProjectileHit hook
Code: Select all
local monstersList = {
"crab","crowern","cube","goromorg","green_slime","herder","herder_big","herder_small","herder_swarm","ice_lizard","ogre","scavenger","scavenger_swarm","shrakk_torr","skeleton_archer","skeleton_archer_patrol","skeleton_patrol","skeleton_warrior","snail","spider","tentacles","uggardian","warden","wyvern"
}
for i=1,# monstersList do
cloneObject{
name = monstersList[i],
baseObject = monstersList[i],
onProjectileHit = function(monster, weapon)
return party_script.projectileCheck(monster,weapon)
end,
}
end
note party_script refers to a script entity in your dungeon.. i tend to use this entity for any party related hooks (and because I am storing a value in a variable I needed to use this for the monster hook too!)
create this object in
items.lua
Code: Select all
cloneObject{
name ="returning_throwing_axe",
baseObject="throwing_axe",
uiName = "Throwing Axe of Returning",
sharpProjectile = false,
stackable = false,
}
I made it non-stackable so that the champion would have an empty hand once he'd thrown it... I also made it non-sharp so that it doesn't get 'carried' by the monster.. otherwise the call to destroy() the item will crash the game.
finally add these scripts to a
party_script entity in your dungeon
Code: Select all
function weaponCheck(champion,weapon)
if weapon ~= nil
then
if weapon.name == "returning_throwing_axe" then
thrower = champion
-- hudPrint(thrower:getName())
end
end
end
function projectileCheck(monster,weapon)
if weapon.name == "returning_throwing_axe" then
-- hudPrint("Returning Throwing Axe with ID " .. weapon.id)
if findEntity(weapon.id) ~= nil then
-- hudPrint(thrower:getName())
weapon:destroy()
if thrower:getItem(7) == nil then
thrower:insertItem(7,spawn("returning_throwing_axe"))
elseif thrower:getItem(8) == nil then
thrower:insertItem(8,spawn("returning_throwing_axe"))
end
end
end
end
When I have more time I'll work on having the axe look like it's fly back from the monster.