Create light at runtime

Discussions about Coding and Scripting
User avatar
Barbie
Godlike
Posts: 2928
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Create light at runtime

Post by Barbie »

A mapper has forgotten to add light in the spawn room and so I'd like to add some light with my map patcher while the map is loaded. Because bNoDelete Actors cannot be spawned, I created a sub class

Code: Select all

class TriggerLightSB extends TriggerLight;

defaultproperties {
	bNoDelete=False
}
spawned that at the proper location and set bInitiallyOn to TRUE:

Code: Select all

A = SpawnActor(Class'TriggerLightSB', LogLevel, , , vect(3232, 514, -224));
if (A != None)
{
	TriggerLight(A).bInitiallyOn = true;
	PatchCount++;
}
But there is still no light visible although the Actor was spawned. Client and server have both the Class'TriggerLightSB' (in package "MapPatcherClt"), the spawning happens in the server-only component (package "MapPatcherSvr"; that is using package "MapPatcherClt").
"If Origin not in center it be not in center." --Buggie
User avatar
Feralidragon
Godlike
Posts: 5498
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Create light at runtime

Post by Feralidragon »

That's never going to work, bInitiallyOn is processed during the actor BeginPlay event, which happens during its spawn, thus by the time you set it yourself, it does absolutely nothing, as you can check in its source code here:
http://uncodex.ut-files.com/UT/v436/Sou ... light.html

From there, why are you using a TriggerLight in the first place? Every single Actor is able to act as a light, by simply setting up its light properties, so rather than using something which is meant to be used by a mapper when building a map, perhaps you're better off in creating a custom actor, maybe one not extending Light even, that you spawn that only lits up the place that you want.

Note also however that this way of lighting areas is not going to work at all if the client has dynamic lighting turned off, so be sure you have dynamic lighting enabled to see it working, and keep in mind that some players will not see any change as many disable it for performance reasons.
User avatar
sektor2111
Godlike
Posts: 6438
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Create light at runtime

Post by sektor2111 »

Let's say that I did not love that darker area around Start Location in map Deep(v2) so I went to light a bit things but... only in player because I don't need new useless actors in server.
A few resources for clarification:
P_DEEP(V2).7z
This is primary code before to be final intended to go "packaged" when map MH-Deep(v2) is being loaded in order to get stuff needed by client. This U file is package-mapped, loaded and started by NavAdder, XCGE is properly defaulted in server configuration in order to manage turning piece of craps into cakes. Doable stuff if you might get interested:
- Getting rid of stupid movers with no collisions or borked ones by moving them away;
- Adding lights - Clients only;
- Adding decorations - Clients only + Dynamic ones (running animations);
- Solving some stuff placed behind so called glasses and which is getting vanished in Net-Play in order to be visible by client way clear and stable.
You do not have the required permissions to view the files attached to this post.
Higor
Godlike
Posts: 1866
Joined: Sun Mar 04, 2012 6:47 pm

Re: Create light at runtime

Post by Higor »

The actor must follow these conditions:
- Loaded in network communication map.
- Relevant to clients.
- Invisible.
- Maps/mods/mutators shouldn't affect it.
- bStatic, bNoDelete must be False by default.
- Should not have self-destructing capabilities.

Recommended actor: UnrealShare.ChargeLight

===
Take note:
If I were to patch it using Gunloc, I'd do it by editing Gunloc.ini and adding this section at the end of the file

Code: Select all

[MonsterHunt,MH-MapIWantToPatch]
Cmd=summon ChargeLight location=(X=3232,Y=514,Z=-224) LifeSpan=0 bAlwaysRelevant=true LightRadius=10 LightBrightness=64 LightSaturation=255 NetUpdateFrequency=2 RemoteRole=ROLE_DumbProxy

===
EDIT:
Which reminds me, I need to release an updated Gunloc build.
This is an example entry:
[MonsterHunt,MH-LongCorridor2006*]
AddedHealthOnSpawn=50
DamageToHealth_MAX=500
DamageToAmmoPct_MAX=100
AutoDamageToHealth=60
AutoDamageToAmmoPct=1500
AutoBossToDamageBonus=4000
timer=3 Cmd=mutate addbotzfaction xc_force 1 1
timer=4 Cmd=mutate addbotzfaction xc_force 1 1
timer=5 Cmd=mutate addbotzfaction xc_force 1 1
timer=6 Cmd=mutate addbotzfaction xc_force 1 1
timer=7 Cmd=mutate addbotzfaction xc_force 1 1
timer=8 Cmd=mutate addbotzfaction xc_force 1 1
timer=9 Cmd=mutate addbotzfaction xc_force 1 1
timer=10 Cmd=mutate addbotzfaction xc_force 1 1
timer=11 Cmd=set botz enemy none
Cmd=set monsterhunt minplayers 0
tag=GasbagTrigger01 delay=3 cmd=mutate gunloc aegor FV_Weapons.LMinigun
tag=SlithTrigger01 delay=3 cmd=mutate gunloc global unreali.toxinsuit
tag=MercenaryEliteTrigger01 delay=3 cmd=mutate gunloc erag FV_Weapons.ApeCannon
tag=MercenaryEliteTrigger01 delay=3 cmd=mutate gunloc rambo FV_Weapons.HellFireCannon
tag=MercenaryEliteTrigger01 delay=3.1 cmd=set apecannon airating 1.1
tag=MercenaryEliteTrigger01 delay=3.1 cmd=set hellfirecannon airating 1.1
tag=MercenaryEliteTrigger01 delay=1500 cmd=mutate gunloc scorpion FV_Weapons.AsmdPulseRifle
GameTime=1300 cmd=mutate gunloc Higor FV_Weapons.AdvancedShockRifle
GameTime=1301 cmd=set lcAdvancedShockRifle airating 1.1
GameTime=1301 cmd=set AdvancedShockRifle airating 1.1
GameTime=2000 cmd=mutate gunloc Raven FV_Weapons.SiegeInstagibRifle
GameTime=2001 cmd=set lcSiegeInstagibRifle airating 1.1
GameTime=2001 cmd=set SiegeInstagibRifle airating 1.1
GameTime=1000 cmd=mutate gunloc NegroVictor Botpack.SniperRifle
GameTime=1000 cmd=mutate gunloc Patcher Botpack.Minigun2
GameTime=1000 cmd=mutate gunloc Reaper Botpack.Armor2
GameTime=1000 cmd=mutate gunloc Reaper Botpack.ThighPads
Tag=PupaeCreatureFactory03 Count=512 Cmd=causeevent PupaeSkip
Tag=PupaeCreatureFactory04 Count=512 Cmd=causeevent PupaeSkip
Tag=SlithCreatureFactory03 Count=512 Cmd=causeevent SlithSkip
Tag=SlithCreatureFactory04 Count=512 Cmd=causeevent SlithSkip
Tag=GasbagCreatureFactory03 Count=512 Cmd=causeevent GasbagSkip
Tag=GasbagCreatureFactory04 Count=512 Cmd=causeevent GasbagSkip
Tag=MercenaryCreatureFactory03 Count=512 Cmd=causeevent MercenarySkip
Tag=MercenaryCreatureFactory04 Count=512 Cmd=causeevent MercenarySkip
Tag=SkaarjLordCreatureFactory03 Count=512 Cmd=causeevent SkaarjSkip
Tag=SkaarjLordCreatureFactory04 Count=512 Cmd=causeevent SkaarjSkip
Tag=BehemothCreatureFactory03 Count=512 Cmd=causeevent BruteSkip
Tag=BehemothCreatureFactory04 Count=512 Cmd=causeevent BruteSkip
Tag=SquidCreatureFactory01 Count=50 Cmd=causeevent SquidSkip
Tag=SquidCreatureFactory02 Count=1024 Cmd=causeevent SquidSkip
Tag=PupaeSkip Count=2 Cmd=summon gunlocteleporter location=(X=5760,Y=-28126,Z=-29144) tag=TeleChain1_S url=TeleChain1_E skin=TranglowG
Tag=SlithSkip Count=2 Cmd=summon gunlocteleporter location=(X=26118,Y=-28216,Z=-29144) tag=TeleChain2_S url=TeleChain2_E skin=TranglowG
Tag=GasbagSkip Count=2 Cmd=summon gunlocteleporter location=(X=25856,Y=-19372,Z=-22869) tag=TeleChain3_S url=TeleChain3_E skin=TranglowG
Tag=MercenarySkip Count=2 Cmd=summon gunlocteleporter location=(X=26590,Y=-12652,Z=-17622) tag=TeleChain4_S url=TeleChain4_E skin=TranglowG
Tag=SkaarjSkip Count=2 Cmd=summon gunlocteleporter location=(X=26624,Y=-3966,Z=-11928) tag=TeleChain5_S url=TeleChain5_E skin=TranglowG
Tag=BruteSkip Count=2 Cmd=summon gunlocteleporter location=(X=26750,Y=3122,Z=-7127) tag=TeleChain6_S url=TeleChain6_E skin=TranglowG
Tag=QuidSkip Count=2 Cmd=summon gunlocteleporter location=(X=27070,Y=16510,Z=-3544) tag=TeleChain7_S url=TeleChain1_S skin=TranglowG
Cmd=summon gunlocteleporter location=(X=26118,Y=-27334,Z=-29144) tag=TeleChain1_E skin=Tranglow
Cmd=summon gunlocteleporter location=(X=25856,Y=-18510,Z=-22869) tag=TeleChain2_E skin=Tranglow
Cmd=summon gunlocteleporter location=(X=26210,Y=-12652,Z=-17622) tag=TeleChain3_E skin=Tranglow
Cmd=summon gunlocteleporter location=(X=26624,Y=-2944,Z=-11928) tag=TeleChain4_E skin=Tranglow
Cmd=summon gunlocteleporter location=(X=26750,Y=3530,Z=-7127) tag=TeleChain5_E skin=Tranglow
Cmd=summon gunlocteleporter location=(X=26176,Y=16510,Z=-3544) tag=TeleChain6_E skin=Tranglow
User avatar
sektor2111
Godlike
Posts: 6438
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Create light at runtime

Post by sektor2111 »

The light in cause
Spoiler
class Dyn_Light expands Light;

event PrebeginPlay(){}

defaultproperties
{
bNetTemporary=True
NetUpdateFrequency=0.5
RemoteRole=ROLE_None
bStatic=False
bNoDelete=False
bCollideWhenPlacing=False
bCollideWorld=False
}
takes place ONLY in client and so it will not be bandwidth consuming, in case that it needs to go triggered, that's another story and server is the authority here for triggered things. I would not do it triggered for making light in spawn area, but leaving light until map-change so this way is more cheap for bandwidth and... server will not have additional actors to iterate. We have only a keypoint doing this task, in final build it is even reducing bloody coronas (TOO BIG) and tweaking "lantern" actors because the have no meaning as dark as they are with their tired default properties.
All decorations intended for client-only will never use any RemoteRole and they do not have any animation issues being handled by client without any borked replication code - see statue from AfterDark as a sample. Charging channels in such case are very last thing which I do. First time I used dual decorations server and client but now I'm no longer interested about such methods, a patching badge can be part of client-only working perfectly (like in WarOfMonsters)...