I've created a basic script to get animated fish to swim around, but it only works with one fish due to variable conflict. I tried using local variables, as well as using tables, but I failed due to scripting ineptness. Any help getting the script to work would be appreciated.
Here is the script:
function fish_swimming_init(e)
animating = 0
state = 0
rotangle = 0
end
function fish_swimming_main(e)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
state = math.random(2)
rotangle = math.random(-2000,2000)
if state == 1 and animating == 0 then
RotateY(e,rotangle)
SetAnimation(1)
PlayAnimation(e)
animating = 1
elseif animating == 0 then
RotateY(e,rotangle)
SetAnimation(2)
PlayAnimation(e)
animating = 1
end
if GetAnimationFrame(e) == 1000 or GetAnimationFrame(e) == 20000 then
SetAnimationFrame(e,0)
animating = 0
end