Re: Ask a simple question, get a simple answer
Posted: Wed Dec 21, 2016 10:23 pm
Dungeon.getMap([level number]):allEntities()
Official Legend of Grimrock Forums
http://grimrock.net/forum/
Get the parties position, add or subtract 1 from x or y, run the spawn() function for that locationkelly1111 wrote:Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Checks whether a location is blocked by a wall, monster, or an obstacle -kelly1111 wrote:Q: and how to take into account that the party might be facing a wall, door, other monster, etc ?
Code: Select all
if not party.map:isBlocked(x, y, elevation) then ...
Code: Select all
local o = party.map:checkObstacle(object, facing)
if not o or o == "dynamic_obstacle" then ...
kelly1111 wrote:Q: in a math.random script, how do you make it so that say for instance math.random(100) the numbers 0-90 trigger nothing
... how do I define that?
Code: Select all
if math.random() >= 0.9 then ...
The global function getForward(party.facing) will return the two [+1, -1, 0 ] coordinate offsets for X and Y that can be used to identify the tile in front of the party; or reversed, to identify the tile behind the party.zimberzimber wrote:Get the parties position, add or subtract 1 from x or y, run the spawn() function for that locationkelly1111 wrote:Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Code: Select all
function surprise()
local dX, dY = getForward(party.facing)
spawn("forest_ogre", party.level, party.x + dX, party.y + dY, (party.facing+2)%4, party.elevation) --spawn Ogre in front of the party
spawn("forest_ogre", party.level, party.x - dX, party.y - dY, party.facing, party.elevation) --spawn Ogre behind of the party
end
Code: Select all
function surprise2()
local dX, dY = getForward((party.facing+1)%4) --This causes the function to return values relative the party's right, instead of them facing forward
spawn("forest_ogre", party.level, party.x + dX, party.y + dY, (party.facing-1)%4, party.elevation) --spawn Ogre to the right of the party
spawn("forest_ogre", party.level, party.x - dX, party.y - dY, (party.facing+1)%4, party.elevation) --spawn Ogre to the left of the party
end
Code: Select all
elseif random == 2 then
local dX, dY = getForward(party.facing)
local map = party.facing
local elevation = map:getElevation(x, y)
if not map:isBlocked(x, y, elevation) then
spawn("rat_swarm", party.level, party.x - dX, party.y - dY, party.facing, party.elevation)
return
end
Code: Select all
elseif random == 2 then
playSound("Horror02")
local dX, dY = getForward(party.facing)
local map = party.map
local elevation = map:getElevation(x, y)
if not map:isBlocked(x, y, elevation) then
spawn("rat_swarm", party.level, party.x - dX, party.y - dY, party.facing, party.elevation)
return
end
Looks like the problem is in (not just near) the line:kelly1111 wrote:Did as you suggested in the code, changed it to this:
I now get the following error, near the line: local elevation = map:getElevation(x, y)Code: Select all
elseif random == 2 then playSound("Horror02") local dX, dY = getForward(party.facing) local map = party.map local elevation = map:getElevation(x, y) if not map:isBlocked(x, y, elevation) then spawn("rat_swarm", party.level, party.x - dX, party.y - dY, party.facing, party.elevation) return end
bad argument #1 to 'get Elevation' (numer expected, got nil) x
... I have copied this line from the skeleton commander summoning part. Why isnt it working in this case?
thanks in forward for the help !