Page 1 of 1

help: potion of invisibility?

Posted: Wed Oct 10, 2012 7:33 pm
by uggardian
So I tried to make somekind of invisibility potion (later a recipe for that too), but I encountered two problems. 1) How to make the poison turn the whole party invisible? I tried to change "function(self, champion)" into function(self, party), but the editor crashed completely. 2) How to make the potion turn empty when somebody drinks it? At the moment I can use it as many times as I want, but that's not good :| .. So maybe somebody wiser than me could help me a bit? :oops:

Code: Select all

cloneObject{
uiName = "Potion of Invisibility",
name = "potion_invisibility",
baseObject = "potion_healing",
onUseItem = function(self, champion)
champion:setCondition("invisibility", 40)
end
}

Re: help: potion of invisibility?

Posted: Wed Oct 10, 2012 7:46 pm
by JohnWordsworth
Ahh, you unfortunately cannot change the function as you tried, when you define onUseItem = function(self, chamption) - you don't actually get to control what's in the parameters 'self' and 'champion', the game does that. You can however, decide what they are called. So if you put onUseItem = function(self, something), then 'something' would still point to the champion that drunk the potion, except you've given it a slightly less convenient name!

However, you can actually get information about the whole party using global functions (functions that always exist) and so your potion could work by iterating over each party slot, checking if there is a champion in that slot, and then turning that champion invisible.

Try something like the following...
SpoilerShow

Code: Select all

cloneObject {
  uiName = "Potion of Invisibility",
  name = "potion_invisibility",
  baseObject = "potion_healing",
  onUseItem = function(self, champion)
    for slot=1,4 do
      if party:getChampion(slot) ~= nil then
        party:getChampion(slot):setCondition("invisibility", 40);
      end
    end
 
    return true;
  end
}
Edit: Added return true so that the potion is replaced with an empty flask after use.

Re: help: potion of invisibility?

Posted: Wed Oct 10, 2012 7:54 pm
by uggardian
Thanks John, it worked. But I still have the other problem: The potion can be drunk unlimited times, it never changes into empty flask. How to fix that? :?:

Re: help: potion of invisibility?

Posted: Wed Oct 10, 2012 8:28 pm
by crisman
I think you need to add 'return true' before the very end of the function onUseItem

Re: help: potion of invisibility?

Posted: Wed Oct 10, 2012 9:31 pm
by JohnWordsworth
@crisman is correct, I'll add that to the above post!