Aller au contenu

Photo

Yet another light question


  • Veuillez vous connecter pour répondre
13 réponses à ce sujet

#1
PJ156

PJ156
  • Members
  • 2 985 messages
I am trying to script a light on.

I know they lose thier tag so I have done it by searching for the nearest light object, but it's not working. The script in bold is the bit that is supposed to be switching the light on.

I found the recomputelighting script, id this needed?

All help welome :)


void main()
{
object oPC = GetPCSpeaker();
object oItem;
oItem = GetItemPossessedBy(oPC, "dd_sune_key");
if (GetIsObjectValid(oItem))
   DestroyObject(oItem);
object oTarget;
oTarget = GetObjectByTag("2010_dd_sune_gem_1");
effect eBeam1 = EffectNWN2SpecialEffectFile("fx_a_spirit_gorge_hit");
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBeam1, oTarget, 3.0f);
 
object oNearest = GetNearestObject(OBJECT_TYPE_LIGHT,oTarget);
SetPlaceableIllumination (oNearest, TRUE);
object oArea = GetArea(oTarget);
RecomputeStaticLighting(oArea);
oTarget = GetObjectByTag("2010_dd_sune_gem_2");
effect eBeam2 = EffectNWN2SpecialEffectFile("fx_death_god_light_blue");
DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBeam2, oTarget, 3.0f));
}

PJ

#2
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
With lights, I've found that if you create them via script and store them as a local object, then it can work. I've found no reliable way to find lights via scripting if they've been placed in the toolset. If you want to tinker with lights, you've got to make them via scripting, sadly.

Alternatively, you could create placed effects which are just lights and then destroy the effect as you see fit.

#3
PJ156

PJ156
  • Members
  • 2 985 messages
Okay so I could create a light blueprint and spawn it on the ipoint?

Is that how it might work.

PJ

#4
Guest_Chaos Wielder_*

Guest_Chaos Wielder_*
  • Guests
Yes, you could do something like that. I'd say either make a waypoint(as I believe they have *slightly* less system drag), but an ipoint would work as well.

#5
PJ156

PJ156
  • Members
  • 2 985 messages
Thanks, the ipoint is there so I will try that first.

Heh! Dinner, Top Gear, script a light; it's shaping up to be a good Sunday night.

PJ

#6
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
You can get placed lights via script if you just use an initialization script at game start, one that looks up the lights by tag and then stores them as local objects. I run my from the module's on-player-loaded event, within a condition that ensures the scripts are only run once, when the player first starts the module (and not on reload).

#7
PJ156

PJ156
  • Members
  • 2 985 messages
Thanks LotRS, that might be why I am having little luck in spawning a light object right now.

I am thinking to investigate SLS2 to see if that will help.

Funny, I know this has come up before but you might have thought switching a light on would be easy ...

PJ

PS: Top Gear was dissappointing too, not the Sunday night I hoped for :)

Modifié par PJ156, 31 juillet 2011 - 09:18 .


#8
Shallina

Shallina
  • Members
  • 1 011 messages
The tag of light are lost when you save a game, or it's probably when you reload it.

So if you want to access a light propelly that mean you can't access it with its tag.

One of the working solutions, is to store the light as a local object, then you can access that local object with the GetLocalObject() function beceause you fetch a ref and not a tag. That's the idea.

Of course it's best to spam the light with script, so you can fully alter them at will with very few effort and even with in game events if you wish.

Modifié par Shallina, 31 juillet 2011 - 09:58 .


#9
Dann-J

Dann-J
  • Members
  • 3 161 messages
Try this:

void main()
{
object oPC = GetPCSpeaker();
object oItem;
oItem = GetItemPossessedBy(oPC, "dd_sune_key");
if (GetIsObjectValid(oItem))
DestroyObject(oItem);
object oTarget;
oTarget = GetObjectByTag("2010_dd_sune_gem_1");
effect eBeam1 = EffectNWN2SpecialEffectFile("fx_a_spirit_gorge_hit");
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBeam1, oTarget, 3.0f);

object oNearest = GetNearestObject(OBJECT_TYPE_LIGHT,oTarget);
SetLightActive(oNearest, 1);
//object oArea = GetArea(oTarget);
//RecomputeStaticLighting(oArea);
oTarget = GetObjectByTag("2010_dd_sune_gem_2");
effect eBeam2 = EffectNWN2SpecialEffectFile("fx_death_god_light_blue");
DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_PERMANENT, eBeam2, oTarget, 3.0f));
}

I don't think you have to recompute static lighting when turning a point light on or off (at least, I've never done so). Just make sure the light you place near the Sune gem is off to begin with. If you want to turn the light off again, simply use SetLightActive(oNearest, 0)

#10
Lugaid of the Red Stripes

Lugaid of the Red Stripes
  • Members
  • 955 messages
Yeah, DannJ is right, I didn't bother to read your code before. SetLightActive is the function you need to use.

#11
Alupinu

Alupinu
  • Members
  • 528 messages
I don't know Pj, i have screwed with light points a thousand times and the only thing that seems to work for me is to just destroy_object(lightpoint)/off and create_object/on.

#12
Dann-J

Dann-J
  • Members
  • 3 161 messages

Alupinu wrote...

I don't know Pj, i have screwed with light points a thousand times and the only thing that seems to work for me is to just destroy_object(lightpoint)/off and create_object/on.


I turn lights on and off via scripts all the time, and as long as I use GetNearestObject instead of GetObjectByTag then it always works for me. I have a script that allows you to light and extinguish candles for when I use day/night cycles indoors. I create and destroy the flame effects, but I simply activate and deactivate the same light object repeatedly.

#13
PJ156

PJ156
  • Members
  • 2 985 messages
That worked DannJ, thanks very much. I searched under light in the script functions and did not see this one.

Perhaps new glasses are in order,

PJ

#14
Alupinu

Alupinu
  • Members
  • 528 messages
GetNearestObject huh? I may have to try that. Thanks DannJ. :)