Sprache Deutsch Language English

Script Dokumentation LS 2015 - HouseLight (Patch 1.3)

Script Dokumentation Übersicht

scripts/objects/HouseLight.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- HouseLight class
2--
3-- Similar to Nightlight class but with an integrated randomizer
4-- The first child is assumed to be the light object
5--
6-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
7
8HouseLight = {}
9
10local HouseLight_mt = Class(HouseLight);
11
12function HouseLight:onCreate(id)
13 g_currentMission:addNonUpdateable(HouseLight:new(id));
14end;
15
16function HouseLight:new(name)
17 local instance = {};
18 setmetatable(instance, HouseLight_mt);
19
20 instance.init = false;
21
22 if getNumOfChildren(name) > 0 then
23 instance.lightId = getChildAt(name, 0);
24 instance.init = true;
25 end;
26
27 instance.isActive = false;
28 if (math.random() >= 0.33) then
29 instance.isActive = true;
30 end;
31
32 g_currentMission.environment:addWeatherChangeListener(instance);
33
34 return instance;
35end;
36
37function HouseLight:delete()
38 if g_currentMission.environment ~= nil then
39 g_currentMission.environment:removeWeatherChangeListener(self);
40 end;
41end;
42
43function HouseLight:weatherChanged()
44 if self.init then
45 if not g_currentMission.environment.isSunOn and self.isActive then
46 setVisibility(self.lightId, true);
47 end;
48
49 if g_currentMission.environment.isSunOn then
50 setVisibility(self.lightId, false);
51
52 -- determine if the lights will be active the next night
53 self.isActive = false;
54 if math.random() >= 0.33 then
55 self.isActive = true;
56 end;
57 end;
58 end;
59end;
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
Script Dokumentation Übersicht