Scripting Experts: Is This Possible?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Scripting Experts: Is This Possible?

Post 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?
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Scripting Experts: Is This Possible?

Post by 7Soul »

The Crystal of Recharging does exactly that as an usable item
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Scripting Experts: Is This Possible?

Post by THOM »

We are in the LoG 1 section...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Scripting Experts: Is This Possible?

Post by 7Soul »

THOM wrote: Tue Feb 05, 2019 5:24 pm We are in the LoG 1 section...
I'm a fool!
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Scripting Experts: Is This Possible?

Post 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)
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Scripting Experts: Is This Possible?

Post 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).
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Scripting Experts: Is This Possible?

Post 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,
	}
User avatar
HypnoToad
Posts: 73
Joined: Thu Sep 22, 2016 1:19 am
Location: Melbourne, Australia

Re: Scripting Experts: Is This Possible?

Post 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
Return of the Dark Lord - V3.5 Download:
https://www.nexusmods.com/grimrock/mods ... escription
Post Reply