Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- AnimatedMapObject
- AnimatedObject
- Bale
- Basketball
- BgaSellStation
- BunkerSilo
- BuyingStation
- DigitalDisplay
- DogBall
- HelpIcons
- InlineBale
- InlineBaleSingle
- LoadingStation
- MountableObject
- NightIllumination
- Nightlight2
- NightlightFlicker
- PackedBale
- PhysicsObject
- ProductionPoint
- Rotator
- SellingStation
- SimParticleSystem
- Storage
- SunAdmirer
- TourIconsMobile
- UnloadingStation
- VehicleSellingPoint
- WildlifeSpawner
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
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_messageCenter:subscribe(MessageType.WEATHER_CHANGED, self.oNWeatherChanged, 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 |
onWeatherChanged
DescriptionChange visibility of night objectDefinition
onWeatherChanged()Code
68 | function NightlightFlicker:onWeatherChanged() |
69 | if g_currentMission ~= nil and g_currentMission.environment ~= nil then |
70 | self.isVisible = not (g_currentMission.environment.isSunOn and not g_currentMission.environment.weather:getIsRaining()) |
71 | setVisibility(self.id, self.isVisible) |
72 | end |
73 | end |
update
DescriptionUpdate flickeringDefinition
update(float dt)Arguments
float | dt | time since last call in ms |
44 | function NightlightFlicker:update(dt) |
45 | if self.isVisible then |
46 | |
47 | self.nextFlicker = self.nextFlicker - dt |
48 | if self.nextFlicker <= 0 then |
49 | self.isFlickerActive = true |
50 | setVisibility(self.id, false) |
51 | self.nextFlicker = math.floor(math.random() * 1500 + self.flickerDuration + 10) -- set next flicker at least 10ms after this one |
52 | end |
53 | |
54 | if self.isFlickerActive then |
55 | self.flickerDuration = self.flickerDuration - dt |
56 | if self.flickerDuration <= 0 then |
57 | self.isFlickerActive = false |
58 | self.flickerDuration = math.floor(math.random() * 200) |
59 | setVisibility(self.id, true) |
60 | end |
61 | end |
62 | |
63 | end |
64 | end |