Page 1 of 6

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

Posted: Thu Nov 06, 2014 11:30 pm
by sps999
Is there any way to tell if the party is underwater? I want to try and make a potion of water breathing or some sort of equipment that would work by constantly restoring energy but only if the party is underwater.

LoG2 has the Zarchton Harpoon that still works underwater, so I think there might be some trait on it that lets it be used underwater. However, it is also important to be able to tell if the party is not above water as then the party would be restoring energy when they shouldn't be which I am not sure if there is something that does that right now.

Any help will be appreciated.

Edit: With the help of a few people, I've put together the following spell and potion.

The spell will provide the entire party with the ability to breath underwater for the duration. You may want to adjust this duration depending on your needs. The potion will provide water breathing to whoever drinks it.

The following code will go into you spells.lua and provides the Water Breathing spell.
The requirements are currently commented out for testing purposes, but once you want the requirements just remove the "--" before requirement = {...}, and you can adjust the requirements by changing the numbers.

Cast it with:
Image

Code: Select all

defineSpell{
   name = "water_breathing",
   uiName = "Water Breathing",
   skill = "water_magic",
   --requirements = {"water_magic", 4, "air_magic", 3,},
   gesture = 96325, -- Bottom Right > Top Right > Top Middle > Middle
   manaCost = 30,
   icon = 28, --7 14 28
   spellIcon = 13, --13 19
   description = "Gives the body the ability to breathe water.",
   onCast = function(champion, x, y, direction, elevation, skillLevel)
      playSound("generic_spell")
      for i = 1, 4, 1 do
         if party.party:getChampion(i):isAlive() then
            party.party:getChampion(i):setCondition("water_breathing", skillLevel*10)
         end
      end 
    end,
}
The next code include the Potion of Waterbreathing and a recipe to craft it. The recipe requires 2 Etherweed and 1 Falconskyre, as well as level 3 alchemy.
The potion has a placeholder image of the Water Flask currently.

Code: Select all

defineRecipe {
   name = "potion_water_breathing_recipe",
   level = 3,
   ingredients = 224, -- Leechweed, Leechweed, Falconskrye
   potion = "potion_water_breathing",
}

defineObject{
   name = "potion_water_breathing",
   baseObject = "base_item",
   components = {
      {
          class = "Model",
          model = "assets/models/items/flask.fbx",
      },
      {
         class = "Item",
         uiName = "Potion of Water Breathing",
         gfxIndex = 144,
         description = "A potion that gives you the ability to breathe underwater.",
         weight = 0.3,
         stackable = true,
      },
      {
         class = "UsableItem",
         sound = "consume_potion",
         onUseItem = function(self,champion)
            champion:setCondition("water_breathing", 30)
         end,
      }
   },
}

Re: Way to tell if party is underwater?

Posted: Fri Nov 07, 2014 12:26 am
by Prozail
there is a trait called "aquatic" that seems to have something to do with it. I'll look into it some more.
Edit: It seems to only be available to the internal workings of the engine.

Re: Way to tell if party is underwater?

Posted: Fri Nov 07, 2014 12:38 am
by NutJob
With a timer and and the party properties concatenated (party.level .. party.x .. party.y) on a polling system (the timer) you could check if the party is within defined vertices. The defined points would just be where you know the water is accessible.

Let me try to get my system out of my library so I can better describe what I mean. I'll be back!

Re: Way to tell if party is underwater?

Posted: Thu Nov 13, 2014 10:05 am
by akroma222
Very interested in how this works...
I am hoping to keep Zarchton as a custom race (who can breath underwater)

I have tried giving the "aquatic" trait to another weapon... and that works - can attack underwater!

I have also tried giving the aquatic trait to the zarchton race
SpoilerShow

Code: Select all

defineTrait{
       	name = "zarchton",
       	uiName = "Zarchton",
       	icon = 27,
       	--iconAtlas = "mod_assets/textures/skills.tga",
	gameEffect = [[- Resist Cold +10][- Can breath underwater][- Discovers special secrets underwater]],
       	description = "As a Zarchton you are able to traverse ponds, rivers and even the ocean as you would do so on land.",
       	traits = { “aquatic” },
	onRecomputeStats = function(champion, level)
		if level > 0 then
			--champion:addStatModifier("resistCold", 10)	--resist Cold+10
			champion:addStatModifier("strength", -2)	--statMod
			champion:addStatModifier("dexterity", 2)
			champion:addStatModifier("willpower", -1)
       		end
	end,   
}
but the zarchton champion will still begin to drown... (have I listed the trait correctly?)
Have any of you discovered anything new about giving the trait to a race?? :)

Re: Way to tell if party is underwater?

Posted: Thu Nov 13, 2014 9:13 pm
by Drakkan
this is quite interesting I will definitely for my dungeon need some "water-breathing" armour item. Please dont give up with this :)

Re: Way to tell if party is underwater?

Posted: Fri Nov 14, 2014 12:18 am
by Prozail
heres how to make a diving helmet. Just make sure you don't have two items, equippable in different slots give water breathing, cuz you'll run into trouble if someone equips both, then removes one.

Code: Select all

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")
				end
			end,
			onUnequipItem=function(self,champion,slot)
				if slot==3 then
					champion:removeCondition("water_breathing")
				end
			end
			
		},
	}
}

Re: Way to tell if party is underwater?

Posted: Fri Nov 14, 2014 1:45 am
by sps999
I've conjured up a simple spell to breath underwater based on Prozail's helmet:

Note: requirements commented out for testing.

Edit: Refined to code to include icons and expiration timer.

Code: Select all

defineSpell{
	name = "water_breathing",
	uiName = "Water Breathing",
	skill = "water_magic",
	--requirements = {"water_magic", 4, "air_magic", 3,},
	gesture = 96325, -- Bottom Right > Top Right > Top Middle > Middle
	manaCost = 30,
	icon = 28, --7 14 28
	spellIcon = 13, --13 19
	description = "Gives the body the ability to breathe water.",
	onCast = function(champion, x, y, direction, elevation, skillLevel)
		playSound("generic_spell")
		for i = 1, 4, 1 do
			if party.party:getChampion(i):isAlive() then
				party.party:getChampion(i):setCondition("water_breathing", skillLevel*10)
			end
		end 
    end,
}
It might not be hard to notice that spell this does not expire. I have no idea how I would make it expire based on a delay. delayedCall() seems like the go to method for lots of people but I would like to keep all the coding in the defineSpell{} and I do not know how to do sort of a delayedCall() inside the onCast hook.

Any ideas? Surely this has been done before and I am just some sort of rookie.

Edit: I had a vague idea of how this might be done with getting the game time and comparing it to the game time at the moment of casting the spell, but I don't know how I would call this code to check without a timer.

Re: Way to tell if party is underwater?

Posted: Fri Nov 14, 2014 1:50 am
by Prozail
you can use setConditionValue("water_breathing",5) instead of just setCondition to give it for 5 seconds.

Re: Way to tell if party is underwater?

Posted: Fri Nov 14, 2014 1:59 am
by sps999
Did a little more testing, and I guess the spell does have a default expiration time and I just didn't realize it. Either way, thanks Prozail for giving a little bit more customization for how long the spell should work.

Edit: Clarification- The setCondition() only has the built in expiration because it is linked with a spell.

Re: Way to tell if party is underwater?

Posted: Fri Nov 14, 2014 2:29 am
by GoldenShadowGS
I have an underwater section of my dungeon and I want the water breathing to be from a new alchemy recipe.
1. How do you define a new potion of water breathing?
2. how do you define the recipe to craft it?