Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

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.
User avatar
THOM
Posts: 1274
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Re: Ask a simple question, get a simple answer

Post by THOM »

thanxs :)
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post 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?
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post 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.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post 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
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post 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 
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post 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 ;)
My asset pack [v1.10]
Features a bit of everything! :D
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

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

Re: Ask a simple question, get a simple answer

Post 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
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post 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.
Post Reply