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
ratman
Posts: 158
Joined: Fri Jan 10, 2020 1:13 am

Re: Ask a simple question, get a simple answer

Post by ratman »

I have an item that creates light when in the characters hand(like a torch) and everything works fine except it always lights brightest to the north, and the ground to the south is completely dark so you can barely even see the floor. I tried using light_component:setDirection(vec(3)) but it didn't change anything. I probably have to change the offset or something but there is no
function to do that in the scripting reference.
light definition:

Code: Select all

			onEquipItem = function(self, champion, slot)
--				print("onEquipItem")
				if (slot == ItemSlot.Weapon) then
--					print("on")
					local light_component = party:createComponent("Light", "light")
					light_component:setBrightness(0.2)
					light_component:setColor (vec(64, 40, 18))
					light_component:setRange(6)
					light_component:setDirection(vec(3))
				end
			end,
			onUnequipItem = function(self, champion, slot)
--				print("onUnequipItem")
				if (slot == ItemSlot.Weapon) then
--					print("off")
					party:removeComponent("light")
				end
			end,
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

ratman wrote: Mon Dec 07, 2020 1:00 amI probably have to change the offset or something but there is no
function to do that in the scripting reference.
Yes there is. Component:setOffset() is in both the official scripting reference and the wiki one:
http://www.grimrock.net/modding/scripti ... #Component
https://github.com/JKos/log2doc/wiki/Co ... #component

LightComponent:setDirection() is only meaningful for directional lights, which your light is not (the default light type is point).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

I'm back to my candle item.
minmay wrote: Wed Dec 02, 2020 8:30 pm I'd suggest adding a TimerComponent to the party on the fly instead of spawning a new object, so that you don't have the issue of the timer slowing down if the party leaves the map.
I have tried this but if I don't oversee anything there is no way to give a component a name by a function. So I am not able to adress it here and to set its stats.

Seems I have to get back to my external timer object and live with the fact, that it will run slower when the party is on another level. Or I script something that copies that timer always on the party.level.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

THOM wrote: Mon Dec 07, 2020 11:16 pmI have tried this but if I don't oversee anything there is no way to give a component a name by a function.
You can provide a second argument to createComponent() to name the new component. For example:

Code: Select all

party:createComponent("Timer","fish")
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Really? Good to know.

Too sad that it's not documented anywhere...
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post by 7Soul »

Has anyone recreated the "testament" object that the island master drops when killed in the Trickster's Lair?
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

7Soul wrote: Sun Dec 13, 2020 9:37 pm Has anyone recreated the "testament" object that the island master drops when killed in the Trickster's Lair?
There's nothing special about this object, it's defined in nex_assets.lua in the asset pack:

Code: Select all

defineObject{
	name = "testament",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/waxseal_note.fbx",
		},
		{
			class = "Item",
			uiName = "Testament",
			gfxIndex = 235,
			weight = 0.1,
			traits = { "readable" },
		},
		{
			class = "UsableItem",
			onUseItem = function(self)
				GameMode.showImage("assets/textures/gui/scroll_images/testament.tga")
				return false
			end,
		},
	},
}
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
7Soul
Posts: 199
Joined: Sun Oct 19, 2014 1:56 am
Location: Brazil

Re: Ask a simple question, get a simple answer

Post by 7Soul »

I actually never noticed this file o,o
Join the LoG discord server: https://discord.gg/ArgAgNN :D

My Mods
User avatar
THOM
Posts: 1266
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

Well, well, it's me again - still working on that candle item.

What I have so far is this in the onEquipItem function:

Code: Select all

					local tim = self.go.id
					if not party.tim then 
						party:createComponent("Timer", "tim") 		
						party.tim:setTimerInterval(5) 
						party.tim:disable()
						party.tim:addConnector("onActivate", "find_item" , "destr", self.go.id) 
					end
					party.tim:start()
This works so far, means: the component gets created, gets programmed and triggers this function in an external script entity:

Code: Select all

			function destr(item)
				delayedCall(self.go.id,0.01,"destr2", item)
			end
			function destr2(item)
				find_item.script.findAnywhere(item,party.level,true)
				hudPrint("The candle has burned to the end.")
				party:removeComponent(item)
			end
What doesn't work that I get the name of the item (which is the same as the created component's name) handled over to the external function. I know that a fourth value is not reported for addConnector("onActivate", "find_item" , "destr", self.go.id) - but I hoped that it works. Doesn't seem so. So I do not know how to tell the other function (minmay's findAnywhere) which item is meant to be destroyed.

Anyone an idea how to do that?
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Use the candle's id (or another string containing it, if you prefer) as the name of your TimerComponent. You can then retrieve it with Component:getName(). Like this:

Code: Select all

local timerName = self.go.id
if not party:getComponent(timerName) then
	local timer = party:createComponent("Timer",timerName)
	timer:setTimerInterval(5)
	timer:addConnector("onActivate", "find_item", "destr")
end
party:getComponent(timerName):start()

Code: Select all

function destr(timer)
	local itemId = timer:getName()
	find_item.script.findAnywhere(itemId,party.level,true)
	hudPrint("The candle has burned to the end.")
	timer.go:removeComponent(timer:getName())
end
Remember to pause the timer in your onUnequipItem hook as well.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply