{script} Spawn something just in front of the party

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

{script} Spawn something just in front of the party

Post by cromcrom »

Hi, another script. I use it to spawn skeletons when you disturb some skulls. Makes for a nasty surprise :-) Enjoy.

Code: Select all

function spawnInFrontOfParty(objectToSpawn)
local spawnX = 0
local spawnY = 0
local spawnfacing = 0

if party.facing == 0 then
spawnX = party.x
spawnY = (party.y)-1
spawnfacing = 2
end
if party.facing == 1 then
spawnX = 1+party.x
spawnY = party.y
spawnfacing = 3
end
if party.facing == 2 then
spawnX = party.x
spawnY = 1+party.y
spawnfacing = 0
end
if party.facing == 3 then
spawnX = (party.x)-1
spawnY = party.y
spawnfacing = 1
end
spawn(objectToSpawn,party.level,spawnX,spawnY,spawnfacing)
end
A trip of a thousand leagues starts with a step.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: {script} Spawn something just in front of the party

Post by JohnWordsworth »

That's really cool and makes it very easy to spook the party - I like it (and look forward to using it!). A quick suggestion if you would like to reduce the number of lines (not all that important I guess, but I just noticed you could reduce the script to about 40% of the size!).

Code: Select all

function spawnInFrontOfParty(objectToSpawn)
  local spawnX = party.x
  local spawnY = party.y
  local spawnFacing = (party.facing + 2) % 4

  if party.facing == 0 then 
    spawnY = spawnY - 1
  elseif party.facing == 1 then
    spawnX = spawnX + 1
  elseif party.facing == 2 then 
    spawnY = spawnY + 1
  else 
    spawnX = spawnX - 1
  end

  spawn(objectToSpawn, party.level, spawnX, spawnY, spawnFacing)
end
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: {script} Spawn something just in front of the party

Post by cromcrom »

I am a lua beginner, I love it how you guys can make things much more nice and simple. Thanks :-)
A trip of a thousand leagues starts with a step.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: {script} Spawn something just in front of the party

Post by JohnWordsworth »

Sorry, I didn't mean to be one of those annoying people that optimises every little line for the sake of it, I just copied it into my 'Fun Lab' dungeon for later use and thought I might as well post back the version I used as it was a bit shorter.

Cool idea - and I can't wait to use it!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: {script} Spawn something just in front of the party

Post by cromcrom »

Don't be, I really genuinely admire code optimizers. Mines are so "brutal" ...
I am adding a lot of little systems like that in The Lost Continent :-) (I now, I am advertising, well, you know... :-) )
A trip of a thousand leagues starts with a step.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: {script} Spawn something just in front of the party

Post by petri »

To get the location in front of an entity you could also use the getForward() function:
local dx,dy = getForward(party.facing)
local x,y = party.x + dx, party.y + dy
Now x and y hold the coordinates in front of the party.

Same technique can be used to get the location behind the party or beside the party. E.g. Replace party.facing by (party.facing+2)%4 to get the location behind the party.

Naturally you can also replace party with any other entity.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: {script} Spawn something just in front of the party

Post by Komag »

so if petri's notes were applied, what would be a good final version of this to put in the Script Repository?
Finished Dungeons - complete mods to play
Post Reply