g_herd_list = {} g_herd_name = {} function herd_leader_init_name(e,name) g_herd_name[e] = {name = name, leader = e} CharacterControlUnarmed(e) end function herd_leader_main(e) if not scheduler(e) then return end local Entity = g_Entity[e] if g_herd_list[e] == nil then g_herd_list[e] = {Leader = true, TargX = 0, TargZ = 0, State = 0, -- 0=wander, 1=relaxed/graze, 2=flee Ctime = 0, Moving = false}; CharacterControlDucked(e) Entity.timer = 0 end local Entity = g_Entity[e] local HL = g_herd_list[e] local eX, eZ = Entity.x, Entity.z local EntObjNo = Entity.obj; local gtime = g_Time local etime = gtime - Entity.timer local dist = 0 if HL.Ctime == 0 then HL.Ctime = math.random(12000, 18000) Entity.timer = gtime return -- if we can't get to our target within 30 seconds reset elseif etime > 30000 then Entity.timer = gtime HL.Moving = false end if not HL.Moving and etime > HL.Ctime then HL.TargX, HL.TargZ = RandomPos(eX, eZ, math.random (300, 900)) CharacterControlStand(e) SetCharacterToWalk(e) AIEntityGoToPosition(EntObjNo, HL.TargX, HL.TargZ) Entity.timer = gtime HL.Moving = true elseif HL.Moving then local DX, DZ = eX - HL.TargX, eZ - HL.TargZ dist = (DX*DX) + (DZ*DZ) if dist < 6000 then HL.Moving = false Entity.timer = gtime HL.Ctime = 0 HL.State = 1 AIEntityStop(EntObjNo); if math.random(1, 8) ~= 1 then CharacterControlDucked(e) else CharacterControlStand(e) end end end if PlayerCloserThan(e, 800) then if HL.State ~= 2 then HL.State = 2 -- flee HL.TargX, HL.TargZ = AIFleePos (Entity, 1600) AIEntityStop(EntObjNo); CharacterControlStand(e) SetCharacterToRun(e) AIEntityGoToPosition(EntObjNo, HL.TargX, HL.TargZ) HL.Moving = true Entity.timer = gtime HL.Ctime = 0 elseif HL.Moving then AIEntityGoToPosition(EntObjNo, HL.TargX, HL.TargZ) end end -- if HL ~= nil then -- local moving = "False" -- if HL.Moving then moving = "True" end -- PromptLocal(e, "State=" .. HL.State .. -- ", Mvg=" .. moving .. -- ", TMR=" .. HL.Ctime .. ", E=" .. etime); -- end end