local chat_angle = {} local chat_range = {} local max_chat_sounds = {} local sound_num = {} local freeze = {} local frozen = {} local played = {} local reset_on_leave = {} --load all the global sounds here first LoadGlobalSound("audiobank\\globalsounds\\sound1.wav",1) LoadGlobalSound("audiobank\\globalsounds\\sound2.wav",2) LoadGlobalSound("audiobank\\globalsounds\\sound3.wav",3) LoadGlobalSound("audiobank\\globalsounds\\sound4.wav",4) function ai_conversation_init(e) max_chat_sounds[e] = 4 --maximum number of sounds to play chat_range[e] = 150 --range when to start the conversation chat_angle[e] = 35 --angle player needs to be facing to start conversation freeze[e] = 1 --toggle freezing the player in place for the conversation or not reset_on_leave[e] = 1 --toggle wether the conversation can be replayed if player leaves and comes back frozen[e] = 0 sound_num[e] = 1 played[sound_num[e]] = 0 end function ai_conversation_main(e) if GetPlayerDistance(e) <= chat_range[e]*1.5 then RotateToPlayer(e) LookAtPlayer(e) end if PlayerLooking(e,chat_range[e],chat_angle[e]) == 1 then if sound_num[e] <= max_chat_sounds[e] then if freeze[e] == 1 and frozen[e] == 0 then FreezePlayer() frozen[e] = 1 end if GetGlobalSoundPlaying(sound_num[e]) == 0 and played[sound_num[e]] == 0 then PlayGlobalSound(sound_num[e]) played[sound_num[e]] = 1 elseif GetGlobalSoundPlaying(sound_num[e]) == 0 then sound_num[e] = sound_num[e] + 1 played[sound_num[e]] = 0 end elseif PlayerLooking(e,chat_range[e]*1.5,chat_angle[e]*1.5) == 1 and freeze[e] == 1 and frozen[e] == 1 then UnFreezePlayer() frozen[e] = 0 end elseif reset_on_leave[e] == 1 then sound_num[e] = 1 played[sound_num[e]] = 0 end end function ai_conversation_exit(e) LoadGlobalSound("audiobank\\globalsounds\\Ogre.wav",5) PlayGlobalSound(5) end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end