Anyway to tell from the object if its in a container?
Re: Anyway to tell from the object if its in a container?
I'm not entirely sure what you are trying to achieve, so this may not be a suitable solution for you, but does it work if you attach a timer component to that particular item GameObject and call self.go:getFullId() from timers onActivate hook? I have not tested this.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: Anyway to tell from the object if its in a container?
I have not been able to make getFullId() work on a monsters inventory yet, but I'm sure it's possible.
Here is the test I ran
Interestingly, "i" is only a number. In this test case, my_boss starts off with a single item. So the Print command would show me a numeric value of "1." Then, when I ran the addItem() command for the battle axe, the Print command would return "1, 2." So it saw the first original item, and then the second item (battle axe) that was added programmatically. That's about where I stopped, as there isn't much I could do yet to find out the ID (or Full ID) of either items via code.
Although, for me, this functionality gives me enough to work with since I can control which Item(s) a monster has at any point. So if the above code returns a certain number I can make certain decisions, without actually knowing the full ID of the item. Hence, since the print command returned "1" and "2" ... I know that the monster has the Battle Axe.
Here is the test I ran
Code: Select all
my_boss.monster:addItem(spawn("battle_axe").item);
for i in my_boss.monster:contents() do
print(i);
end
Although, for me, this functionality gives me enough to work with since I can control which Item(s) a monster has at any point. So if the above code returns a certain number I can make certain decisions, without actually knowing the full ID of the item. Hence, since the print command returned "1" and "2" ... I know that the monster has the Battle Axe.
Re: Anyway to tell from the object if its in a container?
Azel: try
And I tested attaching timer to an item, it doesn't work, the timer is disabled as soon as the item is picked up or placed in container.
Code: Select all
my_boss.monster:addItem(spawn("battle_axe").item);
for i,item in my_boss.monster:contents() do
print(i,item);
end
Code: Select all
defineObject{
name = "my_dagger",
baseObject = "dagger",
components = {
{
class = "Timer",
onActivate = function(self)
print(self.go:getFullId())
end
}
}
}
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: Anyway to tell from the object if its in a container?
The 1st part of my problem was cleanly solved by Petri and that is being able to determine which surface an object is in. getFullId() gives you the ID of the game object of the surface its in.JKos wrote:I'm not entirely sure what you are trying to achieve, so this may not be a suitable solution for you, but does it work if you attach a timer component to that particular item GameObject and call self.go:getFullId() from timers onActivate hook? I have not tested this.
But part 2 of my problem is when an object is in a container or held by a monster or party, how can I tell which entity it is in? For me, as soon as its held (or contained), the object is basically removed from the game, except by referencing it thru container calls. Its a catch-22 because how do I know which container to call? Also, I cannot call getFullId() on the object because there is no object. Petri says this works but I don't see how....
Would you be able to try it out to make sure I am not missing anything?
Re: Anyway to tell from the object if its in a container?
There IS an object. It's just not on a map, so it can't be located with findEntity() or its id.
Since you seem to be unwilling to believe this, here is a demonstration you can do. Pick up an item, then type this into the console and press enter:
It will print the address of a table, which is the item's corresponding GameObject.
Since you seem to be unwilling to believe this, here is a demonstration you can do. Pick up an item, then type this into the console and press enter:
Code: Select all
print(getMouseItem().go)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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Anyway to tell from the object if its in a container?
Yeah, so go:getFullId() works even if the item is in container, but the problem is that there is no way to call it without iterating all containers because you can't have a direct reference to it (as far as I know).
So I think that you really have to use some other way. One possible way is to use modifyObjects-script:
viewtopic.php?f=22&t=8450
This adds that same onInsertItem-hook to all components named as containeritem.
So I think that you really have to use some other way. One possible way is to use modifyObjects-script:
viewtopic.php?f=22&t=8450
Code: Select all
modifyObjects{
filter = {
hasComponents = {'containeritem'}
},
components = {
{
name = 'containeritem',
onInsertItem = function(self,item)
print(item.go.id,'is now in',self.go.id)
end
}
}
}
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: Anyway to tell from the object if its in a container?
Ok. I did not do any of the new framework stuff though like modifyObjects. I get the idea though. I am going to have a finite number of containers in the game, as well as a finite number of monsters who can hold objects and of course one party. So I will have otr setup the appropriate hooks for these. Thanks.JKos wrote:Yeah, so go:getFullId() works even if the item is in container, but the problem is that there is no way to call it without iterating all containers because you can't have a direct reference to it (as far as I know).
So I think that you really have to use some other way. One possible way is to use modifyObjects-script:
viewtopic.php?f=22&t=8450
This adds that same onInsertItem-hook to all components named as containeritem.Code: Select all
modifyObjects{ filter = { hasComponents = {'containeritem'} }, components = { { name = 'containeritem', onInsertItem = function(self,item) print(item.go.id,'is now in',self.go.id) end } } }
Re: Anyway to tell from the object if its in a container?
Good stuff! If I use that, I can ask for the item.go.name to see "battle_axe" as the result. The actual ID of the battle axe, however, is still elusive.JKos wrote:Azel: try
Code: Select all
my_boss.monster:addItem(spawn("battle_axe").item); for i,item in my_boss.monster:contents() do print(i,item); end
Code: Select all
my_boss.monster:addItem(spawn("battle_axe").item);
for i,item in my_boss.monster:contents() do
print(i,item.go:getFullId());
end
my_boss.skull_1
my_boss.45680
No need to spend too much energy on this on my account, though. Since I am not using this in my Mod. Just a fun thing to try reading through this specific thread. Helpful for any future ideas too!