Spawn an object in a random rotation.
Spawn an object in a random rotation.
How would you go about spawning an object in a random rotation via script? For example I want to spawn random details on my floor facing in a random direction ( I have random details spawning on my tile set already, just need to figure out how to randomly face them). I know I could just turn on random tile facing but the base floor doesn't look good that way. I just want to rotate the details that spawn on top.
Re: Spawn an object in a random rotation.
spawn(name,level,x,y,math.random(0,3),elevation,id)
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: Spawn an object in a random rotation.
I have this set up atm.. I thought I did it correctly but it doesn't work in this state. Not getting any errors, its just not working. I missed something just can't find itminmay wrote:spawn(name,level,x,y,math.random(0,3),elevation,id)
Code: Select all
local autoDecoFloorDetail = function(self)
local g = self.go
local details = {
rock_tunnel_ground_detail01=true,
rock_tunnel_ground_detail02=true,
rock_tunnel_ground_detail03=true,
rock_tunnel_ground_detail04=true,
rock_tunnel_ground_detail05=true,
}
if g.map:getElevation(g.x,g.y) == g.elevation then
local choice = math.random()
if choice <= 0.5 then
g:spawn("rock_tunnel_ground_detail05",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.625 then
g:spawn("rock_tunnel_ground_detail02",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.75 then
g:spawn("rock_tunnel_ground_detail03",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.875 then
g:spawn("rock_tunnel_ground_detail04",g.level,g.x,g.y,math.random(0,3),g.elevation)
else
g:spawn("rock_tunnel_ground_detail01",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
end
endRe: Spawn an object in a random rotation.
http://www.grimrock.net/modding/scripting-reference/
GameObject:spawn() only takes a single parameter, the name of the object to be spawned. It spawns the object with the same level, x, y, facing, and elevation as the GameObject you called it from - that's the point of GameObject:spawn().
If you want to spawn an object with a different facing, use the global spawn() function instead, like I said.
Also, you obviously copied and pasted that function from somewhere else without really looking at what it does...the following will give you the functionality you wanted:There is no point in declaring a table if you never use it, nor in checking the elevation, since you're attaching this to a floor object already.
GameObject:spawn() only takes a single parameter, the name of the object to be spawned. It spawns the object with the same level, x, y, facing, and elevation as the GameObject you called it from - that's the point of GameObject:spawn().
If you want to spawn an object with a different facing, use the global spawn() function instead, like I said.
Also, you obviously copied and pasted that function from somewhere else without really looking at what it does...the following will give you the functionality you wanted:
Code: Select all
local autoDecoFloorDetail = function(self)
local g = self.go
local choice = math.random()
if choice <= 0.5 then
spawn("rock_tunnel_ground_detail05",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.625 then
spawn("rock_tunnel_ground_detail02",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.75 then
spawn("rock_tunnel_ground_detail03",g.level,g.x,g.y,math.random(0,3),g.elevation)
elseif choice <= 0.875 then
spawn("rock_tunnel_ground_detail04",g.level,g.x,g.y,math.random(0,3),g.elevation)
else
spawn("rock_tunnel_ground_detail01",g.level,g.x,g.y,math.random(0,3),g.elevation)
end
endGrimrock 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: Spawn an object in a random rotation.
Thank you,
Yes I did copy that code its yours lol..I know what it does I just didn't catch the game object spawn vs the global spawn.
I have that page open at all times and I still didn't see the "Global" .. ugg
Yes I did copy that code its yours lol..I know what it does I just didn't catch the game object spawn vs the global spawn.
I have that page open at all times and I still didn't see the "Global" .. ugg