Scripting help (joining two scripts together) - SOLVED

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Scripting help (joining two scripts together) - SOLVED

Post by Drakkan »

Hi folks. If somebody around could help me I will be greatful. What I need is connect somehow two scripts together.
What I need to do is when monster skeleton_ghost kill any champion wearing item called false_amulet, then cinematic start to play.

I have created party ondie hook

cloneObject{
name = "party",
baseObject = "party",
onDie = function()
murderMystery.checkWhoDidIt()
end,
}

and script which which will start cinematic if ANY member is killed, no matter if that amulet is equiped or not

Code: Select all

    suspectedMurderer = "skeleton_ghost"
    function checkWhoDidIt()
       local x = ""
       local y = ""
       for i=1,4 do
          if i==1 then
             x = party.x+1
          elseif i == 3 then
             x = party.x-1
          else
             x = party.x
          end

          if i==2 then
             y = party.y+1
          elseif i == 4 then
             y = party.y-1
          else
             y = party.y
          end

          for j in entitiesAt(party.level, x, y) do
             if j.name == suspectedMurderer then
               completeGame("mod_assets/cinematics/ending2.lua")
                 return
             end
          end
       end
    end
I need connect it somehow with iterator equiped item check on that amulet which could be something like

function itemCheck(item)
for champ = 1,4 do
for slot = x do (do not know which slot is equiped amulet now)
local x = party:getChampion(champ):getItem(slot)
if x ~= nil then
if x.name == "false_amulet" then
....

Hope its understable.
[/spoiler]
Last edited by Drakkan on Tue Feb 26, 2013 11:00 am, edited 1 time in total.
Breath from the unpromising waters.
Eye of the Atlantis
Marble Mouth
Posts: 52
Joined: Sun Feb 10, 2013 12:46 am
Location: Dorchester, MA, USA

Re: Scripting help (joining two scripts together)

Post by Marble Mouth »

Hi Drakkan. I would start by changing your onDie hook just a little:

Code: Select all

cloneObject{
name = "party",
baseObject = "party",
onDie = function( champion )
murderMystery.checkWhoDidIt( champion )
end,
}
From the ADR: "The function gets one parameter, the dying champion."

Then your script has to accept this parameter and use it to check that champion's equipment:

Code: Select all

suspectedMurderer = "skeleton_ghost"
        function checkWhoDidIt( champion )

        local deadChampionNeckItem = champion:getItem( 6 ) --neck slot == 6
        if ( not deadChampionNeckItem ) or ( not ( deadChampionNeckItem.name == "false_amulet" ) ) then
                return --don't continue checking if the dead champion doesn't have a neck item, or that item is not named "false_amulet"
        end
        
           for i=1,4 do
                local x , y = getForward( i )
                x = x + party.x
                y = y + party.y

              for j in entitiesAt(party.level, x, y) do
                 if j.name == suspectedMurderer then
                   completeGame("mod_assets/cinematics/ending2.lua")
                     return
                 end
              end
           end
        end
I replaced some of your script with the recently standardized function getForward. Note that the script you have above will only check if a monster named "skeleton_ghost" is next to the party. If this monster has ranged attacks, then it might not be next to the party when the champion dies. Also, if a different monster kills the champion while the "skeleton_ghost" is next to the party, that will satisfy the script. Maybe these considerations don't apply to your dungeon. If either (or both) of these possibilities is a problem, you could consider adding an onDealDamage hook to the "skeleton_ghost" to check if it's actually landing the killing blow.

PS: It's generally redundant to write:

Code: Select all

if x ~= nil then
in lua. You can simply write:

Code: Select all

if x then
The only exception is when x could have the boolean-type value false. If x is any other data type (in your example, the type of x will be either table or nil, it will never be boolean) then the two lines above are equivalent.

PPS: Were you able to get cloned crafting items to work?
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: Scripting help (joining two scripts together)

Post by Diarmuid »

Marble Mouth wrote: Note that the script you have above will only check if a monster named "skeleton_ghost" is next to the party. If this monster has ranged attacks, then it might not be next to the party when the champion dies. Also, if a different monster kills the champion while the "skeleton_ghost" is next to the party, that will satisfy the script. Maybe these considerations don't apply to your dungeon. If either (or both) of these possibilities is a problem, you could consider adding an onDealDamage hook to the "skeleton_ghost" to check if it's actually landing the killing blow.
That's why I suggested this structure to drakkan when he subbmitted me his script:

Code: Select all

-- monster hook
onDealDamage = function(monster)
 dieHookScript.setLastMonster(monster)
end

-- party hook
onDie = function(champion)
 dieHookScript.championDied()
end

-- dieHookScript
lastMonster = nil

function setLastMonster(monster)
 lastMonster = monster.name
end

function championDied()
 if lastMonster == "The_Big_Bad_Guy" then
  -- Do whatever you want
 end
end
Does anyone know if onDealDamge works when monsters cast spells?
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Scripting help (joining two scripts together)

Post by Drakkan »

thanks guys, its working correctly now !
Marble Mouth wrote:PPS: Were you able to get cloned crafting items to work?
nope :/
Breath from the unpromising waters.
Eye of the Atlantis
Marble Mouth
Posts: 52
Joined: Sun Feb 10, 2013 12:46 am
Location: Dorchester, MA, USA

Re: Scripting help (joining two scripts together) - SOLVED

Post by Marble Mouth »

Woops, getForward expects a number from 0 to 3 inclusive, not 1 to 4 inclusive.

Code: Select all

    suspectedMurderer = "skeleton_ghost"
            function checkWhoDidIt( champion )

            local deadChampionNeckItem = champion:getItem( 6 ) --neck slot == 6
            if ( not deadChampionNeckItem ) or ( not ( deadChampionNeckItem.name == "false_amulet" ) ) then
                    return --don't continue checking if the dead champion doesn't have a neck item, or that item is not named "false_amulet"
            end
           
               for i=0,3 do
                    local x , y = getForward( i )
                    x = x + party.x
                    y = y + party.y

                  for j in entitiesAt(party.level, x, y) do
                     if j.name == suspectedMurderer then
                       completeGame("mod_assets/cinematics/ending2.lua")
                         return
                     end
                  end
               end
            end

My bad.
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Scripting help (joining two scripts together) - SOLVED

Post by akroma222 »

Diarmuid -
I do not think so... I tried for a few hours today, hoping to get enemy thrown frostbolts to paralyze the party - but to no avail
Surely it would be possible with all the new scripting/hooking framework?? (I have not gotten started on it yet.....)

Something I have noticed though with the onDealDamage Hook... if your guys are disabled (through set/get Enable) the monsters will crash the game when they try to eat you... trying to find a work around atm...
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Scripting help (joining two scripts together) - SOLVED

Post by Drakkan »

akroma222 wrote:Diarmuid -
I do not think so... I tried for a few hours today, hoping to get enemy thrown frostbolts to paralyze the party - but to no avail
Surely it would be possible with all the new scripting/hooking framework?? (I have not gotten started on it yet.....)

Something I have noticed though with the onDealDamage Hook... if your guys are disabled (through set/get Enable) the monsters will crash the game when they try to eat you... trying to find a work around atm...
not sure what are you refering to, I have tried it and its working fine (no crash when another creature kill the champion while amulet is on)
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply