Undead Slayer Skill and Trait definiton help

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Undead Slayer Skill and Trait definiton help

Post by Drakkan »

can you please help me with skill and trait definition ? I am missing the script for the effect itself.



Skill -
this skill should add + 3 damage for every level only against undead creatures (I will add traits = { "undead" }, to undead creatures (like mummy, skeleton etc...)

Code: Select all

defineSkill{
	name = "undead_slayer",
	uiName = "Undead Slayer",
	priority = 20,
	icon = 106,
	description = "You are trained to fight undead creatures. You will gain + 3 damage against undead creatures for each point in this skill. 3rd skill level is giving you minor chance to kill lower undead with one blow and 5th point invested giving you the similar chance for almost any undead.",
	traits = { [3] = "low_undead", [5] = "high_undead" },
-- definition please 
-- on attack if creature trait is { "undead" } gain +3 damage for each point in this skill 
--end,
}

as for the traits - it will again work based on creature trait - lower_undead and higher_undead which I will give to some creatures

Code: Select all

defineTrait{
	name = "low_undead",
	uiName = "Mummy Killer",
	icon = 109,
	description = "You have 10% chance to kill lower undead with one blow (mummy, skeleton archer)",
-- script definition please
-- in case creature trait is lower_undead character has 10% to kill it with one blow (could be solved even like: gain +100 dmg or something like that
--end,
}


defineTrait{
	name = "high_undead",
	uiName = "Vampire Killer",
	icon = 109,
	description = "You have 10% chance to kill any undead with one blow (mummy, skeleton archer, skeleton warrior, undead.",
-- script definition please
-- the same as previous, however checking also higher_undead trait on creature
--	end,
}

thanks for any help in advance
Breath from the unpromising waters.
Eye of the Atlantis
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Undead Slayer Skill and Trait definiton help

Post by GoldenShadowGS »

I looked through the asset packs and can't think of a way to do what you want directly. However, maybe you could change the damage type and make those certain monsters vulnerable that that type of damage.
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Undead Slayer Skill and Trait definiton help

Post by cameronC »

Here is the low_undead trait. I saw some traits in the asset pack with onReceiveCondition and other hooks in the trait definition themselves but that didn't seem to work with onAttack (?) so put this in your party component.

Image

Here are some more images of my testing: https://www.mediafire.com/folder/d4134r ... dead_trait

Code: Select all

		 onAttack =		
			function (self, champion, action, slot)
			local doDebug = false
			local chanceToTrigger = 10
			if champion:hasTrait("low_undead") then
				local xx = 0
				local yy = 0
				if doDebug then print("low_undead onAttack triggered") end
				if party.facing == 0 then 
					yy = yy - 1
				elseif party.facing == 2 then
					yy = yy + 1
				elseif party.facing == 1 then
					xx = xx + 1
				elseif party.facing == 3 then
					xx = xx - 1
				end
				for i in party.map:entitiesAt(party.x + xx, party.y + yy) do
					if i.name == "mummy" or i.name == "skeleton_archer" then
						local traitTrigger = math.random(1, 100)
						if doDebug then print("chanceToTrigger:", chanceToTrigger) end
						if doDebug then print("traitTrigger:", traitTrigger) end
						if traitTrigger <= chanceToTrigger then
							if doDebug then print("Success") end
							i.monster:die()
							hudPrint("The " .. i.name .. " has been slain.")
						end
					end
				end
			end
		end,
When a party member attacks it looks at everything in front of the party and if it sees a mummy or skeleton_archer if rolls to see if it auto-kills.

However, onAttack doesn't seem to deal with the monster or potential damage so I don't know how it is suppose to just increase damage dealt for each point just yet.... But MeleeAttackComponent.onHitMonster(self, monster, tside, damage, champion) does. Adding it to the party definition does not work. Having every weapon call the same function onHitMonster that then goes through traits and applies modifiers could work, though, just not as clean as it could be, maybe.
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Undead Slayer Skill and Trait definiton help

Post by cameronC »

Sorry for the double post.

This code works fine and covers the general damage mod to Undead monsters, the low_undead one-hit-kill chance for mummies/archers, and the high_undead one-hit-kill chance for all undeads... I chose to set it up so that at [5] Undead Slayer it gives you 2 10% chances to kill the mummies/archers, but you can add some checks so it only triggers once for them if you wanted.

in script entity named abilityChecks

Code: Select all

function attackTriggers (self, monster, tside, damage, champion)
local monsterHealth = monster.go.monster:getHealth()
-- General/Skill based modifiers
if monster.go.monster:hasTrait("undead") then
	local undeadDamageMod = champion:getSkillLevel("undead_slayer") * 3
	if undeadDamageMod > 0 then 
		monster.go.monster:setHealth(monsterHealth - undeadDamageMod)
		monster.go.monster:showDamageText(tostring(undeadDamageMod), "FF0000")
	end


end



-- Trait Specific modifiers
if champion:hasTrait("low_undead") then
	local doDebug = false
	local chanceToTrigger = 10
	if monster.go.name == "mummy" or monster.go.name == "skeleton_archer" then
		local traitTrigger = math.random(1, 100)
		if doDebug then print("chanceToTrigger:", chanceToTrigger) end
		if doDebug then print("traitTrigger:", traitTrigger) end
		if traitTrigger <= chanceToTrigger then
			if doDebug then print("Success") end
			monster.go.monster:die()
			hudPrint("The " .. monster.go.name .. " has been slain!")
		end
	end
end
if champion:hasTrait("high_undead") then
	local doDebug = false
	local chanceToTrigger = 10
	if monster.go.monster:hasTrait("undead") then
		local traitTrigger = math.random(1, 100)
		if doDebug then print("chanceToTrigger:", chanceToTrigger) end
		if doDebug then print("traitTrigger:", traitTrigger) end
		if traitTrigger <= chanceToTrigger then
			if doDebug then print("Success") end
			monster.go.monster:die()
			hudPrint("The " .. monster.go.name .. " has been slain!")
		end
	end
end



if monster.go.monster:getHealth() <= 0 then monster.go.monster:die() end
return 
end
in onHitMonster hook of each weapon

Code: Select all

onHitMonster = function(self, monster, tside, damage, champion)
		abilityChecks.script.attackTriggers(self, monster, tside, damage, champion)
	return 
end,
I'm sure it could be tidied up a bit. I couldnt get it to work with just returning the modified damage value, for instance, so had to apply it manually and then check if it was dead (Otherwise if the bonus damage killed the undead then he would just stop moving and block your way - this also had the side effect of not printing the modified damage out, so I added red damage text to show the bonus damage). The downside, of course, is that each weapon needs to have this onHitMonster call and depending on how you are doing your weapons that might be cumbersome, I guess (Though you can add any damage modifers to this function, ones for other traits for example). Functioning perfectly, though a little clunky implementation.
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Undead Slayer Skill and Trait definiton help

Post by Drakkan »

cameronC wrote: in onHitMonster hook of each weapon

Code: Select all

onHitMonster = function(self, monster, tside, damage, champion)
		abilityChecks.script.attackTriggers(self, monster, tside, damage, champion)
	return 
end,
I'm sure it could be tidied up a bit. I couldnt get it to work with just returning the modified damage value, for instance, so had to apply it manually and then check if it was dead (Otherwise if the bonus damage killed the undead then he would just stop moving and block your way - this also had the side effect of not printing the modified damage out, so I added red damage text to show the bonus damage). The downside, of course, is that each weapon needs to have this onHitMonster call and depending on how you are doing your weapons that might be cumbersome, I guess (Though you can add any damage modifers to this function, ones for other traits for example). Functioning perfectly, though a little clunky implementation.
wow impressive, thanks a lot man. The implementation is soo much complicated than I thought it will be :) but I see logic in the script not sure if there is some better solution as for now. Just idea (not sure if possible to script) - instead that hook add for each weapon what about some general script which will check when onHit monster is triggered with a weapon (could be done via default weapon trait check - axe, dagger, light_weapon etc... / or general tag: weapon) , than run a script ? I get this idea when I looked for Martial Training trait which seems little close to it.
Breath from the unpromising waters.
Eye of the Atlantis
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Undead Slayer Skill and Trait definiton help

Post by cameronC »

JKos to the rescue - modifyObject: viewtopic.php?f=22&t=8450&start=27
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Undead Slayer Skill and Trait definiton help

Post by Drakkan »

just had some time and tried your script , seems it is working correctly. I will need some time to change the items, monsters etc... but overall it should work. I really love how you script that the extra damage is triggered with red color on monster hit, thats so cool !
thanks for help
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply