--wildlife script by smallg --how far to move (will keep moving until out of alert distance though) local move_amount = 1000 --how close the player can get before entity will notice him local alert_distance = 600 --delay (in seconds) between idle movements (set to 0 to skip this code) local delay = 5 --set to number of possible idle directions (note you will need to update the code yourself to change these) local idle_options = 5 ------- local time1 = {} local time2 = {} local timepassed = {} local x = {} local z = {} local rand = {} function wildlife_init(e) --get entity numbers if first_e == nil then first_e = e end last_e = e ------ x[e] = 0 z[e] = 0 rand[e] = 0 time1[e] = 0 time2[e] = 0 timepassed[e] = 0 end --init function wildlife_main(e) --setup the character so it can use the AI commands EntObjNo = g_Entity[e]['obj'] CharacterControlUnarmed(e) --check player range if GetPlayerDistance(e) >= alert_distance then SetCharacterToWalk(e) ModulateSpeed(e,1) --get timer for comparison with delay if time1[e] == 0 then time1[e] = g_Time --set initial waypoint to a random location nearby x[e] = g_Entity[e]['x'] + math.random(-move_amount,move_amount) z[e] = g_Entity[e]['z'] + math.random(-move_amount,move_amount) end time2[e] = g_Time timepassed[e] = time2[e] - time1[e] --if delay reached and idle animations/movement on if timepassed[e] / 1000 >= delay and delay > 0 then --move entity randomly --increase entity speed ModulateSpeed(e,1.3) math.randomseed( os.time() ) for a = first_e, last_e do rand[a] = math.random(idle_options) end --move right if rand[e] == 1 then x[e] = g_Entity[e]['x'] + move_amount --move left elseif rand[e] == 2 then x[e] = g_Entity[e]['x'] - move_amount --move up elseif rand[e] == 3 then z[e] = g_Entity[e]['z'] + move_amount --move down elseif rand[e] == 4 then z[e] = g_Entity[e]['z'] - move_amount --stay still elseif rand[e] == 5 then ModulateSpeed(e,1) CharacterControlStand(e) end --random movement --reset timer time1[e] = 0 end --time delay --if player in alert range else SetCharacterToRun(e) --compare position to player and adjust if g_PlayerPosX < g_Entity[e]['x'] then x[e] = g_Entity[e]['x'] + move_amount else x[e] = g_Entity[e]['x'] - move_amount end --entity vs player x if g_PlayerPosZ < g_Entity[e]['z'] then z[e] = g_Entity[e]['z'] + move_amount else z[e] = g_Entity[e]['z'] - move_amount end --entity vs player z end --alert range --move the entity AIEntityGoToPosition(EntObjNo,x[e],z[e]) end --main