How can I spawn a monster randomly?
Posted: Thu Sep 20, 2012 9:39 am
I need to spawn the same monster type randomly, can some one help me with the script/solution?
Official Legend of Grimrock Forums
http://mail.grimrock.net/forum/
Time and location if possiblecromcrom wrote:What kind of random, time or location ?
Code: Select all
function spawnInRange(objectToSpawn,Xrange,Yrange)
local coordinateX = self.x
local coordinateY = self.y
local basecoordinateX = coordinateX-Xrange
local basecoordinateY = coordinateY-Yrange
local maxSpawnX = Xrange*2
local maxSpawnY = Yrange*2
local randomCoordinateX = math.random(0,maxSpawnX)
local randomCoordinateY = math.random(0,maxSpawnY)
local finalCoordinateX = basecoordinateX + randomCoordinateX
local finalCoordinateY = basecoordinateY + randomCoordinateY
spawn(objectToSpawn,1,finalCoordinateX,finalCoordinateY,0)
print(finalCoordinateX,finalCoordinateY)
end
function check()
spawnInRange("snail",3,3)
endThis seems hard to me... seems simple, but i cannot figure out it. Can i send you a PM with the specifics? And maybe mailing you the dungeon with the description of the level?cromcrom wrote:try this for location:
Tie it to a timer, choose the check() functionCode: Select all
function spawnInRange(objectToSpawn,Xrange,Yrange) local coordinateX = self.x local coordinateY = self.y local basecoordinateX = coordinateX-Xrange local basecoordinateY = coordinateY-Yrange local maxSpawnX = Xrange*2 local maxSpawnY = Yrange*2 local randomCoordinateX = math.random(0,maxSpawnX) local randomCoordinateY = math.random(0,maxSpawnY) local finalCoordinateX = basecoordinateX + randomCoordinateX local finalCoordinateY = basecoordinateY + randomCoordinateY spawn(objectToSpawn,1,finalCoordinateX,finalCoordinateY,0) print(finalCoordinateX,finalCoordinateY) end function check() spawnInRange("snail",3,3) end
What it does is that it spawns a monster (objectToSpawn) on a random tile that is within a + or - range (Xrange, Yrange) of the tile this script_entity is located at. Beware of the spawn level.
I am sure it is easy to improve it.
As for time, I have not checked this issue yet, but out of my mind, you could set a percentage chance that this script fires every "timer second", thus making the trick (example, timer seconds = 10, if percentage = 50%, the monster might or might not spawn every 10 seconds. You could reduce the percentage for less spawning chance. Well, you got the figure...). I must go to work now, I will check this stuff in a while,
Code: Select all
function spawnInRandomRangeChanceTime(objectToSpawn,Xrange,Yrange,ChanceTime)
local coordinateX = self.x
local coordinateY = self.y
local basecoordinateX = coordinateX-Xrange
local basecoordinateY = coordinateY-Yrange
local maxSpawnX = Xrange*2
local maxSpawnY = Yrange*2
local randomCoordinateX = math.random(0,maxSpawnX)
local randomCoordinateY = math.random(0,maxSpawnY)
local finalCoordinateX = basecoordinateX + randomCoordinateX
local finalCoordinateY = basecoordinateY + randomCoordinateY
local chancetospawn = math.random(1,100)
if chancetospawn < ChanceTime then
spawn(objectToSpawn,1,finalCoordinateX,finalCoordinateY,0)
--print(finalCoordinateX,finalCoordinateY)
end
end
function check()
spawnInRandomRangeChanceTime("snail",1,1,15)
endOooooh Ooooooh!!! Setup!!!Komag wrote:how to avoid random spawning inside the walls?