Destroying objects on an Altar or in an Alcove

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Destroying objects on an Altar or in an Alcove

Post by Grimfan » Tue Jan 29, 2013 8:24 am

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! :)

User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Destroying objects on an Altar or in an Alcove

Post by Xanathar » Tue Jan 29, 2013 9:25 am

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 :(
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org

Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Destroying objects on an Altar or in an Alcove

Post by Grimfan » Tue Jan 29, 2013 10:24 am

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.

User avatar
aaneton
Posts: 189
Joined: Fri Sep 21, 2012 1:53 pm

Re: Destroying objects on an Altar or in an Alcove

Post by aaneton » Tue Jan 29, 2013 10:55 am

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
My Grimrock mod (LoG1): The Onkalo Project
My Android (and windows desktop) game: Balloon Gentleman

User avatar
Drakkan
Posts: 1317
Joined: Mon Dec 31, 2012 12:25 am

Re: Destroying objects on an Altar or in an Alcove

Post by Drakkan » Tue Jan 29, 2013 11:16 am

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/
Breath from the unpromising waters.
Eye of the Atlantis

User avatar
Komag
Posts: 3634
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Destroying objects on an Altar or in an Alcove

Post by Komag » Tue Jan 29, 2013 11:58 am

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
Finished Dungeons - complete mods to play

Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Destroying objects on an Altar or in an Alcove

Post by Grimfan » Tue Jan 29, 2013 2:15 pm

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. ;)

User avatar
Komag
Posts: 3634
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Destroying objects on an Altar or in an Alcove

Post by Komag » Tue Jan 29, 2013 6:05 pm

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
Finished Dungeons - complete mods to play

User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Destroying objects on an Altar or in an Alcove

Post by akroma222 » Sun Feb 10, 2013 9:38 am

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 :-/....

User avatar
Komag
Posts: 3634
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Destroying objects on an Altar or in an Alcove

Post by Komag » Sun Feb 10, 2013 12:51 pm

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 :(
Finished Dungeons - complete mods to play

Post Reply