Ask a simple question, get a simple answer
Re: Ask a simple question, get a simple answer
Dungeon.getMap([level number]):allEntities()
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: Ask a simple question, get a simple answer
A few questions
Perhaps some of this has been answered before, but I cant seem to find it:
Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Q: and how to take into account that the party might be facing a wall, door, other monster, etc ?
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?
I mean to make randomised sounds in my dungeon, but I want to make them occur at a very low rate
: does anyone have an easy example script for this?
Perhaps some of this has been answered before, but I cant seem to find it:
Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Q: and how to take into account that the party might be facing a wall, door, other monster, etc ?
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?
I mean to make randomised sounds in my dungeon, but I want to make them occur at a very low rate
: does anyone have an easy example script for this?
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: Ask a simple question, get a simple answer
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 ...
Checks for obstacles between an object, and the tile in the direction specified. (0 - 3)
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 ...
My asset pack [v1.10]
Features a bit of everything!
Features a bit of everything!
Re: Ask a simple question, get a simple answer
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?)
eg.
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
So, this works:
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
Re: Ask a simple question, get a simple answer
what am I overseeing here. Why wont it work?
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
- zimberzimber
- Posts: 432
- Joined: Fri Feb 08, 2013 8:06 pm
Re: Ask a simple question, get a simple answer
local map = party.facing
Replace 'facing' with 'map'.
Also, its a good idea to post the error when you're asking for assistance
Replace 'facing' with 'map'.
Also, its a good idea to post the error when you're asking for assistance
My asset pack [v1.10]
Features a bit of everything!
Features a bit of everything!
Re: Ask a simple question, get a simple answer
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)
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 !
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 !
Re: Ask a simple question, get a simple answer
Hi All, Can anyone help with 'swamp_dead_tree' I want to be able to click on the hole in the tree to retrieve/place objects in or out of hole and have a connector
that will activate/deactivate door etc. I have set baseObject = "altar" on swamp_dead_tree defineObject and added class = "Surface", class = "Clickable" and
class = "Socket" but cannot get any item to be in the hole altering offset/size vec. Am I barking up the wrong tree here? Is there a better way PLS Help
that will activate/deactivate door etc. I have set baseObject = "altar" on swamp_dead_tree defineObject and added class = "Surface", class = "Clickable" and
class = "Socket" but cannot get any item to be in the hole altering offset/size vec. Am I barking up the wrong tree here? Is there a better way PLS Help
- Zo Kath Ra
- Posts: 937
- Joined: Sat Apr 21, 2012 9:57 am
- Location: Germany
Re: Ask a simple question, get a simple answer
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 !
local elevation = map:getElevation(x, y)
The error means that x is never assigned a value.