Page 1 of 1

[Mod] Instant Kill Weapons for Certain Monsters

Posted: Thu Nov 22, 2012 11:35 pm
by pferguso
I had an idea for acquiring weapons that will instantly kill a certain type of monster e.g "Spider Slayer", "Ogre's Bane", etc. Here is how I did it:

1. Create a script_entity in your dungeon and call it "super_weapon_script." Place the following Code within it:
SpoilerShow
lastWeaponUsed = "none"
function getLastWeaponUsed()
return lastWeaponUsed
end
function setLastWeaponUsed(sender, theWeapon)
lastWeaponUsed = theWeapon.name
end
2. Create a cloneObject of the weapon that you would like to use as a super weapon, and put it in your items.lua
SpoilerShow
cloneObject{
name = "spiders_bane",
skill = "daggers",
requiredLevel = 2,
uiName = "Spider's Bane",
resistPoison = 30,
coolDownTime = 2,
attackSwipe = "horizontal",
baseObject = "assassin_dagger",
impactSound = "impact_blade",
attackPower = 15,
attackMethod = "meleeAttack",
damageType = "physical",
gameEffect = "*Arachnids*",
description = "This dagger is especially effective against spiders",
onUse = function()
hudPrint("take that!");
end,
}
3. Create a custom_party.lua script and place the following code in it: Make sure you include this file in your init.lua:
SpoilerShow
cloneObject{
name = "party",
baseObject = "party",
onAttack = function(champion, weapon)
local super_weapon_script = findEntity("super_weapon_script")
if super_weapon_script then
super_weapon_script:setLastWeaponUsed(weapon)
end
return true
end,

}
4. Create a monster clone of the monster that you would like to instant kill with the desired weapon. This monster clone goes in Monsters.lua:
SpoilerShow
cloneObject{
name = "my_spider",
baseObject = "spider",
health = 30,
immunities = { "poison" },
onDamage = function(monster, amount, damageType)
if damageType == "physical" then
local super_weapon_script = findEntity("super_weapon_script")
if super_weapon_script then
local spiders_bane = "spiders_bane"
if super_weapon_script:getLastWeaponUsed() == spiders_bane then
monster:setHealth(0)
end
end
end
return true
end,
}

That's pretty much it. So to recap what happens, your party registers the last weapon used and stores its name into the super_weapon_script. Then the monster checks to see if the super_weapon_script exists if he gets hit, and if he was hit by the super_weapon, his health is set to 0.

Comments welcome.

Re: [Mod] Instant Kill Weapons for Certain Monsters

Posted: Fri Nov 23, 2012 12:04 am
by msyblade
I could see this leading to blunt/slash resistance, thrown/missile immunity, etc. Thank you!

Re: [Mod] Instant Kill Weapons for Certain Monsters

Posted: Fri Nov 23, 2012 8:54 am
by Kuningas
SetHealth to zero actually results in an invulnerable monster, I think, but you should be able to handle that with a damage function. I'm not entirely sure, so don't fix it if it isn't broken.

And I very much like the idea! (especially regarding spiders -- I'm no arachnophobe, but damn those things, just damn ; D)

Re: [Mod] Instant Kill Weapons for Certain Monsters

Posted: Fri Nov 23, 2012 12:01 pm
by Komag
Yeah, you would need to do a damage tile, not set health, but that shouldn't be too difficult. Nice script :)

Re: [Mod] Instant Kill Weapons for Certain Monsters

Posted: Mon Nov 26, 2012 12:48 pm
by akroma222
Very interesting! :D

Re: [Mod] Instant Kill Weapons for Certain Monsters

Posted: Mon Nov 26, 2012 6:36 pm
by pferguso
Kuningas wrote:SetHealth to zero actually results in an invulnerable monster, I think, but you should be able to handle that with a damage function. I'm not entirely sure, so don't fix it if it isn't broken.

And I very much like the idea! (especially regarding spiders -- I'm no arachnophobe, but damn those things, just damn ; D)

When I tried it, it didn't result in an invulnerable monster, but it killed it outright. But you're right, a damage tile would definitely do the trick too.