[Solved/Item/Spell] Way to tell if party is underwater?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by Isaac »

A counter & timer could hudPrint() the time remaining; [start/stop the timer in the item's equip/unequip hooks].

Make a dive_time counter, connect a timer to it set to 1 second interval and to decrement the counter. Set the counter to remove the water_breathing trait via script.

and use something like...

hudPrint("") hudPrint("") hudPrint("") hudPrint(tostring(dive_time.counter:getValue()).." seconds of air remaining")

...to print out the time that's left.
User avatar
sps999
Posts: 44
Joined: Sun Oct 26, 2014 11:16 pm

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by sps999 »

Using the same method I imagine you might be able to set the timer to a boss health bar too. Instead of printing out the timer value set the boss NPC's health to that value. I'm not sure on the specifics of boss timers but if you are able to add health to the enemy it should be fine.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by Isaac »

sps999 wrote:Using the same method I imagine you might be able to set the timer to a boss health bar too. Instead of printing out the timer value set the boss NPC's health to that value. I'm not sure on the specifics of boss timers but if you are able to add health to the enemy it should be fine.
I thought about that; it's more complex, but Skuggs has a tutorial for just that idea. https://www.youtube.com/watch?v=-YlAZwqcptc

*It involves an off-screen monster that gets damaged over time ~via script. The boss healthbar diminishes, just as an air meter would.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by bongobeat »

thanks for your answers:
I'm trying to do it, step by step:

pls can you tell me what is wrong in this script?
I got an error after equiping the helmet

diving_timer is the name of the timer I'm actually using

Code: Select all

-- scuba gear
    defineObject {
       name = "diving_helmet",
       baseObject = "full_helmet",
       components = {
          {
             class="Item",
             weight = 3.0,
              uiName = "Diving Helmet",
             gfxIndex = 93,
             traits = { "helmet" },
             onEquipItem=function(self,champion,slot)
                if slot==3 then
                   champion:setCondition("water_breathing")
				diving_timer:activate()
                end
             end,
             onUnequipItem=function(self,champion,slot)
                if slot==3 then
				diving_timer:deactivate()
                   champion:removeCondition("water_breathing")
                end
             end
             
          },
{
			class = "EquipmentItem",
			protection = 1,
		},
       }
    }

My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by Isaac »

bongobeat wrote: pls can you tell me what is wrong in this script?
I got an error after equiping the helmet
diving_timer.timer:start()
diving_timer.timer:stop()
_______________________________________________________________

This should have been in the base game. 8-)
This is fun to use.

*Altered Script ... [Still gives no warning about the air supply running out.]

Code: Select all

   -- scuba gear

        defineObject {
           name = "diving_helmet",
           baseObject = "full_helmet",
           components = {
              {
                 class="Item",
                 weight = 3.0,
                  uiName = "Diving Helmet",
                 gfxIndex = 93,
                 traits = { "helmet" },
                 onEquipItem=function(self,champion,slot)
                    if slot==3 then
                       champion:setCondition("water_breathing")
                diving_timer.timer:start()
                    end
                 end,
                 onUnequipItem=function(self,champion,slot)
                    if slot==3 then
                diving_timer.timer:stop()
                       champion:removeCondition("water_breathing")
                    end
                 end

              },
    {
             class = "EquipmentItem",
             protection = 1,
          },
           }
        }
** I've been tinkering with this a bit more (beyond the script above)... It's not ready for prime time, but this is what it looks like so far:
https://www.dropbox.com/s/z6z9xlizhljyc ... g.avi?dl=0

It uses the diving_helm and the core concept of Skugg's firetrap tutorial to make an air meter.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by bongobeat »

waoww! this is awesome! :shock:
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by akroma222 »

Isaac wrote:
bongobeat wrote: pls can you tell me what is wrong in this script?
I got an error after equiping the helmet
diving_timer.timer:start()
diving_timer.timer:stop()
_______________________________________________________________

This should have been in the base game. 8-)
This is fun to use.

*Altered Script ... [Still gives no warning about the air supply running out.]

Code: Select all

   -- scuba gear

        defineObject {
           name = "diving_helmet",
           baseObject = "full_helmet",
           components = {
              {
                 class="Item",
                 weight = 3.0,
                  uiName = "Diving Helmet",
                 gfxIndex = 93,
                 traits = { "helmet" },
                 onEquipItem=function(self,champion,slot)
                    if slot==3 then
                       champion:setCondition("water_breathing")
                diving_timer.timer:start()
                    end
                 end,
                 onUnequipItem=function(self,champion,slot)
                    if slot==3 then
                diving_timer.timer:stop()
                       champion:removeCondition("water_breathing")
                    end
                 end

              },
    {
             class = "EquipmentItem",
             protection = 1,
          },
           }
        }
** I've been tinkering with this a bit more (beyond the script above)... It's not ready for prime time, but this is what it looks like so far:
https://www.dropbox.com/s/z6z9xlizhljyc ... g.avi?dl=0

It uses the diving_helm and the core concept of Skugg's firetrap tutorial to make an air meter.
Isaac - that is amazing! Nice one :D

I have a further question pertaining to the title of this thread - How to tell if the party is underwater???
I am planning on including Zarchtons as a custom race (they breath underwater! hehe)
It is easy enough just to give a Zarchton champ water breathing and leave them with that condition, however....
I was hoping I could come up with a way to setCondition("water_breathing") as soon as they move onto an underwater space and then remove it if they move onto a space not underwater...
@Nutjob, I think this is where you were heading with your earlier post (have you found a way to do this yet??)

My approach so far has been to use the onMove hook for the party and check for the automap tile connected to the space the party is moving to.
Problem is when moving to a space where the definition specifies automaptile = "water"
Eg
SpoilerShow

Code: Select all

defineTile{
	name = "dungeon_floor_water",
	editorIcon = 112,
	color = {45,95,140,255},
	builder = "dungeon",
	floor = {
		"dungeon_floor_dirt_01", 1,
	},
	ceiling = {
		"dungeon_ceiling", 1,
	},
	wall = {
		"dungeon_wall_01", 1,
	},
	pillar = {
		"dungeon_pillar", 1,
	},
	underwater = true,
	ceilingEdgeVariations = true,
	ceilingShaft = "dungeon_ceiling_shaft",
	automapTile = "water",
}
My code does not seem to recognise the "water" automaptile. So far it returns/prints "0" if there is no automap tile, and 3 for "grassy_ground" automaptile.
This is my script so far (init.lua)
SpoilerShow

Code: Select all

defineObject{
       name = "party",
       baseObject = "party",
       components = {
        {
        class = "Party",
        onMove = function(party,dir)
		for i = 1,4 do
			local c = party:getChampion(i)
		
			local cRace = c:getRace()
		
			if cRace == "zarchton" then
				local tile = party.go.map:getAutomapTile(getForward(dir))
				print(tile)
				if tile == 3 then
					if c:hasCondition("water_breathing") == false then
						hudPrint(""..c:getName().." can breath underwater.")
			
						c:setCondition("water_breathing")
			
					end
				else
					if c:hasCondition("water_breathing") == true then
						hudPrint(""..c:getName().." is not underwater.")
			
						c:removeCondition("water_breathing")

					end
				end
			end
		end
        end,
The code works as intended, if you move to and from spaces that have "grassy_ground" automaptile... but I cant seem to detect the "water" :roll:

If you want to test this out yourself, you will need to change Zarchton to Human (or make a zarchton race)

Can anyone point out what I am doing wrong here??
Or if someone else has come up with a more efficient way of finding out if the party is underwater??
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by GoldenShadowGS »

Water is 2, not 3

viewtopic.php?f=22&t=8522
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by akroma222 »

That's great GoldenShadowGS, I appreciate your response...

but the point is my script is not recognising automaptile == 2
It will recognise pretty much most other automaptiles except water (2). WHY!!? :?
I suspect it may have something to do with the elevation??
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: [Solved/Item/Spell] Way to tell if party is underwater?

Post by GoldenShadowGS »

When I was figuring out how to do my script, I opened the dungeon script in notepad++ to discover how it worked. Try a new dungeon with a blank map and draw a smiley face with water tiles. Save it and open the dungeon .lua script in notepad++ see if you can find the section where you made the smiley face and see what number it was assigned.
Post Reply