Page 1 of 2

Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 8:24 am
by Grimfan
I know how to make doors open and spawn stuff by placing objects on an altar or in an alcove, but how do I destroy and object placed onto or into one of these entities?

I'm sure it's got to do with creating a table of objects or something and I've been looking over the boards, but haven't found anything that really answers my question.

Can someone give me a basic rundown of the sort of script I might need? I know it's probably something that can be done simply, but for the life of me I don't know precisely how to start.

Many thanks in advance! :)

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 9:25 am
by Xanathar
If the item is directly in the alcove (that is not in a sack in the alcove), just call destroy on the item.

Bug beware : if you throw an item over an altar and destroy it inside the trigger of the altar, the game crashes :(
You can workaround this bug using a fast timer to delay the destroy of some microsecond :(

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 10:24 am
by Grimfan
Yes, I can destroy an object using that method, but only if it is longsword_1 or something like that (like a specific object).

I want the altar to destroy every longsword placed on it, whether it's longsword_1 or longsword_36. I don't think I can do that with the destroy object script unless I repeat it 36 times. In fact I want to be able to destroy any instance of a longsword being on the altar or in the alcove.

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 10:55 am
by aaneton
Hi,
this code will destroy all "long_sword":s on altars/alcoves (named my_altar) no matter what the sword ID is.

Code: Select all

function LongswordCheck()
   for i in my_altar:containedItems() do
      if i.name == "long_sword" then
         i:destroy()
         hudPrint("Sword destoryed")
      end
   end
end

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 11:16 am
by Drakkan
if you wanna create specific item, open your dungeon script folder and edit items.lua file.

Lets say you want create unique longsword, in that case insert

cloneObject{
name = "mega_sword", -- this name will be displayed in your dungeon editor and you need use it if you wanna destroy it later
baseObject = "long_sword", -- this is which base object (stats) will be copied
uiName = "My name is Mega", -- this will be displayed to player
}

then save and reload your dungeon. Item mega_sword will appear in items you can place into your dungeon, so you can now also destroy it. Hope this is what you wanted ? :)

Ps: you can modify almost anything you want, see detailed assets definiton for each objects.
http://www.grimrock.net/modding/asset-d ... reference/

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 11:58 am
by Komag
aaneton wrote:Hi,
this code will destroy all "long_sword":s on altars/alcoves (named my_altar) no matter what the sword ID is.

Code: Select all

function LongswordCheck()
   for i in my_altar:containedItems() do
      if i.name == "long_sword" then
         i:destroy()
         hudPrint("Sword destoryed")
      end
   end
end
You can link the altars/alcoves to a fast 0.05s timer connected to run this script (and connected to itself to deactivate). If you have a lot of altars and alcoves, you can set it up more universally by linking the alcove/altars to an inbetween script:

Code: Select all

function swordKillStart(container)
  theContainer = container.id
  swordKillTimer:activate() -- 0.05s triggers longswordCheck()
end

theContainer = "none"

function LongswordCheck()
  if theContainer == "none" then return end
  for i in theContainer:containedItems() do
    if i.name == "long_sword" then
       i:destroy()
       print("sword destroyed")
       hudPrint("Your puny weak blades cannot withstand my power, bwahahaha!")
    end
  end
  theContainer = "none"
end

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 2:15 pm
by Grimfan
Thanks aaneton and Komag for the quick replies and great help, and Drakkan for giving me something else to consider. You're the reason this forum is great. :D

I was very close with this one. I just kept putting longsword instead of i. :roll: And yes, the longsword script is working fantastic. :)

Actually, that gives me an idea. What would be the best method for causing a weapon to break if it struck a particular monster? Like slimes that dissolve melee weapons and require spells or projectiles to kill. Would it be an onHit hook or something similar?

Of course the players would receive a warning (in a scroll or such) before it happens. ;)

Re: Destroying objects on an Altar or in an Alcove

Posted: Tue Jan 29, 2013 6:05 pm
by Komag
It would primarily be the party hook:

onAttack: a hook which is called when a champion attacks. The function gets two parameters: the attacking champion and the weapon used to attack. The weapon parameter is nil for unarmed attacks. If the function returns false, the attack is cancelled.

It's one of the only hooks that gives the weapon used. But since you only want it to work when a monster is hit with it, you would need to combine it with the monster hook:

onDamage: a hook which is called when the monster is damaged. The function gets the following parameters: the monster itself, amount of damage and the damage type (e.g. “physical”, “fire”, etc.). If the function returns false, the monster receives no damage.

have onAttack set a variable (swordSwung = true) and start a short timer (attackTimer, 0.1s maybe).
When the monster gets an onDamage have that run a script that checks whether swordSwung is true (if swordSwung then...), and if so then do the sword breaking stuff
attackTimer then triggers a script that sets the variable back (swordSwung = false)

I don't know if that will actually work, just a theory

Re: Destroying objects on an Altar or in an Alcove

Posted: Sun Feb 10, 2013 9:38 am
by akroma222
Hey Komag,
Have you tried this out yet?
I figure it would be a pretty good way to mimic a drain life effect for weapons
....as lifeleech is hardcoded :-/....

Re: Destroying objects on an Altar or in an Alcove

Posted: Sun Feb 10, 2013 12:51 pm
by Komag
I haven't tried it as I'm not using it in my project, and I just don't have time to explore experimental stuff right now, sorry :(