Jump to content

Scripted light from a weapon


Razakel

Recommended Posts

You will probably have to use functions like GetCurrentTime and GetCurrentWeatherID and possibly GetCurrentWeatherPercent to see if the weather is in transition. Then use a combination of GetLightRadius and SetLightRadius. Calling GetInWorldSpace and having it return 0 means you're in an interior cell. Note that SetLightRadius won't show unless the cell is reloaded or you disable and enable the object. You will need to be using OBSE for most of these functions to work correctly.

 

Another option is to use magic effects and alternate between one with no light and one that has a light and use any one of the dozens of OBSE SetMagicEffectXXXX functions. Can also use enchantments and then use SetEnchantment.

 

What you're asking to do isn't hard but it isn't easy either. Basically you're going to need to see what functions are available to handle your conditions:

 

Is it Night and are we outside?

Is it dark enough to need a light and are we inside?

 

Then, based on those conditions you'll need to respond to them by doing one of the following:

 

Altering light radius.

Swapping between magic effects.

Swapping between enchantments.

 

Hope this helps, all I could come up with off the top of my head :)

Link to comment
Share on other sites

TBH, I think your hardest condition will be is it dark enough to need a light and are we inside. Checking to see if you're inside isn't difficult but checking to see if it's dark enough to need a light might be. You might end up having to have a script walk through ALL objects in a cell and see if they're lights and then check their position and radius and other light parameters and then act accordingly (note this will produce a noticable lag to the user on cell entry).

 

You might want to consider letting the user determine if it's dark enough to use a light and provide some way for them to activate and deactivate the light on the weapon themselves.

Link to comment
Share on other sites

It would be a simple matter of equiping the light source for day/night via script. For the dark interior cells, use glow maps.
Link to comment
Share on other sites

If what you want to do is done in another mod (you mentioned Anduril Reforged), I suggest looking at the weapon script from that mod for an idea of how it works. Don't steal his code line for line, but do use it to teach yourself which commands are being used and how they work. Although from what I've seen Lanceor is a really nice guy, and I bet if you email and ask him for permission he'll have no problem with you copy\pasting his code. Worth a shot anyway.
Link to comment
Share on other sites

Here's a copy of the Anduril Reforged script with everything but the light functions stripped out. Feel free to copy the code and add it to any weapon you like - I learned much of it from studying the Bluefire Claymore after all. :)

 

scn A1AndurilReforgedMain01

Float XCoordinate
Float YCoordinate
Float ZCoordinate
Short Direction
Short Timer
Ref LightSource

BEGIN ONLOAD

set LightSource to A1AndurilMoonlight1

END


BEGIN GAMEMODE

;   Chooses light source based on location or time of day. 

if ( GameHour < 6 ) || ( GameHour >= 20 ) || ( player.IsInInterior == 1 )
set LightSource to A1AndurilMoonlight1
if A1AndurilSunlight1.getdisabled != 1
	A1AndurilSunlight1.disable
endif
else
set LightSource to A1AndurilSunlight1
if A1AndurilMoonlight1.getdisabled != 1
	A1AndurilMoonlight1.disable
endif
endif

;   Routine for moving light around if Anduril is being wielded. 

if ( PlayerRef.GetEquipped ThisSword ) && ( PlayerRef.IsWeaponOut )

Set Direction to PlayerRef.GetAngle Z
Set XCoordinate to PlayerRef.GetPos X + (10 * Sin Direction)
Set YCoordinate to PlayerRef.GetPos Y + (10 * Cos Direction)
Set ZCoordinate to PlayerRef.GetPos Z + 100

if LightSource.getdisabled == 1
	LightSource.enable
endif

if LightSource.getinsamecell player == 0
	LightSource.MoveTo Player
endif

set Timer to Timer - 1

if Timer == 0
	LightSource.PositionCell 0 0 0 0 A1AndurilTestCell
endif

if Timer < 0 
	set Timer to 6	;   Reset timer. 
	LightSource.MoveTo Player XCoordinate, YCoordinate, ZCoordinate	;   Needs to be done occasionally 
endif

LightSource.SetPos X XCoordinate
LightSource.SetPos Y YCoordinate
LightSource.SetPos Z ZCoordinate

else
if LightSource.getdisabled != 1
		LightSource.disable
endif

endif	

END

 

For the script to work, you'll need to create two persistent lights called A1AndurilSunlight1 and A1AndurilMoonlight1. The script moves one of them around to follow the player when the sword is out.

 

At the moment, the only way to change the nature of the light is to use different lights like I did with Anduril. That's why there are only two colours at the moment as the script size will grow exponentially for each colour added. OBSE 0020 will add functions to change the light itself dynamically, and I plan to overhaul the script once it is out of beta.

 

Hope that helps. :thumbsup:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...