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
ai={}
-- Initialization Function (called once at each start of AI turn)
function ai_init()
	ai.suicide1=0
	ai.suicide2=0
	math.randomseed(os.time())
	ai.dir=0
	players=playertable(3,0)
	ai.bestplayer=0;
	ai.bestx=9999;
	ai.lx=getplayerx(0)
	for i=1,#players,1 do
		if (math.abs(getplayerx(players[i])-ai.lx)<ai.bestx) or (ai.bestplayer==0) then
			ai.bestplayer=players[i]
			ai.bestx=math.abs(getplayerx(players[i])-ai.lx)
		end
	end
	if (getplayerx(ai.bestplayer)-ai.lx)>0 then ai.dir=1 end
	ai.lx=666
end
-- Movement Function (called each frame, pre attack)
function ai_move()
	ai_weapon("Uppercut")
	if math.random(1,6)==3 then
		ai_weapon("Brain Punch")
	end
	if getplayerhealth(0)<=30 then
		ai_weapon("Explosive Belt")
	end
	if (math.abs(getplayerx(ai.bestplayer)-getplayerx(0))<16) and ((getplayery(ai.bestplayer)-getplayery(0))<10) and ((getplayery(ai.bestplayer)-getplayery(0))>(-28)) then
		if (getplayerx(ai.bestplayer)-ai.lx)>0 then ai_right() else ai_left() end
		ai_attack()
	else
		if ai.lx==getplayerx(0) then
			ai_backjump()
			ai.suicide1=ai.suicide1+1
		else
			if (ai.suicide1>0) then ai.suicide1=ai.suicide1-1 end
		end
		if (getplayery(0)>=(getwatery()-55)) then
			ai_jump()
		else
			if ai.dir==0 then
				ai_left()
			else
				ai_right()
			end
		end
	end
	ai.ldir=ai.dir
	ai.lx=getplayerx(0)
	if (getplayerx(ai.bestplayer)-ai.lx)>20 then ai.dir=1
	elseif (getplayerx(ai.bestplayer)-ai.lx)<-20 then ai.dir=0
	end
	if (ai.ldir~=ai.dir) then ai.suicide2=ai.suicide2+1 end
	if (ai.suicide1>20) or (ai.suicide2>5) then
		ai_weapon("Explosive Belt")
		ai.bestplayer=0
		ai.suicide1=0
		ai.suicide2=0
	end
end
-- Backing Function (called each frame, post attack)
function ai_back()
--do nothing
end