Page 1 of 1
Changing Item description by looking at it
Posted: Thu Oct 11, 2012 8:56 pm
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
Re: Changing Item description by looking at it
Posted: Fri Oct 12, 2012 1:07 am
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
Re: Changing Item description by looking at it
Posted: Fri Oct 12, 2012 1:14 am
by Neikun
What if a counter does a set item text by referencing a table of possible texts?
Re: Changing Item description by looking at it
Posted: Fri Oct 12, 2012 11:11 am
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?
Re: Changing Item description by looking at it
Posted: Fri Oct 12, 2012 11:45 am
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
Re: Changing Item description by looking at it
Posted: Fri Oct 12, 2012 1:36 pm
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.