How can I spawn a monster randomly?
Re: How can I spawn a monster randomly?
Thank you all, this was truly usefull. But i got anorther question... can it be that more monsters (tentacles) spawns in the same tile? Cause i got a tile with 2 tentacles at once.
If we do not end the war, the war will end us.
Re: How can I spawn a monster randomly?
How can it be... in one dungeon this works weel, the same code in a second dungeon doesn't work. No spawn... i'm sad for this.
tis is the code:
and the Timer is set on Running and Interval 1. Event: Activate - Target:; ScriptTentacles - Action: Check
tis is the code:
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("tentacles",2,2,95)
end
Last edited by Daght on Thu Sep 20, 2012 1:33 pm, edited 1 time in total.
If we do not end the war, the war will end us.
- cromcrom
- Posts: 549
- Joined: Tue Sep 11, 2012 7:16 am
- Location: Chateauroux in a socialist s#!$*&% formerly known as "France"
Re: How can I spawn a monster randomly?
did you check the level where you put the code ? it works only on level 1, I will try to improve this, at it is a little dumb.
A trip of a thousand leagues starts with a step.
- cromcrom
- Posts: 549
- Joined: Tue Sep 11, 2012 7:16 am
- Location: Chateauroux in a socialist s#!$*&% formerly known as "France"
Re: How can I spawn a monster randomly?
the below code should work whatever the level is.
Code: Select all
function spawnInRandomRangeChanceTime(objectToSpawn,Xrange,Yrange,ChanceTime)
local coordinateX = self.x
local coordinateY = self.y
local level = self.level
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,level ,finalCoordinateX,finalCoordinateY,0)
--print(finalCoordinateX,finalCoordinateY)
end
end
function check()
spawnInRandomRangeChanceTime("tentacles",2,2,95)
endA trip of a thousand leagues starts with a step.