Sprache Deutsch Language English

Script Dokumentation LS 2015 - SprayerAreaEvent (Patch 1.3)

Script Dokumentation Übersicht

scripts/vehicles/specializations/SprayerAreaEvent.lua

Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1-- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved.
2
3SprayerAreaEvent = {};
4SprayerAreaEvent_mt = Class(SprayerAreaEvent, Event);
5
6InitStaticEventClass(SprayerAreaEvent, "SprayerAreaEvent", EventIds.EVENT_SPRAYER_AREA);
7
8function SprayerAreaEvent:emptyNew()
9 local self = Event:new(SprayerAreaEvent_mt);
10 return self;
11end;
12
13function SprayerAreaEvent:new(workAreas)
14 local self = SprayerAreaEvent:emptyNew()
15 self.workAreas = workAreas;
16 return self;
17end;
18
19function SprayerAreaEvent:readStream(streamId, connection)
20 local numAreas = streamReadUIntN(streamId, 4);
21 local refX = streamReadFloat32(streamId);
22 local refY = streamReadFloat32(streamId);
23 local values = Utils.readCompressed2DVectors(streamId, refX, refY, numAreas*3-1, 0.01, true);
24 for i=1,numAreas do
25 local vi = i-1;
26 local x = values[vi*3+1].x;
27 local z = values[vi*3+1].y;
28 local x1 = values[vi*3+2].x;
29 local z1 = values[vi*3+2].y;
30 local x2 = values[vi*3+3].x;
31 local z2 = values[vi*3+3].y;
32 Utils.updateSprayArea(x, z, x1, z1, x2, z2);
33 end;
34end;
35
36function SprayerAreaEvent:writeStream(streamId, connection)
37 local numAreas = table.getn(self.workAreas);
38 streamWriteUIntN(streamId, numAreas, 4);
39 local refX, refY;
40 local values = {};
41 for i=1, numAreas do
42 local d = self.workAreas[i];
43 if i==1 then
44 refX = d[1];
45 refY = d[2];
46 streamWriteFloat32(streamId, d[1]);
47 streamWriteFloat32(streamId, d[2]);
48 else
49 table.insert(values, {x=d[1], y=d[2]});
50 end;
51 table.insert(values, {x=d[3], y=d[4]});
52 table.insert(values, {x=d[5], y=d[6]});
53 end;
54 assert(table.getn(values) == numAreas*3 - 1);
55 Utils.writeCompressed2DVectors(streamId, refX, refY, values, 0.01);
56end;
57
58function SprayerAreaEvent:run(connection)
59 print("Error: Do not run SprayerAreaEvent locally");
60end;
61
62function SprayerAreaEvent.runLocally(workAreas)
63
64 local numAreas = table.getn(workAreas);
65
66 local refX, refY;
67 local values = {};
68 for i=1, numAreas do
69 local d = workAreas[i];
70 if i==1 then
71 refX = d[1];
72 refY = d[2];
73 else
74 table.insert(values, {x=d[1], y=d[2]});
75 end;
76 table.insert(values, {x=d[3], y=d[4]});
77 table.insert(values, {x=d[5], y=d[6]});
78 end;
79 assert(table.getn(values) == numAreas*3 - 1);
80
81 local values = Utils.simWriteCompressed2DVectors(refX, refY, values, 0.01, true);
82
83 for i=1, numAreas do
84 local vi = i-1;
85 local x = values[vi*3+1].x;
86 local z = values[vi*3+1].y;
87 local x1 = values[vi*3+2].x;
88 local z1 = values[vi*3+2].y;
89 local x2 = values[vi*3+3].x;
90 local z2 = values[vi*3+3].y;
91 Utils.updateSprayArea(x, z, x1, z1, x2, z2);
92 end;
93end;
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