Code: Select all
1function Create()
2 Object.SetProperty( "Stock", 32.0);
3 Object.SetProperty("StockType", "WaterBottle" );
4 Object.SetProperty("NeedsLoading", false);
5 Object.SetProperty("Count", 0.0);
6 Object.SetProperty("CurrentDrink", "WaterBottle");
7 Object.SetProperty("IsLoaded", true);
8end
9
10function Update( timePassed )
11
12 if Object.GetProperty("IsLoaded") == nil then
13 Create();
14 end
15
16 local currentStock = tonumber(Object.GetProperty("Stock"));
17 local count = tonumber(Object.GetProperty("Count"));
18 local Alert = this.GetNearbyObjects("AlertElectrical", 1)
19 cable = this.GetNearbyObjects("ElectricalCable", 1)
20 nearbyPrisoner = this.GetNearbyObjects("Prisoner",10)
21 local pCounter = 0
22 local cableCount = 0
23
24 for table, distance in pairs(cable) do
25 cableCount = cableCount + 1
26 end
27
28 for table, distance in pairs(nearbyPrisoner) do
29 pCounter = pCounter + 1
30 end
31
32 count = count + timePassed;
33 Object.SetProperty("Count", count);
34
35 if Object.GetProperty("NeedsLoading") then
36 Object.GetProperty("CurrentDrink");
37 Object.SetProperty("CurrentDrink", "WaterBottle");
38 Object.CreateJob("LoadCooler");
39 Object.SetProperty("Tooltip", "job_custom_loadcooler");
40 end
41
42 -- Clear the tooltip.
43 Object.SetProperty("Tooltip", "");
44
45 if count > 20.0 then
46 if cableCount > 0 then
47 if currentStock > 0.0 then
48 if pCounter > 0 then
49 Object.GetProperty("CurrentDrink");
50 local currentDrink = Object.Spawn( "WaterBottle", Object.GetProperty("Pos.x"), Object.GetProperty("Pos.y"));
51 Object.SetProperty("CurrentDrink", currentDrink);
52 Object.SetProperty( "Stock", currentStock - 1 );
53 end
54 end
55 end
56 end
57 Object.SetProperty("Tooltip", "Count 0");
58 Object.SetProperty("Count", 0.0);
59 end
60
61 if currentStock < 1.0 then
62 Object.SetProperty( "NeedsLoading", true );
63 end
64
65 if cableCount < 1 then
66 Object.Spawn("AlertElectrical", this.Pos.x, this.Pos.x)
67 end
68
69 if cableCount > 0 then
70 Object.Delete( Alert )
71 end
72
73 this.Tooltip = tostring(Object.GetProperty("Stock")) .. " Water Bottles Left."
74
75function JobComplete_LoadCooler()
76 Object.SetProperty("Stock", 32.0);
77 Object.SetProperty("NeedsLoading", false);
78 Object.SetProperty("Count", 20.0);
79end
It says that in line 61 i am trying to compare with a nil value, but as you can see, that variable works perfectly fine in line 47. Another weird thing is that this variable check only pops up saying "Attemping to compare with nil value" ONCE, and this variable check is in the update function, so it makes no sense.