[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
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 »

Thanks for the suggestion! I went ahead and did as you said - good investigative tool (should have been doing this ages ago) :roll:

Turns out the problem was
local tile = party.go.map:getAutomapTile(getForward(dir))

when it should have been this...
local tile = party.go.map:getAutomapTile(party.go.x,party.go.y)

Script now works! :D
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 == "human" then
				local tile = party.go.map:getAutomapTile(party.go.x,party.go.y)
				print(tile)
				if tile == 2 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
	}
    },
}
And instead of hooking it up with onMove, Ive decided to just connect it to the party timer
SpoilerShow

Code: Select all

defineObject{
       name = "party",
       baseObject = "party",
       components = {
		{
		class = "Counter",
		name = "partycounter",
		},	
          	{
             	class = "Timer",
		name = "partytimer",
		timerInterval = 1.0,
		triggerOnStart = true,
		onActivate = function(self)
			self.go.partycounter:increment()
			local v = self.go.partycounter:getValue()
			if initCounter.counter:getValue() == 1 then
				initScript.script.initialize()
				initCounter.counter:decrement()
			end
			return hudPrint("Time = "..v.."")
		end
          	},
	}
    }
create initScript (in dungeon) and initCounter set value to 1
SpoilerShow

Code: Select all

function initialize()

	for i = 1,4 do
		local c = party.party:getChampion(i)
		local cRace = c:getRace()
		if cRace == "zarchton" then
			party.partytimer:addConnector("onActivate", "initScript", "waterBreathingCheck")
		end
	end
end
			
----------------------------------------------------------------------------------------------waterBreathingCheck()		
	function waterBreathingCheck()
		for i = 1,4 do
			local c = party.party:getChampion(i)
			local cRace = c:getRace()
			if cRace == "zarchton" then
				local tile = party.map:getAutomapTile(party.x,party.y)
				print(tile)
		
				if tile == 2 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
partytimer triggers initScript, checks if you have Zarchtons in your party,
if so it adds a connector from partytimer to initScript (f waterbreathing) which checks for the automaptile
and from there adds or removes water breathing condition
This way is better than onMove i think

Thanks for your help GoldenShadowGS!
Very happy to get this thing working
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 »

akroma222 wrote:...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??
Try this (your script with some alteration):

Place this in a script object named: waterCheck

Code: Select all

function check(null, void, dir)
        local tile = party.map:getAutomapTile(party.x, party.y)   
      		if dir ~= nil then
             local dX, dY = getForward(dir)
             tile = party.map:getAutomapTile(party.x + dX, party.y + dY)  
			end 
	      	for i = 1,4 do
		        local c = party.party:getChampion(i)
		        local cRace = c:getRace()
		
		        if cRace == "minotaur" then  --"zarchton"
		
		          if tile == 2 then
		             if c:hasCondition("water_breathing") == false then
		             hudPrint("")  hudPrint("") hudPrint("") hudPrint("")
		               hudPrint(""..c:getName().." can breath underwater.")
		               c:setCondition("water_breathing")
		             end
		          else
		             if c:hasCondition("water_breathing") == true then
		             hudPrint("")  hudPrint("") hudPrint("") hudPrint("")
		              hudPrint(""..c:getName().." is not underwater.")
		               c:removeCondition("water_breathing")
		             end
		          end
		        end
		        
    		end
end
Use this as the Party definition:

Code: Select all

       defineObject{
           name = "party",
           baseObject = "party",
           components = {
						{
						class = "Party",
						onMove = function(party, dir)
								local dirTemp = dir
								waterCheck.script:check(party, dirTemp)
							end,
						onTurn = function(party, dir)
								waterCheck.script:check(party, nil)
							end,

					}
				}
			}

https://www.dropbox.com/s/nfmj6nwcox9fs ... k.avi?dl=0
Last edited by Isaac on Tue Dec 16, 2014 6:57 am, edited 3 times in total.
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 »

Haha Isaac! We must have posted at the same time...
Mine works great, but will check out yours now too :D
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 »

akroma222 wrote:Haha Isaac! We must have posted at the same time...
Mine works great, but will check out yours now too :D
Just updated it.
Last edited by Isaac on Tue Dec 16, 2014 7:00 am, edited 2 times in total.
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 »

Nice! I like the way you've done that

And there we have it - 2 ways to tell if the party is underwater
1 using onMove, 1 using a partytimer

Thank you guys! :D
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post by THOM »

Hi - I am looking for a way to make this diving condition invinite. But I didn't found a way.

I tried setCondition("water_breathing", 70000) but that doesn't seem to work. Any ideas someone?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
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 »

Hey THOM,
pretty sure you just leave out the 'value' .... so,

setCondition("water_breathing")
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post by THOM »

akroma222, sadly that's not the solution. If you define it in your way the party members loose the water-breathing-ability after an (unknown?) amount of time... :(
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

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

Post by Eburt »

THOM wrote:Hi - I am looking for a way to make this diving condition invinite. But I didn't found a way.

I tried setCondition("water_breathing", 70000) but that doesn't seem to work. Any ideas someone?
try setConditionValue("water_breathing", 70000)

setCondition only takes one argument, while setConditionValue lets you specify a duration. You could also use math.huge instead of a number for the duration.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post by THOM »

You are my hero! 8-)
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Post Reply