Using/Consuming a potion?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: Using/Consuming a potion?

Post by SpacialKatana »

Cheers Emciel got it working a treat now. If anyone else wants to modify their own custom potions here are my working custom scripts:-

For the recipe:-

Code: Select all

defineRecipe{
    item = "potion_healing_greater",
    ingredients = {1,"flask",1,"milkreed",2,"blooddrop_blossom"}
}
And then for the potion itself:-

Code: Select all

cloneObject{
        name = "potion_healing_greater",
        baseObject = "potion_healing",
        uiName = "Greater Healing Potion",
        description = "A Bernard strength healing potion",
        consumable = true,
        potion = true,
        onUseItem = function(self,champion)
        champion:modifyStat("health", 100)
        playSound("consume_potion")
        return true 
        end
}
The consumable and potion defs may not be needed for a cloned potion, but would be needed if you had 'defined' a new item.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Using/Consuming a potion?

Post by akroma222 »

Thank you for posting up a greater heal potion. That one was definitely on the list :)
Further, I am keen to make an Elixir of Life potion - which heals the whole party regardless of who drinks it and restores everyone's food counter a fair bit (or a lot). I tried to adapt it from the greater heal potion but to no avail - it wont heal the party, just the one who drinks it..... Help me maybe?? ;)

Recipe- elixir of life
SpoilerShow
defineRecipe{
item = "elixir_of_life",
ingredients = {1,"flask",1,"milkreed",1,"blooddrop_blossom",2,"tar_bead"}
}
Script- elixir of life
SpoilerShow
cloneObject{
name = "elixir_of_life",
baseObject = "water_flask",
uiName = "Elixir of Life",
description = "A healing potion with properties that extend out from the user",
consumable = true,
potion = true,
onUseItem = function(self,party)
party:modifyStat("health", 100)
playSound("heal_party")
return true
end
}
Cloned from a water flask gives it the white potion look, and I would love for it to not only make the crystal heal party sound (that bit works) but also the fancy sparkly effect you get when you use a heal crystal.

Can someone please point out what I am doing wrong. I am not a modders bootlace and this dungeon editor is certainly popping that cherry lol any help much appreciated!!!!

Also on the agenda is a Resist magic potion. No work on that as of yet.....
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Using/Consuming a potion?

Post by akroma222 »

Oh! and Elixir of Life should probably cure status effects too (poison, death etc).... hmmm much more complicated than I had originally thought :oops:
SpacialKatana
Posts: 163
Joined: Fri Sep 14, 2012 6:20 pm

Re: Using/Consuming a potion?

Post by SpacialKatana »

In the onUse hook, use a loop to heal each champion for that effect. The editing Superthread will help you there, just cut and paste what you need from a 'Party' script.
C+ is my thing, nudge Komag or another kind soul for help with lua if you get stuck, I'd probably get it wrong first attempt here!
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Using/Consuming a potion?

Post by akroma222 »

Ok, so I thought I would have another crack at mixing up this potion (Elixir of Life)...
Thanks for your reply specialKatana, I found what I believe is a party loop and have taken the coding from the other potions listed in the asset pack...
I have tried the following script, but it crashes the editor.... :(
SpoilerShow

Code: Select all

cloneObject{
        name = "elixir_of_life",
        baseObject = "water_flask",
        uiName = "Elixir of Life",
        description = "A healing potion with properties that extend out from the user",
        consumable = true,
        potion = true,
        onUseItem = function(self,party)
		for i = 1,4 do
  			party:getChampion(i):modifyStat("health", 200),
			party:getChampion(i):modifyStat("energy", 200),
			party:getChampion(i):setCondition("diseased", 0),
			party:getChampion(i):setCondition("paralyzed", 0),
			party:getChampion(i):setCondition("poison", 0),
	end
	playSound("heal_party")
        return true
	end
}
Does anyone know why this code may not work??
Decayer
Posts: 65
Joined: Sat Oct 13, 2012 3:19 pm

Re: Using/Consuming a potion?

Post by Decayer »

You need to remove the commas after the modifyStat / setCondition lines.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Using/Consuming a potion?

Post by akroma222 »

Thanks Decayer, I did try that before but consuming the potion crashes the editor still...
I received this error message...
SpoilerShow

Code: Select all

mod_assets/scripts/items.lua:84: attempt to call method 'getChampion' (a nil value)
stack traceback:
	mod_assets/scripts/items.lua:84: in function 'onUseItem'
	[string "Item.lua"]: in function 'useItem'
	[string "CharSheet.lua"]: in function 'slotClicked'
	[string "CharSheet.lua"]: in function 'draw'
	[string "Gui.lua"]: in function 'draw'
	[string "GameMode.lua"]: in function 'update'
	[string "DungeonEditor.lua"]: in main chunk
	[C]: in function 'xpcall'
	[string "DungeonEditor.lua"]: in function 'preview'
	[string "DungeonEditor.lua"]: in function 'update'
	[string "Grimrock.lua"]: in main chunk
Decayer
Posts: 65
Joined: Sat Oct 13, 2012 3:19 pm

Re: Using/Consuming a potion?

Post by Decayer »

Oh, right, it's crashing because you're supplying your own 'party' variable to the function; try replacing

Code: Select all

onUseItem = function(self,party)
with

Code: Select all

onUseItem = function(item,champion)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Using/Consuming a potion?

Post by akroma222 »

Yes indeed I was! Haha... I have enlisted some extra help and well, here it is, compliments of Crisman (thank you as well Decayer!)
SpoilerShow

Code: Select all

cloneObject{
        name = "elixir_of_life",
        baseObject = "water_flask",
        uiName = "Elixir of Life",
        description = "A healing potion with properties that extend out from the user",
        consumable = true,
        potion = true,
        onUseItem = function(self, champion)
        
party:heal()
      for i = 1,4 do
         party:getChampion(i):modifyFood(1000)  
   end
   playSound("heal_party")
        return true
   end
}
This white looking potion will heal the whole party as a crystal does (health, energy, status effects) as well as restore everyone's food counter...
It does indeed seem powerful, but in-game the recipe is hard to find and is taxing on the ingredients (2 tar bead, 1 blooddrop, 1 slime bell and 1 milkreed). Plus it will be needed for the later boss fights.
User avatar
Modraneth
Posts: 95
Joined: Thu Aug 27, 2015 8:27 pm
Location: Portugal

Re: Using/Consuming a potion?

Post by Modraneth »

hi. it is possible to clone a potion to create a water breathing potion ?
i think i will need it to my mod and i cant make the definition to work
SpoilerShow

Code: Select all

cloneObject{
        name = "potion_waterbreathing",
        baseObject = "potion_poison",
        uiName = "Water Breathing Potion",
        description = "A potion created to breath under water.",
        consumable = true,
        potion = true,
        onUseItem = function(self,champion)
        champion:modifyStat(what do i place here??)
        playSound("consume_potion")
        return true 
        end
}
Mods:
Isle of Gunger
The Bloody Path Dropped
A World of Power work in progress
Post Reply