Ask a simple question, get a simple answer
Re: Ask a simple question, get a simple answer
Hello!
Yes it is possible.
Moreover, there are 2 ways for this: standard math.random() and https://www.grimrock.net/modding/script ... nneTwister.
You can also change the properties of objects in the onInit functions of components. For objects with minimalSaveState this will have an even more unpredictable effect)))
Well, after all, food is usable and has an onUse hook in which you can register a random effect. But this will not be displayed in the interface on the nutritional bar.
Yes it is possible.
Moreover, there are 2 ways for this: standard math.random() and https://www.grimrock.net/modding/script ... nneTwister.
You can also change the properties of objects in the onInit functions of components. For objects with minimalSaveState this will have an even more unpredictable effect)))
Well, after all, food is usable and has an onUse hook in which you can register a random effect. But this will not be displayed in the interface on the nutritional bar.
Re: Ask a simple question, get a simple answer
Yes, thanks, onInit does allow you to create random objects, but for some reason if they are placed in containers on the map it does not work. However, if you put them in a script, then everything is ок - why? Are there any conditions under which onInit does not execute?
Re: Ask a simple question, get a simple answer
I forgot how to offset objects in the world, and I'm trying to put some torches on pillars.
How do????
How do????
Re: Ask a simple question, get a simple answer
Use GameObject:setWorldPosition(). Make sure the object you're offsetting doesn't have minimalSaveState, though.
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: Ask a simple question, get a simple answer
Hmm... I don't know. Apparently the hook only works when an object is created on the map. When an object is placed in a container, it is removed from the map. This means that the hook is not called during creation since the object is not on the map.Hiker wrote: ↑Fri Jul 19, 2024 7:23 pm Yes, thanks, onInit does allow you to create random objects, but for some reason if they are placed in containers on the map it does not work. However, if you put them in a script, then everything is ок - why? Are there any conditions under which onInit does not execute?
Re: Ask a simple question, get a simple answer
GameObject:getWorldPosition()
Returns 3 values, X, Y and Z for the world position of the object. World position coordinates have Y-axis as up/down, X-axis is east/west, Z-axis is north/south. The cube that represent one game square is (3.0 x 3.0 x 3.0) world position units in size.
GameObject:setWorldPosition(vec) - It is written that this method accepts a vector. However, it accepts 3 numbers separated by commas, but not vec(x, y, z). I used it like this: g1_bookshelf_01_18:setWorldPosition(61.5,2.4,48)
Re: Ask a simple question, get a simple answer
The point is that we first create something, and then we put it somewhere. If we ourselves fill the container in the same way, the hook will be called.
Not called:
spawn("sack",15,16,0,0,"sack_2")
spawn("bread",15,16,0,0,"bread_1")
sack_2.containeritem:addItem(bread_1.item)
Called:
sack.containeritem:addItem(spawn("bread").item)
In principle, this may even be useful, but now I have to think (apparently use dynamic hooks) how to disable this call in the script when necessary.
Re: Ask a simple question, get a simple answer
For what? Define a new random container. using baseObject you can inherit from the original container. In the definition of the container component, add an onInit hook. Then you can use a regular container and a random container where necessary.
UPD newermind. I got the context wrong. Let me clarify, at the top is the code that generates the dungeon editor?
Below is what you wrote by hand?
In that case, yes, you can use addConector and removeConnector. But in my opinion, this is not entirely flexible.
Code: Select all
defineObject{
name = "random_sack",
baseObject = "sack",
components = {
{
class = "ContainerItem",
containerType = "sack",
openSound = "container_sack_open",
closeSound = "container_sack_close",
onInit = function(self)
--Your random script here
if self:getItemCount() > 0 then
self.go.model:setModel("assets/models/items/sack_full.fbx")
self.go.item:setGfxIndex(81)
self.go.item:updateBoundingBox()
end
end,
onInsertItem = function(self, item)
-- convert to full sack
if self.go.item:getGfxIndex() == 82 then
self.go.model:setModel("assets/models/items/sack_full.fbx")
self.go.item:setGfxIndex(81)
self.go.item:updateBoundingBox()
end
end,
onRemoveItem = function(self, item)
-- convert to empty sack when last item is removed
if self:getItemCount() == 0 and self.go.item:getGfxIndex() == 81 then
self.go.model:setModel("assets/models/items/sack_empty.fbx")
self.go.item:setGfxIndex(82)
self.go.item:updateBoundingBox()
end
end,
},
},
}
Re: Ask a simple question, get a simple answer
The fact of the matter is that any container created using a script will be filled with items with random properties as specified in their onInit, but if you just put it in dungeon.lua as stated above, then it will not be random.
Okay, I can use this for my own purposes, but then how can I script an item that doesn’t have random properties? I think I can just disable onInit for this before spawning.
Okay, I can use this for my own purposes, but then how can I script an item that doesn’t have random properties? I think I can just disable onInit for this before spawning.