[Open / Signup] One Room Round Robin 3 - Calling All Modders

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: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by AndakRainor »

minmay wrote:
AndakRainor wrote:import "mod_assets/party.lua" comes last in init.lua. Is it not a problem ?
If fw_hooks sees something already set for the hook field in the component, it won't add its own hook and you won't be able to use fw hooks there. So whoever added that onDrawGui hook in party.lua made it impossible for anyone to use fw hooks for PartyComponent.onDrawGui, but they can still use them for the rest of the PartyComponent hooks. If you add your hooks to the PartyComponent definition instead of using fw.script:set(), then you'll remove every other modder's ability to use those hooks, and break all the existing ones. Use. The. Framework. Hooks.
I understood all that, and I agree to use the framework... I just try to get more info about it because I never used it.

If I get it correctly, the fw.script:set() function will be called after the initialization phase of the mod? How could I be sure that the hooks I add are the first ones for those 3 functions, to prevent other modders' hooks to trigger on a canceled event?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by minmay »

AndakRainor wrote:
minmay wrote:
AndakRainor wrote:import "mod_assets/party.lua" comes last in init.lua. Is it not a problem ?
If fw_hooks sees something already set for the hook field in the component, it won't add its own hook and you won't be able to use fw hooks there. So whoever added that onDrawGui hook in party.lua made it impossible for anyone to use fw hooks for PartyComponent.onDrawGui, but they can still use them for the rest of the PartyComponent hooks. If you add your hooks to the PartyComponent definition instead of using fw.script:set(), then you'll remove every other modder's ability to use those hooks, and break all the existing ones. Use. The. Framework. Hooks.
I understood all that, and I agree to use the framework... I just try to get more info about it because I never used it.

If I get it correctly, the fw.script:set() function will be called after the initialization phase of the mod? How could I be sure that the hooks I add are the first ones for those 3 functions, to prevent other modders' hooks to trigger on a canceled event?
Oh, that's what you meant. ScriptComponent sources will execute in the order they are spawned, so stick them on level 1 and you'll be fine. (They'll run after GrimTK's hooks but that's actually what you want, GrimTK's should run before yours.) Xanathar's room uses connectors instead of fw hooks, and connectors run after all fw hooks no matter what, so those are no problem either.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by AndakRainor »

So I have this in the spell pack init file:
SpoilerShow

Code: Select all

defineObject
{
  name = "party",
  baseObject = "party",
  components = {
    {
      class = "Timer",
      name = "spellPackTimer",
      timerInterval = 0,
      triggerOnStart = true,
      onActivate = function(self)
        spells_functions.script.moveLights()
      end,
      onInit = function(self)
        fw.script:set('party.spell_pack.onCastSpell',function(hook,party,champion,spellName)
          return spells_functions.script.onCastSpell(champion, spellName)
        end)
        fw.script:set('party.spell_pack.onWakeUp',function(hook,party)
          return not spells_functions.script.deepSleep
        end)
        fw.script:set('party.spell_pack.onDamage',function(hook,party,champion,damage,damageType)
          return spells_functions.script.onDamage(champion, damage, damageType)
        end)
      end,
    },
  },
}
and the unmodified code in party.lua:
SpoilerShow

Code: Select all

defineObject
{
  name = "party",
  baseObject = "party",
  components = {
    fw_addHooks{
      class = "Party",
      onDrawGui = function(party,g)
        --Dummy hook for enabling onDrawGui-connectors
      end,
    },
  },
}
I added the hooks in this onInit call because in a script code on the first map, I got an error with "fw" not already defined (nil global). I don't really understand why this happened as my script entity was two tiles to the right of the "fw" script. Will it work that way?

Also, why is there an onDrawGui function defined in party.lua exactly? You say it should not, but on the hook framework web page I can read "Enable all party hooks (except onDraw...)" in the first example.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by minmay »

AndakRainor wrote:I added the hooks in this onInit call because in a script code on the first map, I got an error with "fw" not already defined (nil global). I don't really understand why this happened as my script entity was two tiles to the right of the "fw" script. Will it work that way?
All onInit hooks run before script entity sources on the same level (but before script entity sources on the next level). I assumed you were going to set the hooks in a ScriptComponent, since, again, you should set them after the GrimTK hooks instead of before. If for some reason you want to do it in an onInit hook instead you'll need to put the object with the onInit hook on level 2.
AndakRainor wrote:Also, why is there an onDrawGui function defined in party.lua exactly?
Because someone wasn't interested in learning how to use the hook framework.
AndakRainor wrote:You say it should not, but on the hook framework web page I can read "Enable all party hooks (except onDraw...)" in the first example.
Yes, that component definition enables all fw hooks except for onDrawGui because the framework won't overwrite existing hooks.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by AndakRainor »

What is that horror :o

Code: Select all

local partyDistance = (math.abs(wpos[1]-ppos[1])^3+math.abs(wpos[2]-ppos[2])^3+math.abs(wpos[3]-ppos[3])^3)^(1/3)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by minmay »

AndakRainor wrote:What is that horror :o

Code: Select all

local partyDistance = (math.abs(wpos[1]-ppos[1])^3+math.abs(wpos[2]-ppos[2])^3+math.abs(wpos[3]-ppos[3])^3)^(1/3)
It's the formula for the Euclidean distance between two points in 3D space. This code would give the same result:

Code: Select all

local distanceVector = object1:getWorldPosition()-object2:getWorldPosition()
local distance = math.abs(distanceVector[1]^3+distanceVector[2]^3+distanceVector[3]^3)^(1/3)
if you want something nicer to look at.
(Also the reason some temporary variables are put in GameMode instead of a ScriptComponent somewhere in my room is that I'm worried people would copy/paste the items into their own dungeons without copying the ScriptComponent.)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by AndakRainor »

minmay wrote:
AndakRainor wrote:What is that horror :o

Code: Select all

local partyDistance = (math.abs(wpos[1]-ppos[1])^3+math.abs(wpos[2]-ppos[2])^3+math.abs(wpos[3]-ppos[3])^3)^(1/3)
It's the formula for the Euclidean distance between two points in 3D space. This code would give the same result:

Code: Select all

local distanceVector = object1:getWorldPosition()-object2:getWorldPosition()
local distance = math.abs(distanceVector[1]^3+distanceVector[2]^3+distanceVector[3]^3)^(1/3)
if you want something nicer to look at.
Sorry but the Euclidian distance is always the square root of the sum of the squares, in all Euclidian spaces of all number of dimensions :)
(Pythagore look away!)
https://en.wikipedia.org/wiki/Euclidean_distance
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by minmay »

Oops, you're quite correct! That line made it into the gobj.lua monstrosity long ago, and I never noticed the problem even when it was staring me in the face. Thanks for bringing it to my attention.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by AndakRainor »

So I have integrated both our spells in the project. Before I upload it, I have some testing and debugging to do.

I am trying to make hailstorm do triple damage to frozen monsters (and obstacles if possible). I tried with:

Code: Select all

      onHitMonster = function(self, monster)
        if monster:isAlive() and (monster.go.frozen or monster:isImmuneTo("frozen")) then
          -- triple damage on frozen or immune to frozen targets
          self:setAttackPower(9000)
          print(monster.go.name.." takes triple damage")
        end
      end,
      onHitObstacle = function(self, obstacle)
        -- triple damage on frozen or immune to frozen targets
        self:setAttackPower(9000) 
        print(obstacle.go.name.." takes triple damage")
      end,
But it is too late at that point to change the damage dealt, from my tests. How would you do it? (The 9000 value is there just for the test...)
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: [Open / Signup] One Room Round Robin 3 - Calling All Mod

Post by minmay »

Not sure why you want hailstorm to do that in the first place - it's supposed to be weaker against cold-immune targets, not stronger. But I would suggest making a new TileDamager with tripled attack power, and returning false from the first one.
Guess I'll have to come up with a new ability for the Sceptre of Colours instead of a firebeam clone, since actual firebeam is in the dungeon now. Also I'm going to have to replace discharge because its ability to attack diagonally could break some rooms (the implementation of it sucks anyway).

Also the spells in the current public version of MinAssets is a little outdated, so I'll update them to the current versions when I next get the file. Still not sure we actually want that many extra spells though.
Last edited by minmay on Sat Jul 16, 2016 11:37 pm, edited 1 time in total.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply