Script v1.4.4.0
- Handtools
- Events
- Objects
- AnimatedObject
- Bale
- Basketball
- Bga
- BunkerSilo
- FieldDefinition
- FillablePallet
- HelpIcons
- MountableObject
- Nightlight2
- NightlightFlicker
- PhysicsObject
- Rotator
- SaplingPallet
- ShovelTarget
- SimParticleSystem
- StationCrane
- Storage
- TourIcons
- Train
- VehicleSellingPoint
- Placeables
- Triggers
- Utils
- Vehicles
- Specializations
Engine v7.0.0.2
- General
- Entity
- Node
- Scenegraph
- Lighting
- Camera
- Shape
- Particle System
- Physics
- Spline
- Animation
- Overlays
- Sound
- Input
- XML
- Network
- Callbacks
- Text Rendering
- Terrain Detail
- Tire Track
- Editor
- Rendering
- String
- Math
- I3D
- Fillplanes
Foundation Reference
NightlightFlicker
DescriptionNightlightFlickers are flickering lights that are only active at night or during bad weatherFunctions
onCreate
DescriptionCreating nightlightflickerDefinition
onCreate(integer id)Arguments
integer | id | node id |
15 | function NightlightFlicker:onCreate(id) |
16 | g_currentMission:addUpdateable(NightlightFlicker:new(id)); |
17 | end; |
new
DescriptionCreating nightlightflickerDefinition
new(integer name)Arguments
integer | name | node id |
table | instance | Instance of object |
23 | function NightlightFlicker:new(id) |
24 | local self = {}; |
25 | setmetatable(self, NightlightFlicker_mt); |
26 | |
27 | self.id = id; |
28 | self.isVisible = false; |
29 | self.isFlickerActive = false; |
30 | self.nextFlicker = 0; |
31 | self.flickerDuration = 100; |
32 | setVisibility(self.id, self.isVisible); |
33 | |
34 | g_currentMission.environment:addWeatherChangeListener(self); |
35 | |
36 | return self; |
37 | end; |
update
DescriptionUpdate flickeringDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
45 | function NightlightFlicker:update(dt) |
46 | if self.isVisible then |
47 | |
48 | self.nextFlicker = self.nextFlicker - dt; |
49 | if self.nextFlicker <= 0 then |
50 | self.isFlickerActive = true; |
51 | setVisibility(self.id, false); |
52 | self.nextFlicker = math.floor(math.random() * 1500 + self.flickerDuration + 10); -- set next flicker at least 10ms after this one |
53 | end; |
54 | |
55 | if self.isFlickerActive then |
56 | self.flickerDuration = self.flickerDuration - dt; |
57 | if self.flickerDuration <= 0 then |
58 | self.isFlickerActive = false; |
59 | self.flickerDuration = math.floor(math.random() * 200); |
60 | setVisibility(self.id, true); |
61 | end; |
62 | end; |
63 | |
64 | end; |
65 | end; |
weatherChanged
DescriptionChange visibility of night objectDefinition
weatherChanged()Code
69 | function NightlightFlicker:weatherChanged() |
70 | if g_currentMission ~= nil and g_currentMission.environment ~= nil then |
71 | self.isVisible = not (g_currentMission.environment.isSunOn and g_currentMission.environment.currentRain == nil); |
72 | setVisibility(self.id, self.isVisible); |
73 | end; |
74 | end; |