Error: LUA ERROR (ai_update_living): bots/includes/build.lua:31: attempt to perform arithmetic on global 'healthpercent' (a nil value)
Line 31:
1
elseif object(id,"health")<healthpercent*50 then
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
--BUILD function fai_build(id) 	if playerweapons(id,74) then 		ai_selectweapon(id, 74) 		px=player(id,"tilex") 		py=player(id,"tilex") 		-- 20 Search Attempts 		for i=1,20 do 			-- Random Adjacend 			x=px+math.random(-1,1) 			y=py+math.random(-1,1) 			-- Not the player tile itself 			if (x~=px or y~=py) then 				tilex=x 				tiley=y 				if objectat(x,y) >0 then 					local maxhealth, repairable, upgradable = building_properties(id) 					if player(id,"team")==1 then 						local id = objectat(x,y) 						local type = id > 0 and object(id, "type") or 0 						if object(id,"team")==1 then 							if repairable==1 then 								if object(id,"health")<healthpercent*10 then 									local repair=math.random(0,4) 									if repair==4 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*25 then 									ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*50 then 									local repair=math.random(0,1) 									if repair==1 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*75 then 									local repair=math.random(0,2) 									if repair==2 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*100 then 									local repair=math.random(0,3) 									if repair==3 then 										ai_attack(id) 									end 								elseif upgradable==1 then 									ai_attack(id) 							elseif upgradable==1 then 								ai_attack(id) 							end 						end 					elseif player(id,"team")==2 then 						local id = objectat(x,y) 						local type = id > 0 and object(id, "type") or 0 						if object(id,"team")==2 then 							if repairable==1 then 								if object(id,"health")<healthpercent*10 then 									local repair=math.random(0,4) 									if repair==4 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*25 then 									ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*50 then 									local repair=math.random(0,1) 									if repair==1 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*75 then 									local repair=math.random(0,2) 									if repair==2 then 										ai_attack(id) 									end 								elseif object(id,"health")<healthpercent*100 then 									local repair=math.random(0,3) 									if repair==3 then 										ai_attack(id) 									end 								elseif upgradable==1 then 									ai_attack(id) 								end 							elseif upgradable==1 then 								ai_attack(id) 						end 					end 				else 					fai_buildstart(id) 				end 			end 		end 	end end --BUILD function fai_buildstart(id) 	local money=player(id,"money") 	x=tilex 	y=tiley 	if money==16000 then 		local build=math.random(0,5) 		if build==0 then ai_build(id,6,x,y) -- gate field 		elseif build==1 then ai_build(id,7,x,y) -- dispenser 		elseif build==2 then ai_build(id,8,x,y) -- turret 		elseif build==3 then ai_build(id,9,x,y) -- supply 		elseif build==4 then ai_build(id,13,x,y) -- teleporter entrance 		elseif build==5 then ai_build(id,14,x,y) end -- teleporter exit 	elseif money>=10000 then 		local build=math.random(0,3) 		if build==1 then ai_build(id,7,x,y) -- dispenser 		elseif build==2 then ai_build(id,8,x,y) -- turret 		elseif build==3 then ai_build(id,9,x,y) end -- supply 	elseif money>=5000 then 		local build=math.random(0,3) 		if build==1 then ai_build(id,14,x,y) -- teleporter exit 		elseif build==2 then ai_build(id,7,x,y) -- dispenser 		elseif build==3 then ai_build(id,7,x,y) end -- dispenser 	end end function building_properties(id) local maxhealth, repairable, upgradeable, healthpercent 	local id = objectat(x,y) 	local type = id > 0 and object(id, "type") or 0 if "type"==1 then --Barricade maxhealth=150 repairable=1 upgradable=0 elseif "type"==2 then --Barbed wire maxhealth=300 repairable=0 upgradable=0 elseif "type"==3 then --Wall I maxhealth=500 repairable=1 upgradable=1 elseif "type"==4 then --Wall II maxhealth=1000 repairable=1 upgradable=1 elseif "type"==5 then --Wall III maxhealth=2000 repairable=1 upgradable=0 elseif "type"==6 then --Gate field maxhealth=1000 repairable=0 upgradable=0 elseif "type"==7 then --Dispenser maxhealth=1000 repairable=1 upgradable=0 elseif "type"==8 then --Turret maxhealth=500 repairable=1 upgradable=1 elseif "type"==9 then --Supply maxhealth=1000 repairable=1 upgradable=1 elseif "type"==10 then --Construction site maxhealth=100 repairable=1 upgradable=0 elseif "type"==11 then --Dual turret maxhealth=750 repairable=1 upgradable=1 elseif "type"==12 then --Triple turret maxhealth=1000 repairable=1 upgradable=0 elseif "type"==13 then --Teleporter entrance maxhealth=500 repairable=0 upgradable=0 elseif "type"==14 then --Teleporter exit maxhealth=500 repairable=0 upgradable=0 elseif "type"==15 then --Super supply 		maxhealth=1500 		repairable=1 		upgradable=0 	else 		maxhealth=nil 		repairable=nil 		upgradable=nil end if maxhealth then 		healthpercent=maxhealth/100 end return maxhealth, repairable, upgradable, healthpercent end