PLUGIN: Flashlight plugin v1.1.1

Started by a-v-o, Mon 22/09/2003 22:44:19

Previous topic - Next topic

a-v-o

Edit by strazer: v1.2 released

--

When I was checking someone's script I got crashs using the command SetFlashlightBrightness. When I looked into the source code of the plugin I realized that some functions were incomplete. But noone ever reported such a crash to me.

I recommend you replace your older flashlight-dll with this new version:
http://a-v-o.selfhost.de/ags/flashlight/

New feature (still experimental):
- darkness masks
if a character walks around with a flashlight then you can use the mask to create light-behinds (similar to walk-behinds).
warning: for each mask you need a hicolor-sprite with room size, so games can grow big and maybe slow down.

delta

This is odd.  I never had any crashes but if you insist.

Great plugin! My personal favourite

a-v-o

Well, never work in the middle of the night on a source code that you haven't seen for a long time. :-\
Fixing one bug, I introduced another.   >:(

Build 1.1.1.13 should be ok now. (Same download location)

Quote
Great plugin! My personal favourite
Thank you. :)

Vel

Man, you are one of the best programmers around here! And your plugins are the best!

Petter

Is there a plugin that will let me create a semi-transparent shadow beneath my characters feet, or can the flashlight plug do that? Thanks

SSH

You can do it with a transparent character (of the shadow) and the following in your repeatedly_execute:

player[SHADOW].x=player[EGO].x + x_offset
player[SHADOW].y=player[EGO].y + y_offset

or something like that...
12

scotch

The problem with that is it doesn't work during blocking scripts, I think.  A plugin would be useful..

a-v-o

The flashlight plugin is designed to shade all but a round area. It shouldn't be too hard to change it, so that it shades only this round area. If you need it, I look into it.

Barbarian

#8
A really nice plug-in, and it does exactly what I want it to do for some parts of my game, however, I found a bit of a "strange bug", in which I don't know if it's just the FlashLight Plugin, or if it's just the way AGS works.

Anyways, here's an example of the "bug".

Let's say your character is in a dark room in which you want to use the Flashlight Plugin, so you activate it with the script command upon the "Player Enters Screen (Before Fadein)". Okay, so no problem, everything works fine.

Then, lets say you leave the dark room, and you turn off the Flashlight effect to return everything to normal light levels.. okay.. no problem.Ã, 

But.. here's where the "bug" happens...
Let's say you are in the dark room with the Flashlight Plugin activated. And then you make a Save Game point in there... then you leave that room and go into a room in which the Flashlight Plugin effect is turned off and things return to normal light levels.. Now... From the current room you're in with the "normal light levels", choose to "Restore a Game", and select the saved-game-point from where you were in the dark room with the Flashlight Plugin effect active.. Now when the game loads back in, mysteriously, the once dark room is now fully lit!
Restore a game seems to bypass the "Player Enters (before and/or after fadein)" commands, thereby not enabling the Flashlight Plugin.

A couple of possible work-a-rounds was to include the Flashlight Effect in a script to be called in the room's "Repeatedly Execute" option. But, even this way, upon Restoring a game like I mentioned above, you'll still get a quick "Bright flash" of the fully lit room before the Repeatedly Execute has a chance to enable the FLashlight Plugin and run the Flashlight Plugin script.Ã,  Also, doing it this way, it does noticeably slow down the character a bit (a little sluggish almost) as the command is Repeatedly Executed.

The other work-a-round was to perhaps Check on the "Save / Load Disabled" option for the room, but that's kind of an annoying "fix" for that.

Ã,  Ã, Okay, anyone else have this same problem?Ã,  Any ideas of a more better work-a-round or fix?

Best regards,
--- Big Don, the Barbarian.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Pumaman

Plugins have the opportunity to save their state into the save game so that it can be restored properly - looks like the flashlight plugin doesn't current support that. You might want to see if you can contact a-v-o about it, I haven't seen him around here lately.

MrColossal

why not instead of putting the script in rep.execute put it in the before fade in?

have a global int that tells the plug in whether it should be on or not and before fading in AGS should check the global int and then turn on the plug in...

or am i reading you wrong and you tried this already
"This must be a good time to live in, since Eric bothers to stay here at all"-CJ also: ACHTUNG FRANZ!

Hollister Man

If you put it in the before fade in and restore a game saved AFTER the fadein, the function will never be called.  ;)
That's like looking through a microscope at a bacterial culture and seeing a THOUSAND DANCING HAMSTERS!

Your whole planet is gonna blow up!  Your whole DAMN planet...

MrColossal

which brings up a question: OnGameRestore() ?
"This must be a good time to live in, since Eric bothers to stay here at all"-CJ also: ACHTUNG FRANZ!

Gilbert

Hmm in that case why not block the saving function in a room that uses the plugin?

MrColossal

"The other work-a-round was to perhaps Check on the "Save / Load Disabled" option for the room, but that's kind of an annoying "fix" for that."

I think this is what he means... and i agree it is an annoying work around
"This must be a good time to live in, since Eric bothers to stay here at all"-CJ also: ACHTUNG FRANZ!

Barbarian

Yes, I could set the "Save / Load" to Disabled, but, that's not what I really want.
I'm planning a series of dark rooms in my game, and I want the player to be able to Save / Load a game from any room they want. But... I might have another  better work-around in mind, if I can figure out something, I'm sure it's simple.. ;p   I'll let you know.
Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Scorpiorus

Yeah, until saving of the state is implemented you could write your own function that also saves the state of the plugin and replicates it on game load:

int IsScreenDarken = 0;

function DarkenScreen() {

   SetFlashlightDarkness(GetFlashlightMinLightLevel());
   IsScreenDarken = 1;
}


function LightenScreen() {

   SetFlashlightDarkness(GetFlashlightMaxLightLevel());
   IsScreenDarken = 0;
}



function on_event(int event, int data) {

   if (event == RESTORE_GAME) {

      if (IsScreenDarken) DarkenScreen();
      else LightenScreen();
   }

}

a-v-o

Quote from: Barbarian on Mon 31/05/2004 18:35:36Restore a game seems to bypass the "Player Enters (before and/or after fadein)" commands, thereby not enabling the Flashlight Plugin.

Yes, the restore game function bypasses the before/after fadein events but it calls on_event with data=RESTORE_GAME. As this function is also called each time a player enters a room (just like before fadein) you can put there all your code which handles lighting for all rooms:

function on_event (int event, int data){
Ã,  if ((event == ENTER_ROOM) || (event == RESTORE_GAME))
Ã,  {
Ã,  Ã,  // put code to adjust room lighting here
Ã,  }
}

I see in the preview that Scorpiorus suggested something similar.

Barbarian

Yay!! Thank you so much guys!
I finally got it working.. Whew.. I'm learning so much about this scripting stuff.

Okay, I followed Scorpiorus's example of what I might do, but I kept getting various errors (remember I'm still a "newbie" at AGS and this scripting stuff).

Anyways, after some more tiral and error, and some more researching here's how I did it.

In my global script, here's what it looks like (btw, I was going for a lantern/candlelight type of effect)...

// main global script file

int IsScreenDarken = 0;

function DarkenScreen() {

SetFlashlightDarkness (3);
Ã,  SetFlashlightBrightness (GetFlashlightMaxLightLevel ());
Ã,  SetFlashlightDarknessSize (48);
Ã,  SetFlashlightBrightnessSize (20);
Ã,  SetFlashlightFollowCharacter (GetPlayerCharacter (), 0, -20, 20, 10);


IsScreenDarken = 1;
}

function LightenScreen() {

Ã,  Ã, SetFlashlightDarkness (GetFlashlightMaxLightLevel ());
Ã,  Ã, IsScreenDarken = 0;
}


Ã,  ....then towards the bottom of the Global Script, I added...

function on_event(int event, int data) {

Ã,  Ã, if (event == RESTORE_GAME) {

Ã,  Ã,  Ã,  if (IsScreenDarken) DarkenScreen();
Ã,  Ã,  Ã,  else LightenScreen();
Ã,  Ã, }

}


... but, then it still wasn't working untill, silly me,Ã,  realized the functions had to be imported.
So, opening up my Script Header, I added the following...

import function DarkenScreen();
import function LightenScreen();


...so now when I want to use one of those functions in a room, to darken the room and turn on my light, from the room editorÃ,  settings and interaction, I add "Player Enters Screen (before fadein)" option, select add a "Run Script" command, and in the script I put in " DarkenScreen(); "Ã,  and for a room with the effect turned off (normal light levels) I can use " LightenScreen(); ".

Ã,  Ã, I put what I did here for an example in case it might help other users are trying to figure out how to do the same thing or something similar.

Thanks again for all the help everyone. Much appreciated.

--- Big Don, the Barbarian.

Conan: "To crush your enemies, see them driven before you, and to hear the lamentation of the women!"
Mongol General: "That is good."

Blade of Rage: www.BladeOfRage.com

Rui 'Trovatore' Pires

Hmmm.... a-v-o, however many workarounds there may be, is there any specific reason for you not having coded it in such a way that this wouldn't happen? Or are you working on that already?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk