How can I spawn a monster randomly?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Daght
Posts: 146
Joined: Sun Apr 15, 2012 12:28 pm
Location: Italy

Re: How can I spawn a monster randomly?

Post by Daght »

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.
User avatar
Daght
Posts: 146
Joined: Sun Apr 15, 2012 12:28 pm
Location: Italy

Re: How can I spawn a monster randomly?

Post by Daght »

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:

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
and the Timer is set on Running and Interval 1. Event: Activate - Target:; ScriptTentacles - Action: Check
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.
User avatar
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?

Post by cromcrom »

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.
User avatar
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?

Post by cromcrom »

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)
    end
A trip of a thousand leagues starts with a step.
Post Reply