Changing Item description by looking at it

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
sirK2005
Posts: 14
Joined: Wed Oct 10, 2012 3:26 pm

Changing Item description by looking at it

Post by sirK2005 »

Hi again,

another question I hope someone has already found a solution to.

I am trying to make a watch. Meaning an item that shows how much time has passed since the game started.

I thought of simply using a timer that every minute counts a counter upwards. Then the watch, one of the characters has, could change its own description according to how much the counter has already counted and thus presenting all passed minutes.

Now I realized that items only have a onUseItem-Hook. So my ideas for scripting something based on an onLookAtItem-Hook are gone.

Does anyone have a solution for how to do something like that?

Best
Chris
Best
Chris
sirK2005
Posts: 14
Joined: Wed Oct 10, 2012 3:26 pm

Re: Changing Item description by looking at it

Post by sirK2005 »

Well,

I sadly didn't get the lookAtItem thing going (that would have been nice though), but I got the clock working. It was actually easier than I thought.

I simply created a clock object, that's basically a scroll:

Code: Select all

	cloneObject{
		name = "clock",
		baseObject = "scroll",
		uiName = "Clock",
		model = "assets/models/items/compass.fbx",
		description = "It's a chronometer. Its two hands move magically\nin circles.",
		gfxIndex = 161,
		weight = 0.2,
	}
I created a timer that increments a counter every sec and activates a script, which goes as follows:

Code: Select all

function time()

	local newText = "" .. (counter_3:getValue()-(counter_3:getValue()%60))/60 .. ":" .. counter_3:getValue()%60
	
	local itemCnt = 11
	local champCnt = 1
	
	while champCnt <= 4 do
		itemCnt = 11
		while itemCnt <= 31 do
			if party:getChampion(champCnt):getItem(itemCnt) ~= nil then
				if party:getChampion(champCnt):getItem(itemCnt).name == "clock" then
					party:getChampion(champCnt):getItem(itemCnt):setScrollText(newText)
				end
			end
			itemCnt = itemCnt + 1
		end
		champCnt = champCnt + 1
	end

end
This script goes thorugh every champ and every item slot of the champ and if there's a "clock"-item (the one we defined) than it changes its scrollText.
Oh, and the newText is a bit ugly. I dont know if there is a way to divide through a number and get an integer rather than a float/double. Well in short the line

Code: Select all

local newText = "" .. (counter_3:getValue()-(counter_3:getValue()%60))/60 .. ":" .. counter_3:getValue()%60
turns a number like 121 into 2:1.
So, if you want, you can take this code and adapt it, to make an even better clock ;)

Best
Chris
Best
Chris
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Changing Item description by looking at it

Post by Neikun »

What if a counter does a set item text by referencing a table of possible texts?
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
sirK2005
Posts: 14
Joined: Wed Oct 10, 2012 3:26 pm

Re: Changing Item description by looking at it

Post by sirK2005 »

Hi,

I am not quite sure to which part of the code you are referring.
Are you proposing another way of creating a clock?
Best
Chris
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Changing Item description by looking at it

Post by Neikun »

I'm not entirely sure what it'd look like but basically on every count, the script would do another scroll text.
I think in order to do this, you're going to need a scroll with a different icon/model
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
sirK2005
Posts: 14
Joined: Wed Oct 10, 2012 3:26 pm

Re: Changing Item description by looking at it

Post by sirK2005 »

Yes, that was my idea too. I basically created a scroll (and used the compass model) whichs scrollText is updated every second by a timer.
Best
Chris
Post Reply