Page 176 of 396

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 21, 2016 10:23 pm
by minmay
Dungeon.getMap([level number]):allEntities()

Re: Ask a simple question, get a simple answer

Posted: Wed Dec 21, 2016 10:40 pm
by THOM
thanxs :)

Re: Ask a simple question, get a simple answer

Posted: Sun Dec 25, 2016 4:24 pm
by kelly1111
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?

Re: Ask a simple question, get a simple answer

Posted: Sun Dec 25, 2016 6:00 pm
by zimberzimber
kelly1111 wrote:Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Get the parties position, add or subtract 1 from x or y, run the spawn() function for that location
kelly1111 wrote:Q: and how to take into account that the party might be facing a wall, door, other monster, etc ?
Checks whether a location is blocked by a wall, monster, or an obstacle -

Code: Select all

if not party.map:isBlocked(x, y, elevation) then ...
You have an example of this inside the Skeleton Commander definition.

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 ... 
I'm not sure where an example of this can be found inside the vanilla asset pack, but if you have the current version(1.8) of my asset pack, check inside the vampires brain or the Scavenger Queens brain.
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 ...
math.random() will random a number between 0 and 1, and checking if it lands at 0.9 or higher is the equivalent of 10% chance.

Re: Ask a simple question, get a simple answer

Posted: Mon Dec 26, 2016 3:24 am
by Isaac
zimberzimber wrote:
kelly1111 wrote:Q: how do I spawn a monster near the party with a script (regardless of where in the level the party is?)
Get the parties position, add or subtract 1 from x or y, run the spawn() function for that location
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.

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
Also, using (party.facing+1)%4 indicates the tile to the party's right, and (party.facing-1)%4 indicates the tile to the party's left.
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

Posted: Mon Dec 26, 2016 2:44 pm
by kelly1111
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 

Re: Ask a simple question, get a simple answer

Posted: Mon Dec 26, 2016 3:36 pm
by zimberzimber
local map = party.facing

Replace 'facing' with 'map'.
Also, its a good idea to post the error when you're asking for assistance ;)

Re: Ask a simple question, get a simple answer

Posted: Mon Dec 26, 2016 6:44 pm
by kelly1111
Did as you suggested in the code, changed it to this:

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 
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 !

Re: Ask a simple question, get a simple answer

Posted: Mon Dec 26, 2016 7:16 pm
by billb52
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

Re: Ask a simple question, get a simple answer

Posted: Mon Dec 26, 2016 8:05 pm
by Zo Kath Ra
kelly1111 wrote:Did as you suggested in the code, changed it to this:

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 
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 !
Looks like the problem is in (not just near) the line:
local elevation = map:getElevation(x, y)

The error means that x is never assigned a value.