Ask a simple question, get a simple answer

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: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

The object's offset vector could be used for this, or even the 2D subtileOffset.

Code: Select all

setSubtileOffset(x,y)
This moves an object along a 2D x & y grid in a cell, but it's not a function of the projectile component. You would have to obtain the projectile object ID.

*This is easier if using a script instead of a spawner object.

Example: place in script_entity, and connect a timer; timer.facing is the direction of projectile.

Code: Select all

function shoot(self) 
	
	local fireball = self.go:spawn("fireball_small")
	fireball.projectile:setIgnoreEntity(party)
	fireball:setWorldPositionY(1.5)
	fireball:setSubtileOffset(.8,-.5)

end
Image
kelly1111 wrote: Wed Mar 10, 2021 12:50 pmI need a particle that travels close to the wall when fired from a spawner.
How exactly is this to be used? If it's a visual effect, then a custom animation (via Blender) would give more control.
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post by kelly1111 »

Thanks Isaac. I have made a wall object with a long indent in it. I want the projectile / lightsource to travel along that path creating an alternative moving light source effect. But I am now wondering if this will work on a wall object because of the projectile collider component....

I got it working the way I want it
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

kelly1111 wrote: Wed Mar 10, 2021 6:59 pm I got it working the way I want it
8-)

Components can be removed if they are a problem.

The object's position can be determined (or just influenced) with scripting.
Image

But for what you might be doing, a custom animated wall asset could be the best.

Check out the Dark Seal and the in the ORRR3 mod.

Image
User avatar
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

How can you create a nightsight potion that casts the light spell while consuming the item (in hand and inventory)?

My version is crap as it requires the necessary skill of the spell and teaches the spell which is added to the trait window. Other versions with "primaryAction" let me use it indefinitely (unless I used charges) or only turned into an empty flask when used from within the inventory. Usually I used "setCondition" for these purposes, but can a light spell be a condition?!

SpoilerShow

Code: Select all

defineObject{
	name = "flask_light",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/flask.fbx",
		},
		{
			class = "Item",
			uiName = "Nightsight Potion",
			gfxIndex = 144,
			weight = 0.3,
			traits = { "potion" },
			ConvertToItemOnImpact = "dispel_blast",
		},
		{
			class = "UsableItem",
			sound = "consume_potion",
--			emptyItem = "flask",
			onUseItem = function(self, champion)
				if champion:isAlive() then
				champion:castSpell(25)
				end
			end,
		},

	},
}
User avatar
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: Ask a simple question, get a simple answer

Post by ratman »

You could define a new spell that has no requirements and is hidden.

Code: Select all

defineSpell{
	name = "light_potion_spell",
	uiName = "Light",
	gesture = 12321,
	manaCost = 0,
	onCast = "light",
	skill = "concentration",
	--requirements = { "concentration", 2 },
	icon = 58,
	spellIcon = 18,
	description = "Conjures a dancing ball of light that illuminates your path.",
	hidden = true,
}
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

The custom spell (with impossible gesture) would certainly do it, but the nature of the effect is well suited to a being a character condition. As a condition, it can be easily applied to any champion, and effectively handles itself after that; it can also be detected (per champion). Since this is a potion, several PCs might be using them at the same time, whether deliberately or accidental. So the effect should take duplicates into account.

A condition automatically applies an effect icon to the champion's portrait for its duration, and has built in functions to place start, middle, and ending code for both the principle effect, and any cosmetic polishing to it.

Code: Select all

--Place this in one of the starting scripts; eg. spells.lua or other
defineCondition{
   name = "nightvision",
   uiName = "Nightvision",
   description = "Temporarily enhances the ability to see in the dark.",
   icon = 7,										--[icon & iconAtlas can reference a custom image for the portrait-overlay]--
   iconAtlas = "assets/textures/gui/conditions.tga",	--
   beneficial = true,
   harmful = false,
   tickInterval = .05,
   onStart = function(self, champion)
	    if not party.nightsight then party:createComponent("Light", "nightsight") 
  	      party.nightsight:setOffset(vec(0,1.3,-1)) ---------------[Position of light source]--
	   	  party.nightsight:setType("spot")
	   	  party.nightsight:setSpotAngle(117)
	   	  party.nightsight:setSpotSharpness(0)
	   	  party.nightsight:setRange(9)
	   	 end
	   	self:setDuration(60) -----------------------------------[Default duration of nighvision effect]--
   		playSound("spell_out_of_energy")     
   end,
   onStop = function(self, champion)
   		--OPTIONAL message
   			hudPrint(champion:getName():capitalize().."\'s nightvision has expired")
   		--

   		local count = 0
   			for x = 1, 4 do
   				if party.party:getChampion(x):hasCondition("nightvision") then
   					count = count + 1 
   				end
   			end	
   	   		if count < 2 then party:removeComponent("nightsight") end
   	  playSound("spell_expires")
   end,
   onTick = function(self, champion) 
   		local count = 0
   			for x = 1, 4 do
   				if party.party:getChampion(x):hasCondition("nightvision") then
   					count = count + 1 
   				end
   			end	
   	   		if count < 2 then 
		   		if Config.getRenderingQuality()>1 then
			   		if party.nightsight then 
			   			party.nightsight:setColor(vec(5,20,7)) --------------------------------[green tint]--
			   			local jitter = math.abs(math.sin(self:getDuration()*.5)*2)  ----[variable attenuation of the light]--
			   			party.nightsight:setBrightness(jitter)
			   		end
			   	end
			end   			
   end,
}

defineObject{
	name = "potion_nightvision",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/flask.fbx",
		},
		{
			class = "Item",
			uiName = "Nightvision Potion",
			gfxIndex = 146,
			weight = 0.3,
			stackable = true,
			traits = { "potion" },
		},
		{
			class = "UsableItem",
			sound = "consume_potion",
			onUseItem = function(self, champion)
				champion:setCondition('nightvision')
			end,
		},
	},
}
User avatar
Lorial
Posts: 91
Joined: Sat Dec 29, 2018 12:27 pm

Re: Ask a simple question, get a simple answer

Post by Lorial »

Thanks a bunch for that, guys.

Just had the same idea with no requirements today, the gesture is a nice addition indeed.
I have used numerous custom conditions for 1, 2 or all 4 chars, but I never managed to connect a consumable item with casting a spell. Creating complex conditions that replicate a spell is way out of my league. Time to play around with these a bit and see what sticks.
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Ask a simple question, get a simple answer

Post by Eleven Warrior »

Isaac wrote: Sat Mar 13, 2021 6:23 am The custom spell (with impossible gesture) would certainly do it, but the nature of the effect is well suited to a being a character condition. As a condition, it can be easily applied to any champion, and effectively handles itself after that; it can also be detected (per champion). Since this is a potion, several PCs might be using them at the same time, whether deliberately or accidental. So the effect should take duplicates into account.

A condition automatically applies an effect icon to the champion's portrait for its duration, and has built in functions to place start, middle, and ending code for both the principle effect, and any cosmetic polishing to it.

Code: Select all

--Place this in one of the starting scripts; eg. spells.lua or other
defineCondition{
   name = "nightvision",
   uiName = "Nightvision",
   description = "Temporarily enhances the ability to see in the dark.",
   icon = 7,										--[icon & iconAtlas can reference a custom image for the portrait-overlay]--
   iconAtlas = "assets/textures/gui/conditions.tga",	--
   beneficial = true,
   harmful = false,
   tickInterval = .05,
   onStart = function(self, champion)
	    if not party.nightsight then party:createComponent("Light", "nightsight") 
  	      party.nightsight:setOffset(vec(0,1.3,-1)) ---------------[Position of light source]--
	   	  party.nightsight:setType("spot")
	   	  party.nightsight:setSpotAngle(117)
	   	  party.nightsight:setSpotSharpness(0)
	   	  party.nightsight:setRange(9)
	   	 end
	   	self:setDuration(60) -----------------------------------[Default duration of nighvision effect]--
   		playSound("spell_out_of_energy")     
   end,
   onStop = function(self, champion)
   		--OPTIONAL message
   			hudPrint(champion:getName():capitalize().."\'s nightvision has expired")
   		--

   		local count = 0
   			for x = 1, 4 do
   				if party.party:getChampion(x):hasCondition("nightvision") then
   					count = count + 1 
   				end
   			end	
   	   		if count < 2 then party:removeComponent("nightsight") end
   	  playSound("spell_expires")
   end,
   onTick = function(self, champion) 
   		local count = 0
   			for x = 1, 4 do
   				if party.party:getChampion(x):hasCondition("nightvision") then
   					count = count + 1 
   				end
   			end	
   	   		if count < 2 then 
		   		if Config.getRenderingQuality()>1 then
			   		if party.nightsight then 
			   			party.nightsight:setColor(vec(5,20,7)) --------------------------------[green tint]--
			   			local jitter = math.abs(math.sin(self:getDuration()*.5)*2)  ----[variable attenuation of the light]--
			   			party.nightsight:setBrightness(jitter)
			   		end
			   	end
			end   			
   end,
}

defineObject{
	name = "potion_nightvision",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/flask.fbx",
		},
		{
			class = "Item",
			uiName = "Nightvision Potion",
			gfxIndex = 146,
			weight = 0.3,
			stackable = true,
			traits = { "potion" },
		},
		{
			class = "UsableItem",
			sound = "consume_potion",
			onUseItem = function(self, champion)
				champion:setCondition('nightvision')
			end,
		},
	},
}
Could you do the same for a fireball potion to Issac? Player drinks potion and launches a fireball.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

Eleven Warrior wrote: Sun Mar 14, 2021 11:10 pm Could you do the same for a fireball potion to Issac? Player drinks potion and launches a fireball.
Potion of Fire Breathing?
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Ask a simple question, get a simple answer

Post by Eleven Warrior »

yeah
Post Reply