I want to have multiple enemies that will animate and attack me when i get to close. I have written a very long function that worked for one enemy, but when i put two in, they did not work right because the variable's i'm using (for detecting my presence, for changing animations, etc.) are the same for both enemies. I know i could just type out individual functions for each enemy, but i plan to have 10's, or 100's, of enemies in the game at once (their low graphic models). How would i right a function that used individual variables for each enemy automatically? The code is the Function for controlling my AI (sorry if it's low quality...I'm new). To make sure its clear, this code works perfect for 1 enemy.
Rem N=number of enemies. Its definded in the main loop
function enemy(N)
x#=N
cx#=camera position x()
cy#=camera position y()
cz#=camera position z()
dist#=(sqrt((object position x(x#)-object position x(3))^2+(object position y(x#)-object position y(3))^2+(object position z(x#)-object position z(3))^2))-10
if dist#<100
EnemyDetect#=1
if dist#<10
EnemyDetect#=2
endif
else
EnemyDetect#=0
endif
set cursor 1,300
print dist#
if EnemyDetect#=2
point object x#,cx#,cy#,cz#
if Attack#<1 and EnemyDetect#=2
Play object x#,150,175
loop object x#,150,175
set object speed x#,10
Attack#=1
endif
Move#=0
Idle#=0
endif
if EnemyDetect#=1
point object x#,cx#,cy#,cz#
if Move#<1 and EnemyDetect#=1
Play object x#,100,125
loop object x#,105,125
set object speed x#,5
Move#=1
endif
move object x#,1
Idle#=0
Attack#=0
endif
if EnemyDetect#=0
If Idle#<1 and EnemyDetect#=0
Play object x#,50,75
Loop object x#,59,75
set object speed x#,1
Idle#=1
endif
Move#=0
Attack#=0
endif
Ox#=object position x(x#)
Oz#=object position z(x#)
Oy#=get ground height(1,Ox#,Oz#)
position object x#,Ox#,Oy#,Oz#
if object hit(x#,0)>0
dec Ox#,get object collision x()
dec Oy#,get object collision y()
dec Oz#,get object collision z()
endif
position object x#,Ox#,Oy#,Oz#
endfunction