Page 1 of 1

Scripting Experts: Is This Possible?

Posted: Tue Feb 05, 2019 9:36 am
by HypnoToad
Basically I want to recharge a spent item, I know I can do a destroy and spawn in an alcove, but is there a way to do this and/or recharge it while the players has it in their hands?

Say a fighter has the Fire Blade and it's empty, can I have a spell that will swap it for a charged one or recharge it while he is holding it?

Re: Scripting Experts: Is This Possible?

Posted: Tue Feb 05, 2019 4:34 pm
by 7Soul
The Crystal of Recharging does exactly that as an usable item

Re: Scripting Experts: Is This Possible?

Posted: Tue Feb 05, 2019 5:24 pm
by THOM
We are in the LoG 1 section...

Re: Scripting Experts: Is This Possible?

Posted: Tue Feb 05, 2019 6:08 pm
by 7Soul
THOM wrote: Tue Feb 05, 2019 5:24 pm We are in the LoG 1 section...
I'm a fool!

Re: Scripting Experts: Is This Possible?

Posted: Tue Feb 05, 2019 10:28 pm
by Zo Kath Ra
HypnoToad wrote: Tue Feb 05, 2019 9:36 am Basically I want to recharge a spent item, I know I can do a destroy and spawn in an alcove, but is there a way to do this and/or recharge it while the players has it in their hands?

Say a fighter has the Fire Blade and it's empty, can I have a spell that will swap it for a charged one or recharge it while he is holding it?
I haven't tried this, but maybe you could use
http://www.grimrock.net/modding_log1/sc ... reference/
Champion:getItem(slot)
Champion:removeItem(slot)
Champion:insertItem(slot, item)

Re: Scripting Experts: Is This Possible?

Posted: Wed Feb 06, 2019 12:01 am
by HypnoToad
Zo Kath Ra wrote: Tue Feb 05, 2019 10:28 pm I haven't tried this, but maybe you could use
http://www.grimrock.net/modding_log1/sc ... reference/
Champion:getItem(slot)
Champion:removeItem(slot)
Champion:insertItem(slot, item)
Thanks for the advice, I looked at that and it's beyond my limited scripting knowledge so I'm likely going with put the item in an alcove and insert a coin and it recharges (swaps it out for a recharged one).

Re: Scripting Experts: Is This Possible?

Posted: Wed Feb 06, 2019 1:25 am
by Isaac
Here is a working spell, and spell_scroll item.

Code: Select all

defineSpell{
	name = "recharge_fireblade",
	uiName = "Recharge Fireblade",
	skill = "fire_magic",
	level =  5,
	runes = "ADE",
	manaCost = 50,
	onCast = function(champion, X, Y, direction, skill)
					for slot = 7,8 do
						local item = champion:getItem(slot)
						if item and item.name == "fire_blade" then
							item:setCharges(9)
							champion:setCondition("fire_shield", 2)
							playSound("generic_spell")
							return
						elseif item and item.name == "fire_blade_empty" then
							champion:removeItem(slot)
							champion:insertItem(slot, spawn('fire_blade'))
							champion:getItem(slot):setCharges(9)	
							champion:setCondition("fire_shield", 2)
							playSound("generic_spell")
							return
						end	
					end
					hudPrint(champion:getName().."'s spell fizzled.")
					hudPrint("[No equipped Fireblade]")
				end		
}

defineObject{
		name = "scroll_recharge_fireblade",
		class = "Item",
		uiName = "Scroll of Recharge Fireblade",
		model = "assets/models/items/scroll_spell.fbx",
		gfxIndex = 113,
		scroll = true,
		spell = "recharge_fireblade",
		weight = 0.3,
	}

Re: Scripting Experts: Is This Possible?

Posted: Wed Feb 06, 2019 4:33 am
by HypnoToad
Isaac wrote: Wed Feb 06, 2019 1:25 am Here is a working spell, and spell_scroll item.

Code: Select all

defineSpell{
	name = "recharge_fireblade",
	uiName = "Recharge Fireblade",
	skill = "fire_magic",
	level =  5,
	runes = "ADE",
	manaCost = 50,
	onCast = function(champion, X, Y, direction, skill)
					for slot = 7,8 do
						local item = champion:getItem(slot)
						if item and item.name == "fire_blade" then
							item:setCharges(9)
							champion:setCondition("fire_shield", 2)
							playSound("generic_spell")
							return
						elseif item and item.name == "fire_blade_empty" then
							champion:removeItem(slot)
							champion:insertItem(slot, spawn('fire_blade'))
							champion:getItem(slot):setCharges(9)	
							champion:setCondition("fire_shield", 2)
							playSound("generic_spell")
							return
						end	
					end
					hudPrint(champion:getName().."'s spell fizzled.")
					hudPrint("[No equipped Fireblade]")
				end		
}

defineObject{
		name = "scroll_recharge_fireblade",
		class = "Item",
		uiName = "Scroll of Recharge Fireblade",
		model = "assets/models/items/scroll_spell.fbx",
		gfxIndex = 113,
		scroll = true,
		spell = "recharge_fireblade",
		weight = 0.3,
	}
Wow, that's just what I wanted, thanks soooooo much! :P