Script v1.7.1.0
- AI
- Animals
- Contracts
- Debug
- Economy
- Effects
- Events
- Farms
- GUI
- Handtools
- I3d
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- AnimatedObjectEvent
- Bale
- Basketball
- Bga
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- LoadingStation
- NightIllumination
- Nightlight2
- NightlightFlicker
- PhysicsObject
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- StorageSystem
- SunAdmirer
- TourIcons
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Placeables
- Player
- Shop
- Sounds
- Specializations
- Triggers
- Utils
- Vehicles
- Weather
Engine v1.7.1.0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- XML
- general
Foundation Reference
NightlightFlicker
Descriptions are flickering lights that are only active at night or during bad weatherFunctions
new
DescriptionCreating nightlightflickerDefinition
new(integer name)Arguments
integer | name | node id |
table | instance | Instance of object |
21 | function NightlightFlicker:new(id) |
22 | local self = {}; |
23 | setmetatable(self, NightlightFlicker_mt); |
24 | |
25 | self.id = id; |
26 | self.isVisible = false; |
27 | self.isFlickerActive = false; |
28 | self.nextFlicker = 0; |
29 | self.flickerDuration = 100; |
30 | setVisibility(self.id, self.isVisible); |
31 | |
32 | g_currentMission.environment:addWeatherChangeListener(self); |
33 | |
34 | return self; |
35 | end |
onCreate
DescriptionCreating nightlightflickerDefinition
onCreate(integer id)Arguments
integer | id | node id |
13 | function NightlightFlicker:onCreate(id) |
14 | g_currentMission:addUpdateable(NightlightFlicker:new(id)); |
15 | end |
update
DescriptionUpdate flickeringDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
43 | function NightlightFlicker:update(dt) |
44 | if self.isVisible then |
45 | |
46 | self.nextFlicker = self.nextFlicker - dt; |
47 | if self.nextFlicker <= 0 then |
48 | self.isFlickerActive = true; |
49 | setVisibility(self.id, false); |
50 | self.nextFlicker = math.floor(math.random() * 1500 + self.flickerDuration + 10); -- set next flicker at least 10ms after this one |
51 | end; |
52 | |
53 | if self.isFlickerActive then |
54 | self.flickerDuration = self.flickerDuration - dt; |
55 | if self.flickerDuration <= 0 then |
56 | self.isFlickerActive = false; |
57 | self.flickerDuration = math.floor(math.random() * 200); |
58 | setVisibility(self.id, true); |
59 | end; |
60 | end; |
61 | |
62 | end; |
63 | end |
weatherChanged
DescriptionChange visibility of night objectDefinition
weatherChanged()Code
67 | function NightlightFlicker:weatherChanged() |
68 | if g_currentMission ~= nil and g_currentMission.environment ~= nil then |
69 | self.isVisible = not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining()); |
70 | setVisibility(self.id, self.isVisible); |
71 | end; |
72 | end |