Ai sus! Very good fandango!
What are some of the random animations the duck will be playing while idle? Speaking of random animations it would probably be a good idea to add some kind of counter measure to check if duck is playing a random animation & have it wait until finished before resuming chase if character is already moving, no? I wonder if it's possible, will have to check the data structure.
* edit: according to data structure it's possible, as you can check animation state of characters which will return an integer value based on idle, talking, character, random animations. - I wonder why walking is not included in the list?
CharacterAnimState | t_int | Type of currently playing character animation:
'0': No animation.
'1': Individual character animation.
'2': Random animation.
'3': Talk animation.
'4': Standing animation.
here's the final revised script... (no promises that it's the final version mind).
--[[
Automated chase character handler (dynamic distance radius) [v4] (07/05/2015)
Written by AFRLme [Lee Clarke]
-- + --
afrlme@outlook.com | skype @ AFRLme
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]
-- * local variables * --
local distance = 250 -- radius from current character in pixels @ 100%
local chaser = Characters["duck"]
local temp_distance -- empty (will be used to calculate new distance based on current characters scale value)
-- * function that is used to start & stop character chasing * --
function quackers()
if game.CurrentCharacter.CharacterState == 3 and chaser.CharacterFollowCharacter ~= game.CurrentCharacter and chaser.CharacterAnimState ~= 2 then
if ActiveActions["end_chase"] ~= nil then stopAction(ActiveActions["end_chase"]) end
chaser.CharacterFollowCharacter = game.CurrentCharacter; chaser.CharacterFollowReachDistance = 0
elseif game.CurrentCharacter.CharacterState ~= 3 and not chaser.CharacterFollowCharacter:isEmpty() then
temp_distance = math.floor( (chaser.CharacterSize / 100) * distance)
chaser.CharacterFollowReachDistance = temp_distance; startAction("Actions[end_chase]")
end
end
registerEventHandler("mainLoop", "quackers") -- turns quackers function into a looping function
Please let me know if this works. It should automatically wait until idle animations have finished playing, so it might be an idea to only set your idle animations to play a limited amount of loops.