Wagtunes' Modding Questions

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Isaac wrote: Thu May 06, 2021 7:06 pm
wagtunes wrote: Thu May 06, 2021 3:26 pmI'm guessing that by fiddling with these coordinates I can make it so that the item appears at the top of the catacomb, which I have seen in several dungeons.
In the Foundry there are shelves that accept items on both top & bottom.

I don't have the source project with me, but I think I used two alcoves with different click regions to do it. So both have to be on the same tile, with the same facing. (Or I might have automated this, via script. :? )
Yes, I know the acloves you're talking about. I have the source code for ORR 2 so I'll check it out. Of course finding anything in that maze is extremely difficult.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

They are in the Foreman's office, and the pantry.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Okay, not sure how to handle this.

Code: Select all

function checkAlcoveForItems()
   -- change these variables to match your alcove's ID and the item you want to test for
   local itemName1 = "gold_key"
   local alcoveID1 = temple_alcove_38
   
   
   -- iterate through all the contained items on alcove, checking for a matching name
   for i in alcoveID1:containedItems() do
      if i.name == itemName1 then
         itemFound1()
             
      end
   end
end

-- run this script _once for each item_ with a matching name
function itemFound1()
   	goldkeyaltar:destroy()
   end
end
If I try to put the key in the alcove a second time, I get an error because the altar no longer exists. Obviously because it's gone.

So, is there a check to see if something exists function that I can call before I destroy the altar? That way, if it doesn't exist, I can bypass the destroy command.

So something like...

If goldkeyaltar:exists() then

Do we have something like that?

** EDIT ** Found it. findEntity
User avatar
7Soul
Posts: 209
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Useful scripts repository

Post by 7Soul »

wagtunes wrote: Fri May 07, 2021 3:53 am So, is there a check to see if something exists function that I can call before I destroy the altar? That way, if it doesn't exist, I can bypass the destroy command.

So something like...

If goldkeyaltar:exists() then

Do we have something like that?

** EDIT ** Found it. findEntity
A more efficient way is to do simply

Code: Select all

if goldkeyaltar then
findEntity is better for when you're trying to find an object with a name based on a variable
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

7Soul wrote: Fri May 07, 2021 9:05 pm
wagtunes wrote: Fri May 07, 2021 3:53 am So, is there a check to see if something exists function that I can call before I destroy the altar? That way, if it doesn't exist, I can bypass the destroy command.

So something like...

If goldkeyaltar:exists() then

Do we have something like that?

** EDIT ** Found it. findEntity
A more efficient way is to do simply

Code: Select all

if goldkeyaltar then
findEntity is better for when you're trying to find an object with a name based on a variable
Thanks. I didn't know if that kind of syntax would work. Finding syntax help for this language is not what I'd call easy. A lot of it, for me anyway, has been guesswork.

Anyway, the code is written so I'm just going to leave it the way it is. In the future I'll switch to this syntax.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

FindEntity() returns the found entity or nil.
Always know what happens if your test/ or instruction is given nil.

Lua can treat false and nil as the same in conditions, but they are not the same. There are situations where a nil value can crash the game. False means false, and nil means 'nothing'.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Okay, I'm a bit stumped. Here's the scenario.

I created a custom potion similar to the potion of umbral solution in ORR 2. This potion, when put into an alcove opens the door next to the alcove. It's called potionunlocking.

I don't want the potion to be a forever use thing where after it's put into the alcove the champion can just remove it and use it over and over. So I want it destroyed when it's put into the altar but after the door is opened.

I've tried everything I can think of but every name I try to reference I come up with a nil value.

Here is what I have right now. Obviously, it's wrong.

Code: Select all

function checkAlcoveForItems()
   -- change these variables to match your alcove's ID and the item you want to test for
   local itemName1 = "potionunlocking"
   local alcoveID1 = temple_alcove_10
   counter = 0
   
   -- iterate through all the contained items on alcove, checking for a matching name
   for i in alcoveID1:containedItems() do
      if i.name == itemName1 then
		itemFound1()
      end
   end
end

-- run this script _once for each item_ with a matching name
function itemFound1()
   counter = counter+1
   if counter == 1 then
   temple_door_metal_2:open();
	potionunlocking:destroy()
   end
end

I've tried i.name, itemName, alcoveID1:containedItems() , nothing works.

I'll try to see if I can find the code in ORR 2 but that's like looking for a needle in a haystack.
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

I found the ORR 2 code

Code: Select all

function sfjndUmbralCorpseContents(entity, item)
for i in entity:containedItems() do
if i.name == item then
return true
end
end
return false
end

function sfjndUmbralCorpseCheck()
if sfjndUmbralCorpseContents(sfjndumbralcorpse, "potionabsolution")
then
sfjndtemple_door_iron_2:close()
	sfjndtimer_1:activate()
		help.safeDestroy(sfjndlever_2)
		help.safeDestroy(sf_temple_wall_final)
		spawn("itm_key_swirl", 8, 10, 7, 3)
		temple_door_ornament_1:close();
		orrrManager.exitRoom(2);
		orrrManager.activateHub(8);
		orrrManager.completeRoom(2)
	 		spawn("temple_wall_text", 8, 10, 6, 3, "sfjndtext")
				sfjndtext:setWallText("I said no admittance, and I meant it! -THE WARDEN")
	end
end
But it doesn't help me. It doesn't appear that the potion itself is destroyed.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Useful scripts repository

Post by Isaac »

To destroy it, you must access it from the alcove it is contained within.
SpoilerShow

Code: Select all

function destroySpecialPotion(self) 
	local alcove = self
	potionName = "potionunlocking"
	
	if type(alcove) == "table" and string.match(alcove.name,"alcove") then
		for itm in alcove:containedItems() do -------------------------------------------{The alcove's contained items iterator}
			if itm.name == potionName then
				
				--optional effects
					local effect = spawn("fx",itm.level,itm.x,itm.y,itm.facing)
						effect:translate(0,1.3,0)
						effect:setParticleSystem("blob")
						effect:setLight(0, 0, 1, 1000, 2, .5, true)
						playSound("goromorg_shield_hit")
				--/optional effects
						
				itm:destroy()
			end	
		end	
	end	
end
*Updated!
(Minor tweak)
wagtunes
Posts: 316
Joined: Sun Feb 04, 2018 11:04 pm

Re: Useful scripts repository

Post by wagtunes »

Isaac wrote: Sun May 09, 2021 11:23 pm To destroy it, you must access it from the alcove it is contained within.
SpoilerShow

Code: Select all

function destroySpecialPotion(self) 
	local alcove = self
	potionName = "potionunlocking"
	
	if type(alcove) == "table" and string.match(alcove.name,"alcove") then
		for itm in alcove:containedItems() do -------------------------------------------{The alcove's contained items iterator}
			if itm.name == potionName then
				
				--optional effects
					local effect = spawn("fx",itm.level,itm.x,itm.y,itm.facing)
						effect:translate(0,1.3,0)
						effect:setParticleSystem("blob")
						effect:setLight(0, 0, 1, 1000, 2, .5, true)
						playSound("goromorg_shield_hit")
				--/optional effects
						
				itm:destroy()
			end	
		end	
	end	
end
*Updated!
(Minor tweak)
Thank you very much. That did it. Now I have to study this function so I can understand why and how it works.
Post Reply