New weapon skills - Resolved

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

New weapon skills - Resolved

Post by Drakkan »

New weapon proficiency skills.

Main purpose is to give player possibility to evolve and train some favorite weapon skill similar to Log1.
In case you want use / modify it, no need to ask, credit goes to akroma22 who helped me with scripting. As for myself no credit need.
You will need to use you own / existing icons.


Setup:
- Dagger / Bow not developed yet
- for Swords nothing is required, just copy skill / trait code
- for Axe and Mace you need

1. copy Axe / Mace skills and traits as well
2. Inside editor create script and put inside following code:
TBD (find akroma manager in this topic
3. You need modify EACH axe and mace weapon you want to "enhance". All you need to do is to insert following onAttack hook for such a weapon. If you want all the basic axe and mace weapons to support these skills / traits, you need modify them as well.
SpoilerShow

Code: Select all

onAttack = function(self, champion, action, slot)
         weaponModManager.script.addWeaponModifiers(self, champion:getOrdinal(), "axe")
                   delayedCall("weaponModManager", 0.2, "removeWeaponModifiers", self,  champion:getOrdinal(), "axe")
             end,

-------------------------
--Example:
--Reworked basic hand axe
------------------------

defineObject{
	name = "hand_axe",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/hand_axe.fbx",
		},
		{
			class = "Item",
			uiName = "Hand Axe",
			gfxIndex = 25,
			impactSound = "impact_blade",
			weight = 2.4,
			traits = { "light_weapon", "axe" },
		},
		{
			class = "MeleeAttack",
			attackPower = 10,
			accuracy = 0,
			cooldown = 4.5,
			swipe = "horizontal",
			attackSound = "swipe",
onAttack = function(self, champion, action, slot)
         weaponModManager.script.addWeaponModifiers(self, champion:getOrdinal(), "axe")
                   delayedCall("weaponModManager", 0.2, "removeWeaponModifiers", self,  champion:getOrdinal(), "axe")
             end,
		},
	},
	tags = { "weapon" },
}
For Mace it is following onAttack hook
SpoilerShow

Code: Select all

               onAttack = function(self, champion, action, slot)
            weaponModManager.script.addWeaponModifiers(self, champion:getOrdinal(), "mace")
                      delayedCall("weaponModManager", 0.2, "removeWeaponModifiers", self,  champion:getOrdinal(), "mace")
                end,
-----------------
--Example:
-----------------

defineObject{
	name = "branch",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/branch.fbx",
		},
		{
			class = "Item",
			uiName = "Branch",
			gfxIndex = 273,
			impactSound = "impact_blunt",
			weight = 1.2,
			traits = { "light_weapon", "mace" },
		},
		{
			class = "MeleeAttack",
			attackPower = 3,
			pierce = 0,
			accuracy = 0,
			cooldown = 3,
			swipe = "vertical",
			attackSound = "swipe",
               onAttack = function(self, champion, action, slot)
            weaponModManager.script.addWeaponModifiers(self, champion:getOrdinal(), "mace")
                      delayedCall("weaponModManager", 0.2, "removeWeaponModifiers", self,  champion:getOrdinal(), "mace")
                end,
		},
	},
	tags = { "weapon" },
}
Skills and traits definitions

SWORD
Skill
SpoilerShow

Code: Select all

defineSkill{
           name = "sword_prof",
           uiName = "Sword prof",
           priority = 10,
           --iconAtlas = "mod_assets/icons/testujuikony.tga",
           icon = 0,

           description = "Mastering the sword requires both dexterity and Strength. Each point invested increases your Strength / Hit points or Dexterity / energy. On Level 5 any attack with sword is 20% faster.",

       onRecomputeStats = function(champion, level)
          if level == 1 then
             champion:addStatModifier("dexterity", level)
             champion:addStatModifier("max_energy", level * 5)
          elseif level == 2 then
             champion:addStatModifier("dexterity", level - 1)
             champion:addStatModifier("max_energy", (level - 1) * 5)
             champion:addStatModifier("strength", level - 1)
             champion:addStatModifier("max_health", (level - 1) * 5)
          elseif level == 3 then
             champion:addStatModifier("dexterity", level - 1)
             champion:addStatModifier("max_energy", (level - 1) * 5)
             champion:addStatModifier("strength", level - 2)
             champion:addStatModifier("max_health", (level - 2) * 5)
          elseif level == 4 then
             champion:addStatModifier("dexterity", level - 2)
             champion:addStatModifier("max_energy", (level - 2) * 5)
             champion:addStatModifier("strength", level - 2)
             champion:addStatModifier("max_health", (level - 2) * 5)
          elseif level == 5 then
             champion:addStatModifier("dexterity", level - 3)
             champion:addStatModifier("max_energy", (level - 3) * 5)
             champion:addStatModifier("strength", level - 3)
             champion:addStatModifier("max_health", (level - 3) * 5)
          end
       end,
       traits = { [5] = "grandmaster_sword"   },
     }
Trait
SpoilerShow

Code: Select all

defineTrait{
       name = "grandmaster_sword",
       uiName = "Sword Slasher",
       icon = 2,
       description = "Any sword attack is 20% faster.",
onComputeCooldown = function(champion, weapon, attack, attackType, level)
      if weapon:hasTrait("sword") or weapon:hasTrait("sword") then return 0.833 end
   end
end,
}
AXE
Skill
SpoilerShow

Code: Select all

defineSkill{
name = "axe_prof",
uiName = "Axe proficiency",
priority = 10,
--iconAtlas = "mod_assets/icons/testujuikony.tga",
icon = 1,
description = "Swinging the axe makes your character much stronger. Each point increases your Strength (+1) and Hit points (+5). At the 3rd skill level you gain the Expert Axeman trait (Attack Power +10 with axes) and at the 5th level you gain the Grand Master Axeman trait (Attack Power +30 with axes).",
   onRecomputeStats = function(champion, level)
      champion:addStatModifier("max_health", level*5)
      champion:addStatModifier("strength", level*1)
   end,
traits = {  [3] = "expert_axeman", [5] = "grandmaster_axeman"  },
}
Traits
SpoilerShow

Code: Select all

defineTrait{
	name = "expert_axeman",
	uiName = "Expert Axeman",
        icon = 5,
	description = "You have learned how to use axe properly and there are scary rumors among the monsters.",
}

defineTrait{
       name = "grandmaster_axeman",
       uiName = "Axe Grand Master",
       icon = 6,
       description = "Finally you have mastered the axe with full potential. Monsters tremble with fear now !",
}
MACE
Skill
SpoilerShow

Code: Select all

defineSkill{
name = "mace_prof",
uiName = "Mace proficience",
priority = 10,
--iconAtlas = "mod_assets/icons/testujuikony.tga",
icon = 2,
description = "You become more resistant on the battlefield while fighting with Mace. Each point invested increases your Vitality and Hit points. On Level 3 your attack with mace ignores 10 points of opponents armor and finally on level 5 your attack ignores 30 points of armor.",
   onRecomputeStats = function(champion, level)
      champion:addStatModifier("max_health", level*5)
      champion:addStatModifier("vitality", level*1)
   end,
	traits = { [3] = "expert_mace", [5] = "grandmaster_mace"  },
}
Traits
SpoilerShow

Code: Select all

defineTrait{
name = "expert_mace",
uiName = "Chain Breaker",
icon = 2,
description = "You learned how to use mace beyond regular knowledge. Now you ignore 15 points of opponents armor with any mace-weapon type.",
}

defineTrait{
       name = "grandmaster_mace",
       uiName = "Wardens Bane",
       icon = 2,
       description = "You bash any armored enemy with deadly precision, ignoring additional 30 points of armor.",
}
Last edited by Drakkan on Wed Apr 01, 2015 7:40 am, edited 8 times in total.
Breath from the unpromising waters.
Eye of the Atlantis
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: some weapon skill help pls

Post by cameronC »

On my way out the door to go to work but here is something quick to point you in the right direction (hopefully).

The other two cannot be done JUST within a trait definition, as traits seemingly only have onRecomputeStats, onComputeCooldown, onComputeCritChance, and onReceiveCondition. So you need to add onHitMonsterChecks that have parts that activate by checking if champion:hasTrait

Code: Select all

defineTrait{
name = "master_swordsman",
uiName = "Sword Master",
icon = 94,
description = "Sword master !",

onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if weapon:hasTrait("sword") or weapon:hasTrait("sword") then return 0.8 end
	end
end,
should work as intended.

Code: Select all

defineTrait{
name = "master_daggerman",
uiName = "Dagger Master",
icon = 94,
description = "Dagger master !",

onComputeCritChance = function(self, champion, weapon, attack, attackType)
		if weapon:hasTrait("dagger") or weapon:hasTrait("dagger") then return 10 end
 end
end,
That I think will work, however, it doesn't check if you are attacking from behind... Since there is no monster passed to the onComputeCritChance function you would have to do a check of the entities in front of the party and check the facing of any monsters and compare them. Otherwise you can have an onHitMonster check (In weapons) that applies the modifier if wiedling a dagger, if champion:hasTrait, and checking monster facing versus party facing. If you are using jkos' modifyObject script to add one function to all onHitMonster hooks this is easiest, if not putting the checks in the trait itself can also work, it's just a little clunky.
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
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: some weapon skill help pls

Post by Grimfan »

I know that pierce is the ability which allows weapons and monsters to bypass armor, but it's not normally accessible to champs. You will probably need to modify every mace-type weapon in the game so that they gain the pierce ability when the user has the trait.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: some weapon skill help pls

Post by minmay »

cameronC wrote:

Code: Select all

defineTrait{
name = "master_swordsman",
uiName = "Sword Master",
icon = 94,
description = "Sword master !",

onComputeCooldown = function(champion, weapon, attack, attackType, level)
		if weapon:hasTrait("sword") or weapon:hasTrait("sword") then return 0.8 end
	end
end,
should work as intended.
This is 25% faster cooldown, not 20%. For 20% faster you need to return 5/6.

For axe master and mace master you should use onEquipItem and onUnequipItem instead of onHitMonster, so that the damage/pierce modifiers are shown in the attack power display.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: some weapon skill help pls

Post by cameronC »

The QUICK trait in the asset pack decreases cooldown by 10% by returning 0.9, though. Why doesn't returning 0.8 decrease cooldown by 20%?
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
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: some weapon skill help pls

Post by Grimfan »

I'm also wondering why 0.2 isn't 20% of 1? Is maths in lua different or something? :?
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: some weapon skill help pls

Post by Batty »

If cooldown = 10 and you change it to 5, you would decrease cooldown by 50%, yes. However, it would be a 100% faster cooldown (5/5 = 1 = 100%).

Returning 0.8 does decrease cooldown by 20% but 0.2/0.8 = 0.25 = 25% faster (or increased) cooldown & Drakkan asked for 20% faster cooldown which is 5/6 = 0.833 or a 16.7% decrease in cooldown.
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: some weapon skill help pls

Post by Grimfan »

Okay. Now that makes sense.

Of course, it doesn't help Drakkan any. :lol:
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: some weapon skill help pls

Post by Drakkan »

thanks guys, could somebody please write that script for mace / axe ?
As for the dagger I think that should be too complicated to include... I though that original light weapons has this crit chance already, but seems thats hardcoded ?
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: some weapon skill help pls

Post by akroma222 »

Ok, I think I may have something... a little clunky though

First I tried using onAttack hook, setting attackPower to (100) then using onHitMonster AND onPostAttack hook to return the axe attackPower to the original value
....but if you attack a monster and miss, then those two other hooks are not called and attack power stays the same = DOES NOT WORK

What seems to work (but I am sure someone has a better solution) is using onAttack hook with this:
SpoilerShow

Code: Select all

{
          	class = "MeleeAttack",
          	attackPower = 10,
          	accuracy = 0,
          	swipe = "horizontal",
          	attackSound = "swipe",
          	cooldown = 4.5,
          	baseDamageStat = "strength",
         	damageType = "physical",
		onAttack = function(self, champion)
			local item = self
			local champ = champion:getOrdinal()
			if champion:hasTrait("master_axeman") then
				item:setAttackPower(100)
				print(""..item:getAttackPower().."")
				delayedCall("attackScript", 0.2, "resetAttackPower", item, champ)
			end
		end,
       	},
The delayedCall fucntion calls a script in dungeon (script entity called 'attackScript') with this:
SpoilerShow

Code: Select all

function resetAttackPower(item, ord)
	local c = party.party:getChampion(ord)
	local i = item
	if c:hasTrait("master_axeman") then
		if i.go and i.go.name == "hand_axe" then
			i:setAttackPower(10)
			print(""..i:getAttackPower().."")
		end
	end
end
resetAttackPower function will return the axe to its original attackPower (which you have to enter in manually)
You also will need to add in (elseif i.go and i.go.name == "other weapons names" then) for your other weapons.

Quite clunky, but this is all I got for now...
With maces you will just need to use getPierce and setPierce instead of getAttackPower and setAttackPower
and also change the hasTrait("master_axeman") to hasTrait("master_maceman") obviously

Hopefully we can come up with something better than this :roll:
Post Reply

Return to “Mod Creation”