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