Page 1 of 1

Scripting help (joining two scripts together) - SOLVED

Posted: Tue Feb 26, 2013 12:41 am
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]

Re: Scripting help (joining two scripts together)

Posted: Tue Feb 26, 2013 2:34 am
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?

Re: Scripting help (joining two scripts together)

Posted: Tue Feb 26, 2013 5:51 am
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?

Re: Scripting help (joining two scripts together)

Posted: Tue Feb 26, 2013 10:59 am
by Drakkan
thanks guys, its working correctly now !
Marble Mouth wrote:PPS: Were you able to get cloned crafting items to work?
nope :/

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

Posted: Wed Feb 27, 2013 12:35 am
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.

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

Posted: Wed Mar 06, 2013 7:03 pm
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...

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

Posted: Wed Mar 06, 2013 10:33 pm
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)