Ask a simple question, get a simple answer

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
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

AndakRainor wrote:- If you ignore the compatibility warning and load your old save game file, the definitions of new objects in the new mod version are never defined, the init phase occurring only once.
Sorry, I don't know how I came to this conclusion, it is totally wrong.

You can spawn objects from new definitions when updating a mod. This will allow me to make some patches for old versions upgrades. But even with that, it is still forbidden to assign a new value to a function in an existing script component. So I will have to use addConnector on the new spawned script object to achieve anything (or use another hack from Minmay!)
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

AndakRainor wrote:
zimberzimber wrote:recomputeStats in traits comes after heroes?
If so, I'm just gonna give every champion a hidden trait for all the stat sharing.
I am not sure what you mean there, but the various onRecomputeStats functions are called in some order, I don't know which one. I you want to know exactly this order, you could print some messages in all EquipmentItemComponent, skills and traits of champions, (in races, classes, ...) then see if they always appear in the same order.

But you can be nearly sure, when inside a onRecomputeStats function that you won't be in the last one to be executed, so the stats you can read from champions are not final, they are being built, you can't trust their current value. It is possible for example that your protection was still 0 at the time you read it.

All thoses functions are called every frame, before any timer component triggers, so you could use a timer to get the current value of a stat, but not while they are being calculated.
Sorry for the unearthing of this topic - has anyone tested the order of onRecomputeStat hooks ... ??
I tried, printing each source and the total protection (each added a diff amount) ...

I ended up getting the order as:
Condition , Class trait , trait , Race trait , Condition tick (set to 0)

Can anyone confirm or correct this??
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Why are all sounds except for level tracks are disabled when switching to a non-party camera?
(Both on the cameras location, and the parties location)
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

About stats recompute order, I can say one thing for sure, condition tick comes always after the recompute process. It means you can read the stats values in this function and trust the result 100%. That also means that you can't modify thoses values there, as it will be executed too late (but to be sure, you should also see if it always comes before or after normal timers hooks, combat damage calculation and frame rendering with onDrawGui). I think I have a very good example with the "might" condition. This really simplified and made my code cleaner and less buggy:

Code: Select all

defineCondition
{ name = "might",
  uiName = "Might",
  description = "Doubles strength, dexterity, vitality and willpower.",
  icon = 0,
  iconAtlas = path.."textures/gui/conditions/might.tga",
  beneficial = true,
  harmful = false,
  tickInterval = 0,
  onStart = function(self, champion)
    local ordinal = champion:getOrdinal()
    for att,tab in pairs(spells_functions.script.might) do tab[ordinal] = champion:getCurrentStat(att) end
  end,
  onStop = function(self, champion)
    local ordinal = champion:getOrdinal()
    for att,tab in pairs(spells_functions.script.might) do tab[ordinal] = 0 end
  end,
  onRecomputeStats = function(self, champion)
    local ordinal = champion:getOrdinal()
    for att,tab in pairs(spells_functions.script.might) do champion:addStatModifier(att, tab[ordinal]) end
  end,
  onTick = function(self, champion)
    local ordinal = champion:getOrdinal()
    for att,tab in pairs(spells_functions.script.might) do tab[ordinal] = champion:getCurrentStat(att) - tab[ordinal] end
  end,
}
You can see the onTick is used to read values and store them until the next frame. The previous value is substracted to get only the value without the previous contribution of might. When it's time for the next frame, all stat modifiers are cleared and all recomputes are redone, and during that process, at any time, might gives the value stored from the previous frame. So you could say, might is always one frame late when a stat changes. It is still better than my previous 1 second refresh interval and when trying to give bonuses to champions that also depend on other present bonuses, I think it is logically the best thing you can do. Again because, unless I'm proven wrong, when all recomputes are done, it is too late to add another modifier.

For the non-party camera sounds mute, I can only say that it is exactly the same effect you get when you disable all champions... I guess it is somehow the same problem.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

AndakRainor wrote:For the non-party camera sounds mute, I can only say that it is exactly the same effect you get when you disable all champions... I guess it is somehow the same problem.
Agh forgot about this. I disabled all champions when using the camera.
Now to find a way to hide champions, but keep the GUI.
Any ideas?
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

I tried that a lot some time ago, for a tavern GUI. There is no solution at all! I disable champions and use only the level track while in this interface (then restore it on exit). If you don't disable champions, and draw over them for example, they will still react to mouse and keayboard commands... I think you will have to find another idea for that sequence you try to build.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Hmm...
Is there a way to change a levels ambient track through scripts?
If not, I'll just teleport the party into a level with the ambient track and disable champions :lol:

Another question - Can you change champion data while they're disabled? (health, inventory, traits, etc...)
EDIT: Yes, you can.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

So far so good!
Has but one issue - Sound doesn't fade when changing level. Not a biggie.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

You can also use GameMode.playStream("my_music")

edit; nice fire frog boss ;)
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

AndakRainor wrote:You can also use GameMode.playStream("my_music")

edit; nice fire frog boss ;)
I don't have the time to experiment with it right now, but can it fade in/out?

That boss is a meme Image
My asset pack [v1.10]
Features a bit of everything! :D
Post Reply