-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Default script - does nothing. local idle = {} local alert = {} local charging = {} local idlecomplete = {} local idlechoice = {} local state = {} local state2 = {} local timer = {} local started = {} local walking = {} local grazing = {} local xpos = {} local ypos = {} local zpos = {} local setpos = {} local aggressive = {} local animationcomplete = {} local attacking = {} local alerted = {} local threatening = {} local xpos = {} local zpos = {} local ypos = {} local buffaloHealth = {} function buffalo_follower_init(e) idle[e] = 0 alert[e] = 0 charging[e] = 0 idlecomplete[e] = 0 idlechoice[e] = 0 state[e] = "relaxed" state2[e] = "walking" timer[e] = 0 started[e] = 0 walking[e] = 0 grazing[e] = 0 xpos[e] = 0 ypos[e] = 0 zpos[e] = 0 setpos[e] = 0 aggressive[e] = 0 animationcomplete[e] = 0 attacking[e] = 0 alerted[e] = 0 threatening[e] = 0 xpos[e] = g_Entity[e]['x'] zpos[e] = g_Entity[e]['z'] ypos[e] = g_Entity[e]['y'] buffaloHealth[e] = g_Entity[e]['health'] leader = 1 end function buffalo_follower_main(e) EntObjNo = g_Entity[e]['obj'] if GetAnimationFrame(e) == 130 then PlaySound(e,0) end if GetAnimationFrame(e) == 480 then PlaySound(e,1) end if aggressive[e] == 0 and state2[e] == "walking" and GetDistance(e,leader) > 300 then RotateToPointSlowly(e,g_Entity[leader]['x'],g_Entity[leader]['z'],1) end --Prompt(buffaloHealth[e].." "..g_Entity[e]['health'].." "..aggressive[e].." "..state[e]) --Prompt(GetPlayerDistance(e).." "..state[e].." Animcomplete-"..animationcomplete[e].." threat-"..threatening[e].." Aggressive-"..aggressive[e]) if GetPlayerDistance(e)<500 then aggressive[e] = 1 end if g_Entity[e]['health'] < buffaloHealth[e] then aggressive[e] = 1 end if aggressive[e] == 0 then if GetPlayerDistance(e) > 1000 and alerted[e] == 0 then if state[e] ~="idle" then g_Entity[e]['animating'] = 0 state[e] ="idle" end idle[e] = 1 alert[e] = 0 charging[e] = 0 attacking[e] = 0 elseif GetPlayerDistance(e) > 1000 and alerted[e] == 1 then if state[e] ~="alert" then g_Entity[e]['animating'] = 0 state[e] ="alert" end idle[e] = 0 alert[e] = 1 charging[e] = 0 attacking[e] = 0 alerted[e] = 1 elseif GetPlayerDistance(e) < 1000 then if state[e] ~="alert" then g_Entity[e]['animating'] = 0 state[e] ="alert" end idle[e] = 0 alert[e] = 1 charging[e] = 0 attacking[e] = 0 alerted[e] = 1 end end if aggressive[e] == 1 then if GetPlayerDistance(e) > 100 and animationcomplete[e] == 1 then if state[e] ~="charging" then g_Entity[e]['animating'] = 0 state[e] ="charging" end alert[e] = 0 charging[e] = 1 idle[e] = 0 attacking[e] = 0 elseif GetPlayerDistance(e) < 100 then if state[e] ~="attacking" then g_Entity[e]['animating'] = 0 state[e] ="attacking" end alert[e] = 0 charging[e] = 0 idle[e] = 0 attacking[e] = 1 elseif g_Entity[e]['health'] < buffaloHealth[e] then if state[e] ~="charging" then g_Entity[e]['animating'] = 0 state[e] ="charging" end alert[e] = 0 charging[e] = 1 idle[e] = 0 attacking[e] = 0 end end if alert[e] == 1 then if threatening[e] == 0 then CharacterControlLimbo(e) ModulateSpeed(e,1.5) MoveForward(e,40) RotateToPlayerSlowly(e,3) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(5,104) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if started[e] == 0 then timer[e] = GetTimer(e) started[e] = 1 end if GetTimer(e)-timer[e] > 10000 and GetPlayerDistance(e) < 1200 and animationcomplete[e] == 1 then threatening[e] = 1 started[e] = 0 StopAnimation(e) elseif GetTimer(e)-timer[e] > 10000 and GetPlayerDistance(e) > 1200 and animationcomplete[e] == 1 then alerted[e] = 0 started[e] = 0 end if GetAnimationFrame(e) > 100 then animationcomplete[e] = 1 end if GetAnimationFrame(e) < 10 then animationcomplete[e] = 0 end end if threatening[e] == 1 then CharacterControlLimbo(e) ModulateSpeed(e,1) RotateToPlayerSlowly(e,1) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(480,580) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if started[e] == 0 then timer[e] = GetTimer(e) started[e] = 1 end if GetTimer(e)-timer[e] > 5000 and GetPlayerDistance(e) < 1200 and animationcomplete[e] == 1 then aggressive[e] = 1 started[e] = 0 elseif GetTimer(e)-timer[e] > 5000 and GetPlayerDistance(e) > 1200 and animationcomplete[e] == 1 then aggressive[e] = 0 started[e] = 0 end if GetAnimationFrame(e) > 575 then animationcomplete[e] = 1 end if GetAnimationFrame(e) < 485 then animationcomplete[e] = 0 end end end if idle[e] == 1 then CharacterControlLimbo(e) ModulateSpeed(e,1.5) if idlecomplete[e] == 1 then idlechoice[e] = math.random(0,1) idlecomplete[e] = 0 end if idlechoice[e] == 0 then if state2[e] ~= "grazing" then g_Entity[e]['animating'] = 0 state2[e] = "grazing" end walking[e] = 0 grazing[e] = 1 elseif idlechoice[e] == 1 then if state2[e] ~= "walking" then g_Entity[e]['animating'] = 0 state2[e] = "walking" end walking[e] = 1 grazing[e] = 0 end if walking[e] == 1 then if started[e] == 0 then timer[e] = GetTimer(e) started[e] = 1 end if GetTimer(e)-timer[e] > 10000 then idlecomplete[e] = 1 started[e] = 0 end MoveForward(e,30) ModulateSpeed(e,1.5) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(5,104) PlayAnimation(e) g_Entity[e]['animating'] = 1 end end if grazing[e] == 1 then if started[e] == 0 then timer[e] = GetTimer(e) started[e] = 1 end if GetTimer(e)-timer[e] > 10000 then idlecomplete[e] = 1 started[e] = 0 end ModulateSpeed(e,1) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(220,410) PlayAnimation(e) g_Entity[e]['animating'] = 1 end end end if charging[e] == 1 then --using custom controls CharacterControlLimbo(e) RotateToPlayerSlowly(e,7) MoveForward(e,260) ModulateSpeed(e,1.7) SetAnimationSpeed(e,1) --Using character controls --ModulateSpeed(e,1.7) --SetCharacterToRun(e) --CharacterControlUnarmed(e) --rndx=math.random(1,360) --rndz=math.random(1,360) --rndx2=math.sin(rndx)*10 --rndz2=math.cos(rndz)*10 --AIEntityGoToPosition(EntObjNo,g_PlayerPosX+rndx2,g_PlayerPosZ+rndz2) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(110,170) PlayAnimation(e) g_Entity[e]['animating'] = 1 end end if attacking[e] == 1 then CharacterControlLimbo(e) ModulateSpeed(e,1) if GetPlayerDistance(e) >90 then MoveForward(e,200) end RotateToPlayer(e) if g_Entity[e]['animating'] == 0 then SetAnimationFrames(685,745) PlayAnimation(e) g_Entity[e]['animating'] = 1 end if GetPlayerDistance(e) < 100 and (GetAnimationFrame(e) == 700 or GetAnimationFrame(e) == 720) then HurtPlayer(e,10) PlaySound(e,2) end if GetAnimationFrame(e) > 740 then animationcomplete[e] = 1 end if GetAnimationFrame(e) < 690 then animationcomplete[e] = 0 end end if g_PlayerHealth < 1 then buffalo_init(e) end end function buffalo_exit(e) ModulateSpeed(e,1.0) CharacterControlLimbo(e) SetAnimationFrames(750,800) PlayAnimation(e) StopSound(e) end function GetDistance(e,v) if g_Entity[e] ~= nil and g_Entity[e] ~= 0 and g_Entity[v] ~= nil and g_Entity[v] ~= 0 then local disx = g_Entity[e]['x'] - g_Entity[v]['x'] local disz = g_Entity[e]['z'] - g_Entity[v]['z'] return math.sqrt(disx^2 + disz^2) end end