run script upon save game load? FX lights issue, LightSource

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: run script upon save game load? FX lights issue, LightSo

Post by Phitt »

I have a question related to this one here. I'm using looping sound effects in my dungeon and I want them to stay (for example a fire with an appropriate sound effect). I can trigger the sounds with a hidden pressure plate, but reloading a save game removes them. Is there really no way to play a looping sound by simply placing it or tying it to a model for example? Either that or a reliable way to run a script function each time the player loads a game would be very helpful. Any suggestions? Anything I missed?
User avatar
SpiderFighter
Posts: 789
Joined: Thu Apr 12, 2012 4:15 pm

Re: run script upon save game load? FX lights issue, LightSo

Post by SpiderFighter »

aaneton wrote:I figured out the light save problem by creating lights as objects.

Objects.lua
example red floor light:

Code: Select all

defineObject{
	name = "red_floor_light",
	class = "LightSource",
	lightPosition = vec(0.5, 0.5, 0),
	lightRange = 6,
	lightColor = vec(1, 0, 0),
	brightness = 60,
	castShadow = true,
	placement = "floor",
	editorIcon = 88,
}
Now you can place (and spawn) light objects in editor, and of course destroy when needed to be off.
Yep. My method, as well. Never had a problem after doing this.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: run script upon save game load? FX lights issue, LightSo

Post by Komag »

Phitt wrote:I have a question related to this one here. I'm using looping sound effects in my dungeon and I want them to stay (for example a fire with an appropriate sound effect). I can trigger the sounds with a hidden pressure plate, but reloading a save game removes them. Is there really no way to play a looping sound by simply placing it or tying it to a model for example? Either that or a reliable way to run a script function each time the player loads a game would be very helpful. Any suggestions? Anything I missed?
Maybe you can create a custom monster that is invisible and blind and invulnerable and stick him in the wall or something and make his idle sound be the sound you want
Finished Dungeons - complete mods to play
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: run script upon save game load? FX lights issue, LightSo

Post by Phitt »

Komag wrote:
Phitt wrote:I have a question related to this one here. I'm using looping sound effects in my dungeon and I want them to stay (for example a fire with an appropriate sound effect). I can trigger the sounds with a hidden pressure plate, but reloading a save game removes them. Is there really no way to play a looping sound by simply placing it or tying it to a model for example? Either that or a reliable way to run a script function each time the player loads a game would be very helpful. Any suggestions? Anything I missed?
Maybe you can create a custom monster that is invisible and blind and invulnerable and stick him in the wall or something and make his idle sound be the sound you want
Hmm...that's quite the effort for something as simple as a sound effect and the sound would come from the monster in the wall, not from the source in game. Plus it would noticeably hurt performance as I would like to add ~20-30 looping sounds to one level (hope they really stop playing and are not only muted after the player leaves their max distance, otherwise I'll face other problems...). Thanks for the suggestion though, any other ideas?
Wish there was an onLoad function and also wish you could simply place sounds just like any other object.
User avatar
J. Trudel
Posts: 117
Joined: Tue Aug 28, 2012 3:05 pm
Location: Montreal, Canada

Re: run script upon save game load? FX lights issue, LightSo

Post by J. Trudel »

HaunterV wrote:
petri wrote:FX objects are meant to be used for short unimportant effects that need not persist across save games (persisting the state of particle effects would make the save game system much more complex because each individual particle would need to be saved).
That sounds like witch talk to me. Keep the quantum mechanics or star trek teleportation pattern talk out of grimrock!
What about the Grimrock quantum blue lighted teleportation ? Just kidding, but to explain in an easy but less accurate way : Effects that are temporary cannot be saved. because it's complicated.
The Lurker
User avatar
J. Trudel
Posts: 117
Joined: Tue Aug 28, 2012 3:05 pm
Location: Montreal, Canada

Re: run script upon save game load? FX lights issue, LightSo

Post by J. Trudel »

Phitt wrote:
Komag wrote:
Phitt wrote:I have a question related to this one here. I'm using looping sound effects in my dungeon and I want them to stay (for example a fire with an appropriate sound effect). I can trigger the sounds with a hidden pressure plate, but reloading a save game removes them. Is there really no way to play a looping sound by simply placing it or tying it to a model for example? Either that or a reliable way to run a script function each time the player loads a game would be very helpful. Any suggestions? Anything I missed?
Maybe you can create a custom monster that is invisible and blind and invulnerable and stick him in the wall or something and make his idle sound be the sound you want
Hmm...that's quite the effort for something as simple as a sound effect and the sound would come from the monster in the wall, not from the source in game. Plus it would noticeably hurt performance as I would like to add ~20-30 looping sounds to one level (hope they really stop playing and are not only muted after the player leaves their max distance, otherwise I'll face other problems...). Thanks for the suggestion though, any other ideas?
Wish there was an onLoad function and also wish you could simply place sounds just like any other object.
What about an effect like the torch ? I don't know if it's hard scripted or not but a wall torch play a looping sound.
The Lurker
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: run script upon save game load? FX lights issue, LightSo

Post by Phitt »

J. Trudel wrote: What about an effect like the torch ? I don't know if it's hard scripted or not but a wall torch play a looping sound.
Couldn't find anything useful in the torch item or torch holder object definitions, seems like the sound is hardcoded. Same for the healing crystal or teleporter btw.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: run script upon save game load? FX lights issue, LightSo

Post by Komag »

Maybe a ticking script that checks for the presence of an FX light you created (since they die with reloads), such as
findEntity("checkThisFX")
you would need to create the FX light, perhaps at dungeon start. You could do it in a script like this

Code: Select all

function makeCheckFX()
  local makeFX = spawn("fx", party.level, party.x, party.y, 0, "checkThisFX")
  makeFX:setLight(1, 0, 0, 1, 1, 6000000, false)
end
makeCheckFX()
Then you have a different script running to make sure that light still exists (because if it doesn't, that means there has been a reload), something like this:

Code: Select all

function lookForFX()
  if findEntity("checkThisFX") == "nil" then
     print("the little light is GONE! There must have been a reload")
    else
     print("the little light is still there")
  end
end
except of course you would replace the prints with whatever you want to do. In the case of the light still being there, you probably don't want to do anything, so you would actually just have the script like this:

Code: Select all

function lookForFX()
  if findEntity("checkThisFX") == "nil" then
     doStuff blah blah blah (turn back on sounds you want)
  end
end
You then set up a Timer with something like 1 or 2 seconds and have it constantly tick forever and ever, always running lookForFX() function. If you set the timer too low, like 0.1 seconds, it will tax the system. Too high, like 5 seconds, and the player could reload and be walking around for a few seconds before your script turns back on the sounds.
Finished Dungeons - complete mods to play
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: run script upon save game load? FX lights issue, LightSo

Post by Batty »

Phitt wrote:Wish there was an onLoad function and also wish you could simply place sounds just like any other object.
I agree, both these things are needed for many reasons.
User avatar
Phitt
Posts: 442
Joined: Tue Aug 14, 2012 9:43 am

Re: run script upon save game load? FX lights issue, LightSo

Post by Phitt »

Komag wrote:Maybe a ticking script that checks for the presence of an FX light you created [...]
Nice idea, unfortunately the entity still exists on reload. Tried with a particle system instead of a light, no luck. Here is the code I use, but I'm pretty sure it's not the fault of the code as it returns 'ok' so it creates and finds the entity...but also after reload, even after exiting the game and reloading. Setup is a pressure plate at the beginning of level 4 (set to activate once) which triggers makeDummyFX, lev4sounds and a timer with a 1 second interval which constantly triggers lookForFX.

Code: Select all

function makeDummyFX()
  local makeFX = spawn("fx", party.level, party.x, party.y, 0, "FXDummy")
  makeFX:setParticleSystem("earthquake_dust")
end

function lookForFX()
  if findEntity("FXDummy") == "nil" then
	makeDummyFX()
	lev4sounds()
	print("reload")
	else
	print("ok")
  end
end

function lev4sounds()
	playSoundAt("mine_volcano_fire",4,23,21)
end
Post Reply