[Solved] itemActionComponent/secondaryAction problem

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
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

[Solved] itemActionComponent/secondaryAction problem

Post by Blichew »

There's this ItemAction (base) Component for Item Component on script-reference page:
http://www.grimrock.net/modding/scripti ... nComponent

I was wondering if anyone tried doing something with it - looking through the option it should be possible to twist secondaryAction a bit to achieve something interesting (there's this getBuildUp() and so on) like the longer you hold the button the better the effect. Is this even possible :) ?

:EDIT:

I went a bit different way with:

Code: Select all

			secondaryAction = {function()
				local luck = math.random(10)
				if luck > 2 then
					return "doubleShot0"
				else
					return "doubleShot1"
				end
			end},
I tried also without "{" and "}" on secondaryAction =, still no luck.
Here's whole item definition:
SpoilerShow

Code: Select all

defineObject{
	name = "twostringbow",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/short_bow.fbx",
		},
		{
			class ="Item",
			uiName = "Two-String Bow",
			gfxIndex = 13,
			GfxIndexPowerAttack = 466,
			secondaryAction = function()
				local luck = math.random(10)
				if luck > 2 then
					return "doubleShot0"
				else
					return "doubleShot1"
				end
			end,
			weight = 2.7,
			impactSound = "impact_blade",
			traits = { "bow", "missile_weapon" },
			description = "Short Bow that can spit two arrows at a same time."
		},
		{
			class = "RangedAttack",
			attackPower = 5,
			accuracy = 10,
			Ammo = "arrow",
			attackSound = "swipe_bow",
			cooldown = 2.0,
			baseDamageStat = "dexterity",
			damageType = "physical",
		},
		{
			class = "RangedAttack",         
			name = "doubleShot0",
			uiName = "Tripple Shot",
			Ammo = nil,
			--repeatCount = 1,
			attackPower = 10,
			attackSound = "swipe_special",
			baseDamageStat = "dexterity",
			damageType = "physical",
			chainAction = "doubleShot1",
			chainActionDelay = 0.1,
			cooldown = 4.0,
			energyCost = 5,
			onAttack = function(self, champion, slot, chainIndex)
				hudPrint(champion.name.." shot one extra arrow out of nowhere !")
			end,
		},
		{
			class = "RangedAttack",         
			name = "doubleShot1",
			uiName = "Double Shot",
			Ammo = "arrow",
			--repeatCount = 1,
			attackPower = 10,
			attackSound = "swipe_special",
			baseDamageStat = "dexterity",
			damageType = "physical",
			chainAction = "doubleShot2",
			chainActionDelay = 0.1,
			cooldown = 3.0,
			energyCost = 5,
		},
		{
			class = "RangedAttack",         
			name = "doubleShot2",
	 --     uiName = "Double Shot",
			Ammo = "arrow",
			--repeatCount = 1,
			attackPower = 10,
			attackSound = "swipe_special",
			baseDamageStat = "dexterity",
			damageType = "physical",
	--		cooldown = 3.0,
			energyCost = 5,
		},
	},
}
Looking forward to your ideas :D
Last edited by Blichew on Fri Nov 07, 2014 9:46 am, edited 2 times in total.
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: itemAction Component/secondaryAction problem

Post by Blichew »

Bumping with my further tries:

:EDIT: Nevermind, it's working now. I don't know what was wrong.

I tried with onAttack funcction of AttackChain:

Code: Select all

		{
			class = "RangedAttack",         
			name = "doubleShot0",
			uiName = "Double/Triple Shot",
			Ammo = "arrow",
			attackPower = 10,
			attackSound = "swipe_special",
			baseDamageStat = "dexterity",
			damageType = "physical",
			chainAction = "doubleShot2",
			chainActionDelay = 0.1,
			cooldown = 4.0,
			energyCost = 5,
			onAttack = function(self, champion, slot, chainIndex)
				if math.random(10) > 2 then
					print("Got lucky:::")
                                        self:setChainAction("doubleShot1")
				else
					print("Unlucky")
				end
			end,
		},
I'm using self:setChainAction(string) because self.go.id returns item id, so self should be this ItemActionComponent of class "RangedAttack"
SpoilerShow
[/code]
defineObject{
name = "twostringbow",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/short_bow.fbx",
},
{
class ="Item",
uiName = "Two-String Bow",
gfxIndex = 13,
GfxIndexPowerAttack = 466,
secondaryAction = "doubleShot0",
weight = 2.7,
impactSound = "impact_blade",
traits = { "bow", "missile_weapon" },
description = "Short Bow that can spit two arrows at a same time."
},
{
class = "RangedAttack",
attackPower = 5,
accuracy = 10,
Ammo = "arrow",
attackSound = "swipe_bow",
cooldown = 2.0,
baseDamageStat = "dexterity",
damageType = "physical",
},
{
class = "RangedAttack",
name = "doubleShot0",
uiName = "Double/Triple Shot",
Ammo = "arrow",
attackPower = 10,
attackSound = "swipe_special",
baseDamageStat = "dexterity",
damageType = "physical",
chainAction = "doubleShot2",
chainActionDelay = 0.1,
cooldown = 4.0,
energyCost = 5,
onAttack = function(self, champion, slot, chainIndex)
if math.random(10) > 2 then
print("Got lucky:::")
self:setChainAction("doubleShot1")
else
print("Unlucky")
end
end,
},
{
class = "RangedAttack",
name = "doubleShot1",
uiName = "Double/Triple Shot",
Ammo = "arrow",
--repeatCount = 1,
attackPower = 10,
attackSound = "swipe_special",
baseDamageStat = "dexterity",
damageType = "physical",
chainAction = "doubleShot2",
chainActionDelay = 0.1,
cooldown = 3.0,
energyCost = 5,
},
{
class = "RangedAttack",
name = "doubleShot2",
uiName = "Triple Shot",
Ammo = "arrow",
--repeatCount = 1,
attackPower = 10,
attackSound = "swipe_special",
baseDamageStat = "dexterity",
damageType = "physical",
-- cooldown = 3.0,
energyCost = 5,
},
},
}
[/code]
Did anyone try messing up with item customization this much :) ?


:EDIT: Nevermind, it's working now. I don't know what was wrong.


So the real question remains: can you modify object properties dynamically or does everything has to be done inside hooks, like onAttack ?
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [(partly)Solved] itemActionComponent/secondaryAction pro

Post by petri »

Sure you can!
User avatar
Blichew
Posts: 157
Joined: Thu Sep 27, 2012 12:39 am

Re: [(partly)Solved] itemActionComponent/secondaryAction pro

Post by Blichew »

petri wrote:Sure you can!
:D

to rephrase: in object definition:

Code: Select all

         secondaryAction = function()
            local luck = math.random(10)
            if luck > 2 then
               return "doubleShot0"
            else
               return "doubleShot1"
            end
         end,
this won't work (judging from my observations). Or I'm just doing something wrong ?
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [(partly)Solved] itemActionComponent/secondaryAction pro

Post by petri »

I meant yes you can change objects properties dynamically. E.g. setSecondaryAction()
Post Reply