Setting accuracy/damage when explicit using a bow?

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
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Setting accuracy/damage when explicit using a bow?

Post by CrEaToXx »

Good evening,

in the traits.lua the closest thing to modifie weapon/damage/accuracy stats during character creation, is this...

Code: Select all

defineTrait{
	name = "piercing_arrows",
	uiName = "Piercing Arrows",
	icon = 23,
	description = "Your Missile Weapon attacks ignore 20 points of enemy's armor.",
	-- hardcoded skill
}
...unfortunately it is hard coded, and doesn't reveal any sign on how to exactly give stats boost when using a bow weapon. I understand that dexterity increases accuracy for all ranged weapons used, but that's not what I want. In particular, I am modding a new race, you guess it, Elfs, which should benefit from using bows. Would this be working...

Code: Select all

EquipmentItemComponent.onComputeAccuracy(self, champion, weapon, attack, attackType)
...when using weapon = "bow"?
minmay
Posts: 2770
Joined: Mon Sep 23, 2013 2:24 am

Re: Setting accuracy/damage when explicit using a bow?

Post by minmay »

The onComputeAccuracy hook for traits works fine for RangedAttackComponent, you don't need to use EquipmentItemComponent.

Unfortunately, you cannot cleanly give a bonus to damage or pierce.
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.
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Re: Setting accuracy/damage when explicit using a bow?

Post by CrEaToXx »

Would this work?

Code: Select all

defineTrait{
	name = "elf",
	uiName = "Elf",
	icon = 41,
	description = "As an elf you belong to the most elder of all races in the realms. You are very fast and nimble, and very capable with the bow. Most elfs are also naturally gifted users of magic.\n Strength -4, Dexterity +3,\n Willpower +1,\n- Evasion +3.\n- Max Load -25kg.",
	onRecomputeStats = function(champion, level)
		if level > 0 then
			champion:addStatModifier("strength", -4)
			champion:addStatModifier("dexterity", 3)
			champion:addStatModifier("willpower", 1)
			champion:addStatModifier("evasion", 3)
			champion:addStatModifier("max_load", level * 25)
		end
	end,
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and weapon == "short_bow" then return 1 end
		if level > 0 and weapon == "longbow" then return 2 end		
	end,
}
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Re: Setting accuracy/damage when explicit using a bow?

Post by CrEaToXx »

I give up for today. There'd be other workarounds, like creating a racial trait to boost dexterity, and therefore accuracy. But it seems you can not increase accuracy with a racial trait when equipping the short_bow or longbow rangedweaponcomponents. The stats in UI simply won't change. Again, I feel I'm close to a solution, but missing something vital?
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Setting accuracy/damage when explicit using a bow?

Post by akroma222 »

CrEaToXx wrote:Would this work?

Code: Select all

	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and weapon == "short_bow" then return 1 end
		if level > 0 and weapon == "longbow" then return 2 end		
	end,
Hey CrEaToXx,
It certainly will not - it should crash at character creation....
The onComputeAccuracy hook would be why... your first line:

Code: Select all

if level > 0 and weapon == "short_bow" then
will be checking champion hands and returning nil for weapon before you have begun the game >> crash

Notice this asset pack trait is ok though
(as you cant make attacks in character creation):

Code: Select all

defineTrait{
	name = "weapon_specialization",
	uiName = "Martial Training",
	icon = 0,
	charGen = true,
	description = "You are trained to use a wide variety of melee weapons. Melee attacks gain Accuracy +7.",
	onComputeAccuracy = function(champion, weapon, attack, attackType, level)
		if level > 0 and attackType == "melee" then return 7 end
	end,
}


So, change your hook to something like this (for now) :
SpoilerShow
onComputeAccuracy = function(champion, weapon, attack, attackType, level)
if level > 0 then
if attackType == "missile" then
print(champion:getName(), weapon.go.name, attack:getName(), attackType, level)
if weapon and weapon.go.name == "short_bow" then
print(weapon.go.name)
return 50
elseif weapon and weapon.go.name == "crossbow" then
print(weapon.go.name)
return 20
end
end
end
end, [/code]
EDIT: This^^ works :) - and Ive included console prints so you can see the values of args/vars

I dont have time right now to reply in full, but here is a link to a thread that can probably help further.

viewtopic.php?f=22&t=9966

As minmay has stated -you cannot cleanly give a bonus to damage or pierce....
But this thread does have a (still not clean) work around by checking champion hands/weapons every frame

Im actually still using this work around as - AFAIK - its the best we can do about damage and pierce
(minmay - if Im outdated or incorrect here pls leme know!)

EDIT: In fact, pls do confirm whether this approach is still ok (although not clean) to use
- its been a while since that thread was posted, I have built quite a lengthy script around it - just want to make sure :D
CrEaToXx
Posts: 25
Joined: Thu Jan 19, 2017 9:58 pm

Re: Setting accuracy/damage when explicit using a bow?

Post by CrEaToXx »

Yes, working perfectly and clean. If by clean you mean there shouldn't be any errors in console/log file?

I was primarly interested in accuracy. I can life with no damage increase.

Thanks a lot...*thumbs up*
Post Reply