Temporary potion effects [solved]

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!
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Temporary potion effects [solved]

Post by Aisuu »

So I looked everywhere but didnt find solution for this.
It would by nice to have sortiment of potions with temporary effect, like strenght, dextirity etc..
I know we have rage potion but its hard coded?

I tryed to come up with my own sript solution. This is what I have so far, but dont work :)
Champion gain +1 strengh but stat wont return to original value.
It should return to original value after 20 sec.
SpoilerShow

Code: Select all

onUseItem = function(self, champion)
  local basestr = champion:getBaseStat("strength")
  spawn("timer",party.level,party.x,party.y,party.facing,party.elevation,"strtimer")
  spawn("counter",party.level,party.x,party.y,party.facing,party.elevation,"strcounter")
  strtimer.timer:addConnector("onActivate","strcounter","increment")
  strtimer.timer:setTimerInterval(1)
  strcounter.counter:setValue(1)
  strtimer.timer:start()
  local cvalue = strcounter.counter:getValue()
  if cvalue <=20 then
    champion:upgradeBaseStat("strength", 1)	
  else
  champion:setBaseStat("strength",basestr)
  --stoping and destroy timer/counter
  end
end,
Last edited by Aisuu on Wed Dec 17, 2014 8:42 pm, edited 1 time in total.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Temporary potion effects [not solved]

Post by Drakkan »

just an idea (maybe little "hard" solution, but could work)- what about just making regular potion to gain some stat (for example STR - champion:upgradeBaseStat("strength", 1) ) and put into onUse hook to activate ingame timer (for example called PluStrenght), which after time run out is going to activate another in-game script, which will decrease that stat (champion:upgradeBaseStat("strength", -1) . there need to be some checks which champion used that potion and to whom then decrease that stat, but you have the idea...
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Temporary potion effects [not solved]

Post by Aisuu »

I was thinking about such solution, but it seems sooo complicated. Lets just say it wouldn't be ideal if you want to create many such different potions. Thats why I was trying doing it in single onUseItem function. Later I wanted to create trait/condition that indicate you have str potion effect on and prevent champion to drink more then one potion at one time.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Temporary potion effects [not solved]

Post by THOM »

isn't it possible to use delayedCall(self.go.id, <timeInSeconds>, <"Event"> )
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Temporary potion effects [not solved]

Post by Aisuu »

I was think about that too. But I dont know how to hook it to external script nor to function itself.

Normaly delayCall is used like this:
function myfunction()
delayedCall(self.go.id,"time","myotherfunction")
end

function myotherfunction()
--do delayed staff here
end

But how to use it within onUseItem function? :(

EDIT:
Nevermind that, Iam fool :)
I successfully delayed onUseItem to external script... I let you know final result...
cameronC
Posts: 80
Joined: Wed Apr 11, 2012 10:54 pm

Re: Temporary potion effects [not solved]

Post by cameronC »

THOM wrote:isn't it possible to use delayedCall(self.go.id, <timeInSeconds>, <"Event"> )
I haven't seen this work on a script component of an item, plus since the potion is consumed onUse I don't know if that would work either.

Setting the stat bonuses via trait works, when you go that route, but the traits still need to be removed on a timer so it's the same core issue.

Edit: Yeah, delaying to a separate script entity is probably the simplest way right now. Functional, but not the best way, probably
Writer and sometimes artist of the very slightly acclaimed comic series Scrambled Circuits. A comic series about a robot written by a human.

Grimrock 2 socketSystem: viewtopic.php?f=22&t=8546 / Github
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Temporary potion effects [not solved]

Post by Aisuu »

It is possible, only problem is to somehow identify champion who used potion and send values via delayedCall function to external script. Thats what Iam trying figuring right now :(

EDIT:
Just to let you know, this doesnt work :(
SpoilerShow

Code: Select all

onUseItem = function(self, champion)
  delayedCall(self.go.id,2,"callback")
  local callback = function()
    --do staff
  end
end,
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Temporary potion effects [not solved]

Post by Batty »

You can add arguments/parameters to delayedCall, so something like:

Code: Select all

delayedCall("script ID", time, "method", champion:getOrdinal())
User avatar
Aisuu
Posts: 61
Joined: Fri Oct 31, 2014 2:07 pm

Re: Temporary potion effects [solved]

Post by Aisuu »

Thx Batty. With your help and inspirations of others I was able to solve it :)
Here is complete solution and example for adding +1 strenght to champion for 20 seconds.

Add this into potion onUseItem function
SpoilerShow

Code: Select all

   champion:upgradeBaseStat("strength", 1)	
   delayedCall("yourscript",20,"yourfunction",champion:getOrdinal())
And name your script entity "yourscript" with this function:
SpoilerShow

Code: Select all

function yourfunction(champ)
	local ch = party.party:getChampion(champ)
	local modi = ch:getBaseStat("strength")
        local base = modi -1
        ch:setBaseStat("strength",base)
end
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Temporary potion effects [solved]

Post by Drakkan »

Aisuu wrote:Thx Batty. With your help and inspirations of others I was able to solve it :)
Here is complete solution and example for adding +1 strenght to champion for 20 seconds.

Add this into potion onUseItem function
SpoilerShow

Code: Select all

   champion:upgradeBaseStat("strength", 1)	
   delayedCall("yourscript",20,"yourfunction",champion:getOrdinal())
And name your script entity "yourscript" with this function:
SpoilerShow

Code: Select all

function yourfunction(champ)
	local ch = party.party:getChampion(champ)
	local modi = ch:getBaseStat("strength")
        local base = modi -1
        ch:setBaseStat("strength",base)
end
could please somebody extend this script so it will return point to the champion which used the potion ? In case you move champion to some other slot, script does not detect it and return point to another one. thanks a lot
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply