-- DESCRIPTION: Add to an object to display that object's specified animation Start and End frames.
-- DESCRIPTION: Check the [RunAtStart!=0] box to activate Frame Finder Max at start.
-- DESCRIPTION: If unchecked, a logic connection is required to activate, like using a switch or a zone.
-- DESCRIPTION: Type the animation name in the [AnimationName$="Type Animation Name Here"] box.
-- DESCRIPTION: WARNING! - Type in the FULL ANIMATION NAME or the wrong frames may be displayed.
-- DESCRIPTION: Single letters or partial names will still allow the animation to play.
-- DESCRIPTION: But the frames for the correct animation will not be counted correctly.
-- DESCRIPTION: Run the test level and the animation Start and End frames will be counted and displayed on screen.
-- DESCRIPTION: -- Frame Finder Max v2.0 For GameGuru Max -- Script/Behavior By EyeFly (Chris Wilson) --
-- Scripted By: EyeFlyGS

local find_frames = {}
local start_frame = {}
local end_frame = {}
local play_anim = {}
local frame_grab = {}
local act_once = {}
local frame_finder_terminal = {}
local ff_terminal1 = {}
local ff_terminal2 = {}
local ff_terminal3 = {}
local ff_terminal4 = {}
local switch_delay = {}
local disp_info = {}
timer = {}

function frame_finder_max_properties(e, runatstart, animationname)
 find_frames[e]['runatstart'] = runatstart
 find_frames[e]['animationname'] = animationname
end

function frame_finder_max_init(e)
find_frames[e] = {}
find_frames[e]['runatstart'] = 0
start_frame[e] = 0
end_frame[e] = 0
play_anim[e] = 1
frame_grab[e] = 0
act_once[e] = 0
switch_delay[e] = 0
disp_info[e] = 0
frame_finder_terminal[e] = g_Entity[e]

    frame_finder_terminal[e]['terminal_image1'] = "scriptbank\\user\\images\\frame_finder_max\\ffs1.png"  
	ff_terminal1 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image1']))
	SetSpriteSize(ff_terminal1,100,100)  
	SetSpritePosition(ff_terminal1,200,200)
	
	frame_finder_terminal[e]['terminal_image2'] = "scriptbank\\user\\images\\frame_finder_max\\ffs2.png"  
	ff_terminal2 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image2']))
	SetSpriteSize(ff_terminal2,100,100)  
	SetSpritePosition(ff_terminal2,200,200)
	
	frame_finder_terminal[e]['terminal_image5'] = "scriptbank\\user\\images\\frame_finder_max\\ffs3.png"  
	ff_terminal5 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image5']))
	SetSpriteSize(ff_terminal5,100,100)  
	SetSpritePosition(ff_terminal5,200,200)
	
	frame_finder_terminal[e]['terminal_image6'] = "scriptbank\\user\\images\\frame_finder_max\\ffs4.png"  
	ff_terminal6 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image6']))
	SetSpriteSize(ff_terminal6,100,100)  
	SetSpritePosition(ff_terminal6,200,200)
	
	frame_finder_terminal[e]['terminal_image3'] = "scriptbank\\user\\images\\frame_finder_max\\fff.png"  
	ff_terminal3 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image3']))
	SetSpriteSize(ff_terminal3,100,100)  
	SetSpritePosition(ff_terminal3,200,200)
	
	frame_finder_terminal[e]['terminal_image4'] = "scriptbank\\user\\images\\frame_finder_max\\ffni.png"  
	ff_terminal4 = CreateSprite(LoadImage(frame_finder_terminal[e]['terminal_image4']))
	SetSpriteSize(ff_terminal4,100,100)  
	SetSpritePosition(ff_terminal4,200,200)
	
end
timer[1] = 0
function frame_finder_max_main(e)
  if GetAnimationSpeed (e) > 1 then
   SetAnimationSpeed(e,1)
   end
  if find_frames[e]['runatstart'] == 1 and act_once[e] == 0 then
   g_Entity[e]['activated'] = 1
 end
  if g_Entity[e]['activated'] == 1 and act_once[e] == 0 then
   disp_info[e] = 1
   act_once[e] = 1
 end
  if disp_info[e] == 1 then
  if frame_grab[e] == 1 then 
   start_frame[e] = GetAnimationFrame(e)
   frame_grab[e] = 2
 end
  if GetObjectAnimationFinished(e) == 1 and frame_grab[e] == 2 then
   end_frame[e] = GetAnimationFrame(e)

 end
  if g_Entity[e]['activated'] == 1 and play_anim[e] == 1 and GetEntityAnimationNameExist(e,find_frames[e]['animationname']) > 0 then
   SetAnimationName(e,find_frames[e]['animationname'])
   PlayAnimation(e)
   frame_grab[e] = 1
   play_anim[e] = 0
   SetActivated(e,0)
 end

  if GetObjectAnimationFinished(e) == 0 then
  if timer[1] == nil then
   timer[1] = g_Time + 75
  elseif g_Time > timer[1] then
   timer[1] = g_Time + 75
   switch_delay[e] = switch_delay[e] + 1
  if switch_delay[e] > 3 then
   switch_delay[e] = 0
 end
 end
  if GetObjectAnimationFinished(e) == 0 then
  if switch_delay[e] == 0 then
   PasteSpritePosition(ff_terminal1,0,0)
  else
  if switch_delay[e] == 1 then
   PasteSpritePosition(ff_terminal2,0,0)
  else
  if switch_delay[e] == 2 then
   PasteSpritePosition(ff_terminal5,0,0)
  else
  if switch_delay[e] == 3 then
   PasteSpritePosition(ff_terminal6,0,0)
 end
 end
 end
 end
 end
 end
  if GetEntityAnimationNameExist(e,find_frames[e]['animationname']) > 0 then
  if GetObjectAnimationFinished(e) == 1 then
   PasteSpritePosition(ff_terminal3,0,0)
 end
  else
   PasteSpritePosition(ff_terminal4,0,0)
 end
  if GetEntityAnimationNameExist(e,find_frames[e]['animationname']) > 0 then
  if GetObjectAnimationFinished(e) == 0 then
   TextCenterOnX(50,78,4,"Animation Name : " .."["..find_frames[e]['animationname'].."]" .." = VALID")
   TextCenterOnX(50,72.2,4,"Searching For Start And End Frames For Animation Name : " .."[" ..find_frames[e]['animationname'] .."]")
   TextCenterOnXColor(50,83.3,4,"Start Frame Found - " .."[" ..start_frame[e] .."]",0,255,0)
   TextCenterOnX(50,88.5,4,"Searching For End Frame " .."[" ..GetAnimationFrame(e) .."]".." - Counting Frames...")
   TextCenterOnXColor(50,65,5,"Please Wait... More Frames = Longer Wait Time",0,127,255)
 end
  if GetObjectAnimationFinished(e) == 1 then
   TextCenterOnX(50,72,4,"Found Frames For Animation Name : " .."[" ..find_frames[e]['animationname'] .."]")
   TextCenterOnXColor(50,76.5,5,"Start Frame Found - " .."[" ..start_frame[e] .."]",0,255,0)
   TextCenterOnXColor(50,83.5,5,"End Frame Found - " .."["..end_frame[e] .."]",0,255,0)
   TextCenterOnXColor(50,92.2,3,"- Press [ESC] To Exit -",0,127,255)
   TextCenterOnXColor(50,65,5,"Thanks For Waiting! Here's Your Frames!",0,127,255)
 end
  else
   TextCenterOnXColor(50,65,5,"Please Enter A VALID Name!",255,0,0)
   TextCenterOnX(42.9,72.2,4,"Sorry, Can't Search For Frames With that Animation Name : ")
   TextCenterOnXColor(72,72.2,4,"NAME NOT FOUND!",255,0,0)
   TextCenterOnX(50,77,4,"Animation Name : " .."["..find_frames[e]['animationname'].."]" .." = INVALID")
   TextCenterOnXColor(37,81.5,5,"ERROR",255,0,0)
   TextCenterOnX(54.5,81.5,5," - NO DATA FOUND!")
   TextCenterOnXColor(50,88.9,4,"- Press [ESC] To Exit -",255,0,0)
 end
   TextCenterOnX(50,94,4,"[".."Frame Finder Max v2.0 - A GGMax Dev-Tool Made By : EyeFly-G.S. - 2022-2023" .."]")
 end
end


