Page 4 of 6

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

Posted: Tue Dec 16, 2014 5:11 am
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

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

Posted: Tue Dec 16, 2014 5:12 am
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

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

Posted: Tue Dec 16, 2014 5:17 am
by akroma222
Haha Isaac! We must have posted at the same time...
Mine works great, but will check out yours now too :D

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

Posted: Tue Dec 16, 2014 5:21 am
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.

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

Posted: Tue Dec 16, 2014 5:41 am
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

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

Posted: Tue Feb 17, 2015 12:22 am
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?

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

Posted: Tue Feb 17, 2015 9:06 am
by akroma222
Hey THOM,
pretty sure you just leave out the 'value' .... so,

setCondition("water_breathing")

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

Posted: Tue Feb 17, 2015 9:51 am
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... :(

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

Posted: Tue Feb 17, 2015 6:25 pm
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.

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

Posted: Wed Feb 18, 2015 12:15 am
by THOM
You are my hero! 8-)