I saw this youtube video so I’m writing this module that does something similar to what this programmer is doing in this video. I want to post it here to provide inspiration and resources to other developers. I have updated it on 8/20/2023,8/21/2023,8/28/2023,11/30/2023
This is the newest version!! The code below is the old version
(1) AwarenessV2 - Roblox
local aware = {}
local chatmodule=require(script.Parent.ChatModule)
local personalities=require(script.Parent.Personalities)
local interchangephrase={{"and their are","and their is"},}
syntheticdatasynonms={
{"very close","quite close","extremely close"},
{"close","near","not far"},
{"kind of close","pretty near","somewhat near"},
{" tiny "," mini "," minuscule "},
{" small "," little "," petite "},
{" large "," big ","huge"},
{"gigantic","colossal","massive"},
{"a few","some","a couple"},
{"many","numerous","several"},
{"lots of","tons of","a good number of"},
{"There is","Over there is"},
{"I see","I can see"},
{"Nearby is","Close by is"},
{"Additionally","Furthermore","Moreover"},
{"Also","In addition","Plus"},
{"However","But","Though"},
{"to the north","northward","to the northern side."},
{"to the south","southward","to the southern area"},
{"to the east","eastward","to the eastern side"},
{"to the west","westward","to the western side"},
{"and their is"
,"and their exists","and their lies","and their stands","and their remains","and their reside","and their resides"},
{"Their is"
,"Their exists","Their lies","Their stands","Their remains","Their reside","Their resides"},
{"to the current position"}
}
ticktime=workspace.GlobalSpells.Tick
local function tablehandler(location)
-- Get the folder from the workspace
local tableobj={}
local mapObjectsFolder = location
local result=mapObjectsFolder:GetChildren()
return result
end
-- Call the function and assign it to a variable
--ticks=.6 seconds 100 ticks=60seconds 100ticks =1min
tablekeys={
["mapobject"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=200}, workspace.MapObjects},
["plants"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=300}, workspace.Plants},
["enemys"]={{["datatable"]=nil, ["writetime0]"]=ticktime.Value, ["refreshrate"]=100}, workspace.Enemys},
["rubble"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=200}, workspace.Rubble},
["trees"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=600}, workspace.Trees},
["chests"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=300}, workspace.Chests},
["grounditems"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=100}, workspace.GroundItems},
["houses"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=500}, workspace.Houses},
["players"]={{["datatable"]=nil, ["writetime"]=ticktime.Value, ["refreshrate"]=100}, game.Players},
["dungeons"]={{["datatable"]=nil,["writetime"]=ticktime.Value, ["refreshrate"]=100}, workspace.AmbientAreas},
["npcs"]={{["datatable"]=nil, ["writetime"]=ticktime.Value,["refreshrate"]=100}, workspace.NPCS}
}
--aware.Gettable(Key)
function aware.Gettable(Key)
if tablekeys[Key] then
local results,location=tablekeys[Key][1],tablekeys[Key][2]
local timer=results["writetime"]
local refresh=results["refreshrate"]
local data=results["datatable"]
if timer+refresh<ticktime.Value and data~=nil then
return results["datatable"]
else
tablekeys[Key]={{["datatable"]=tablehandler(location), ["writetime"]=ticktime.Value,["refreshrate"]=refresh},location}
return tablekeys[Key][1]["datatable"]
end
else
return nil
end
end
function getnearest(list,root,dist,getone,mode)
local list=list
local pos=root.Position
local torso = nil
local dist = 30
local temp = nil
local human = nil
local temp2 = nil
local amnt=0
local scope=nil
local list=list
if list~=nil then
for x = 1, #list do
temp2 = list[x]
if temp2==root.Parent then
temp=nil
elseif temp2:IsA("BasePart") then
temp = temp2
elseif temp2:IsA("Model") then
if temp2.PrimaryPart~=nil then
temp=temp2.PrimaryPart
else
temp=temp2:FindFirstChildOfClass("BasePart")
end
elseif temp2:IsA("Player") then
temp=temp2.Character:FindFirstChild("HumanoidRootPart")
elseif temp2:IsA("Folder") then
local m=temp2:FindFirstChildOfClass("Model")
if m then
temp=m:FindFirstChildOfClass("BasePart")
end
end
if (temp ~= nil and root~=temp) then
if (temp.Position - pos).magnitude < dist then
amnt=amnt+1
if mode then torso=temp else torso = temp2 end
dist = (temp.Position - pos).magnitude
scope = temp.Size
if getone==true then
return torso,scope
end
end
end
end
end
return torso,amnt,scope
end
function aware.nearrubble(root,dist,getone)
rubble = aware.Gettable("rubble")
return getnearest(rubble,root,dist,getone,true)
end
function aware.nearplant(root,dist,getone)
plants = aware.Gettable("plants")
return getnearest(plants,root,dist,getone,true)
end
function aware.neartree(root,dist,getone)
trees = aware.Gettable("trees")
return getnearest(trees,root,dist,getone,true)
end
function aware.nearhouse(root,dist,getone)
houses = aware.Gettable("houses")
return getnearest(houses,root,dist,getone,true)
end
function aware.neardungeons(root,dist,getone)
dungeons = aware.Gettable("dungeons")
return getnearest(dungeons,root,dist,getone,true)
end
function aware.nearchest(root,dist,getone)
chests = aware.Gettable("chests")
return getnearest(chests,root,dist,getone,true)
end
function aware.nearmapobj(root,dist,getone)
mapObjects = aware.Gettable("mapobject")
return getnearest(mapObjects,root,dist,getone,true)
end
function aware.nearloot(root,dist,getone)
grounditems = aware.Gettable("grounditems")
return getnearest(grounditems,root,dist,getone,true)
end
function aware.nearNPC(root,dist,getone)
npcs = aware.Gettable("npcs")
return getnearest(npcs,root,dist,getone,true)
end
function aware.nearEnemy(root,dist,getone)
enemys = aware.Gettable("enemys")
return getnearest(enemys,root,dist,getone,true)
end
function aware.nearplayer(root,dist,getone)
playerstable = aware.Gettable("players")
return getnearest(playerstable,root,dist,getone,true)
end
function aware.judgedistance(position, position2, maxDist)
local distVector = (position - position2).Magnitude
local judgedDist = {0.2, 0.4, 0.6, 0.8, 1, 1.5, 2}
local judgeStrings = {{"very close"}, {"close"}, {"kind of close"},{"not far"}, {"kinda far"}, {"far"}, {"very far"}}
local index = 1
local distanceJudge = ""
repeat
if distVector <= maxDist * judgedDist[index] then
if distVector>1 then
distanceJudge = judgeStrings[index][1]
else
distanceJudge="right here"
end
break
end
index = index + 1
until index > #judgedDist
-- Get direction
local dirVector = (position2 - position).Unit -- Unit vector pointing to position2
local angle = math.atan2(dirVector.Z, dirVector.X) -- Angle in radians
local dirName = ""
if distanceJudge~="right here" then
if angle > math.rad(157.5) or angle < math.rad(-157.5) then
dirName = "south"
elseif angle > math.rad(112.5) then
dirName = "southwest"
elseif angle > math.rad(67.5) then
dirName = "west"
elseif angle > math.rad(22.5) then
dirName = "northwest"
elseif angle > math.rad(-22.5) then
dirName = "north"
elseif angle > math.rad(-67.5) then
dirName = "northeast"
elseif angle > math.rad(-112.5) then
dirName = "east"
else
dirName = "southeast"
end
else dirName = "current position."
end
return distanceJudge,dirName
end
function aware.judgeamnt(amnt,judgestrings)
local judgedistribution={1,2,3,4,5,6,8}
local judgestrings={{"a single"},{"a couple"},{"a few"},{"a quartet"},{"several"},{"a bunch"},{"a lot"}}
local index=1
repeat
local distvector=amnt
if distvector<=judgedistribution[index] then
return judgestrings[index][1]
end
until index>=#judgedistribution
end
function aware.judgething(size, bigSize,judgeSizes,judgeStrings)
local index = 1
local sizeJudge = ""
if typeof(size)=="Vector3" then
for i, judge in ipairs(judgeSizes) do
if size <= bigSize * judge then
local sizeJudge2 = judgeStrings[i]
sizeJudge=sizeJudge2[math.random(1,#sizeJudge)]
break
end
end
end
return sizeJudge
end
function aware.getsurroundingobjects(root,player)
local closestPlant, numPlants,plantsize = getnearest(plants, root, 40)
local closestTree, numTrees = getnearest(trees, root, 80)
local closestStructure, numStructures,structuresize = getnearest(mapObjects, root, 160)
local closestEnemy, numEnemies = getnearest(enemys, root, 60)
local closestNPC, numNPCs = getnearest(npcs, root, 60)
local closestPlayer, numPlayers = getnearest(playerstable, root, 80)
local closestRubble, numRubble = getnearest(rubble, root, 20)
local closestChest, numChests = getnearest(chests, root, 30)
local closestGroundItem, numGroundItems = getnearest(grounditems, root, 40)
local closestHouse, numHouses,housesize = getnearest(houses, root, 100)
local closestDungeon, numDungeons,dungsize = getnearest(dungeons, root, 200)
local pos=root.Position
local function describeTrees()
if numTrees > 1 then
local treeText
treeText= aware.judgeamnt(numTrees).." of trees surround the area"
return treeText
end
end
local function describePlants()
if numPlants > 1 then
local plantText = aware.judgeamnt(numPlants).." of plants are scattered around"
return plantText
end
end
local function describeRubble()
if numRubble > 1 then
local rubbleText = aware.judgeamnt(numRubble).." of pieces of rubble lay on the ground"
return rubbleText
end
end
local function describeEnemies()
if numEnemies > 1 then
local enemyText = aware.judgeamnt(numEnemies).." of enemies are lurking nearby"
return enemyText
end
end
local function describeNPCs()
if numNPCs > 1 then
local npcText = aware.judgeamnt(numNPCs).." of strangers are in the area"
return npcText
end
end
local function describePlayers()
if numPlayers > 1 then
local playerText = aware.judgeamnt(numPlayers).." of players are nearby"
return playerText
end
end
local function describeChests()
if numChests > 1 then
local chestText = aware.judgeamnt(numChests).." of chests are scattered around"
return chestText
end
end
local function describeGroundItems()
if numGroundItems > 1 then
local groundItemText = aware.judgeamnt(numGroundItems).." of items lay on the ground"
return groundItemText
end
end
local function describeHouses()
if numHouses > 1 then
local houseText = aware.judgeamnt(numHouses).." of houses stand nearby"
return houseText
end
end
local function describeDungeons()
local dungeonText = ""
if numDungeons > 1 then
local dungeonText = aware.judgeamnt(numDungeons).." of areas around here."
return dungeonText
end
end
local function describestructures()
if numStructures > 1 then
local structureText = aware.judgeamnt(numDungeons).." of interesting places to check out around here."
return structureText
end
end
local function describeSurroundings(pos)
local descStrings = {}
local opener={"Their are ","I see ","Surrounding us are "}
local descTrees = describeTrees()
local descPlants = describePlants()
local descRubble = describeRubble()
local descEnemies = describeEnemies()
local descNPCs = describeNPCs()
local descPlayers = describePlayers()
local descChests = describeChests()
local descGroundItems = describeGroundItems()
local descHouses = describeHouses()
local descDungeons = describeDungeons()
if descTrees then
table.insert(descStrings, ""..descTrees)
end
if descPlants then
table.insert(descStrings, ""..descPlants)
end
if descRubble then
table.insert(descStrings, ""..descRubble)
end
if descEnemies then
table.insert(descStrings, ""..descEnemies)
end
if descNPCs then
table.insert(descStrings, ""..descNPCs)
end
if descPlayers then
table.insert(descStrings, ""..descPlayers)
end
if descChests then
table.insert(descStrings, ""..descChests)
end
if descGroundItems then
table.insert(descStrings, ""..descGroundItems)
end
if descHouses then
table.insert(descStrings, ""..descHouses)
end
if descDungeons then
table.insert(descStrings, ""..descDungeons)
end
-- Remove any nil values
local finalStrings = {}
local paragraphstring=""
for i,str in ipairs(descStrings) do
if str ~= "" then
--table.insert(finalStrings, opener[math.random(1,#opener)]..str..".")
paragraphstring=paragraphstring..str..", "
end
end
if paragraphstring~="" then
paragraphstring=opener[math.random(1,#opener)]..paragraphstring.."."
table.insert(finalStrings,paragraphstring)
end
-- Join the strings together
return finalStrings
end
local function describeSurroundings2(pos)
local function describeRubble2(context)
local rubbleText = ""
if closestRubble then
if closestRubble:IsA("BasePart") then
local dist, dir = aware.judgedistance(pos, closestRubble.Position, 20)
local size = aware.judgesize(closestRubble.Size,Vector3.new(40,40,40))
rubbleText = "piece of " ..size.. " rubble is " ..dist.. " to the " ..dir
end
end
if numRubble > 1 then
if context==nil then
return rubbleText,aware.judgeamnt(numRubble).. " of pieces of rubble lay on the ground"
else
rubbleText = rubbleText .. context.. aware.judgeamnt(numRubble).. " of pieces of rubble lay on the ground"
end
end
return rubbleText
end
local function describeChests2(context)
local chestText = ""
if closestChest then
local dist, dir = aware.judgedistance(pos, closestChest.PrimaryPart.Position, 30)
--local size = aware.judgesize(closestChest.Size)
chestText = "chest is " ..dist.. " to the " ..dir
end
if numChests > 1 then
if context==nil then
return chestText,aware.judgeamnt(numChests).." of chests are scattered around"
else
chestText = chestText .. context .. aware.judgeamnt(numChests).." of chests are scattered around"
end
end
return chestText
end
local function describeGroundItems2(context)
local groundItemText = ""
if closestGroundItem then
local dist, dir = aware.judgedistance(pos, closestGroundItem.Item:FindFirstChildOfClass("BasePart").Position, 40)
-- local size = aware.judgesize(closestGroundItem.Size,Vector3.new(40,40,40))
groundItemText = aware.judgeobject(closestGroundItem)" is " ..dist.. " to the " ..dir
end
if numGroundItems > 1 then
if context==nil then
return groundItemText,aware.judgeamnt(numGroundItems).." of items lay on the ground"
else
groundItemText = groundItemText .. context .. aware.judgeamnt(numGroundItems).." of items lay on the ground"
end
end
return groundItemText
end
local function describeHouses2(context)
local houseText = ""
if closestHouse then
local dist, dir = aware.judgedistance(pos, closestHouse.Position, 100)
local size = aware.judgesize(closestHouse.PrimaryPart.Size,Vector3.new(100,100,100))
houseText = "" ..size.. " house is " ..dist.. " to the " ..dir
end
if numHouses > 1 then
if context==nil then
return houseText,aware.judgeamnt(numHouses).." of other houses stand nearby"
else
houseText = houseText .. context .. aware.judgeamnt(numHouses).." of other houses stand nearby"
end
end
return houseText
end
local function describestructures2(context)
local dungeonText=""
if closestStructure then
local dist, dir = aware.judgedistance(pos, closestStructure.PrimaryPart.Position, 200)
local size = aware.judgesize(closestStructure.PrimaryPart.Size,Vector3.new(200,100,200))
dungeonText = aware.judgeobject(closestStructure).." is "..dist.. " to the " ..dir
end
if numStructures > 1 then
if context==nil then
return dungeonText,aware.judgeamnt(numStructures)" of interesting places to check out around here"
else
dungeonText = dungeonText .. context..aware.judgeamnt(numStructures)" of interesting places to check out around here"
end
end
return dungeonText
end
local function describeDungeons2(context)
local dungeonText = ""
if closestDungeon then
local dist, dir = aware.judgedistance(pos, closestDungeon:FindFirstChildOfClass("BasePart").Position, 200)
local size = aware.judgesize(closestDungeon:FindFirstChildOfClass("BasePart").Size,Vector3.new(360,20,360))
dungeonText = aware.judgeobject(closestDungeon).." is "..dist.. " to the " ..dir
end
if numDungeons > 1 then
if context==nil then
return dungeonText,aware.judgeamnt(numDungeons)" of areas around here"
else
dungeonText = dungeonText .. context..aware.judgeamnt(numDungeons)" of areas around here"
end
end
return dungeonText
end
local function describeTrees2(context)
local treeText = ""
if closestTree then
local dist, dir = aware.judgedistance(pos, closestTree.PrimaryPart.Position, 160)
treeText = aware.judgeobject(closestTree).." is " ..dist.. " to the " ..dir
end
if numTrees > 1 then
if context==nil then
return treeText, aware.judgeamnt(numTrees).." of other trees surround the area"
else
treeText = treeText ..context.. aware.judgeamnt(numTrees).." of other trees surround the area"
end
end
return treeText
end
local function describePlants2(context)
local plantText = ""
if closestPlant then
local dist, dir = aware.judgedistance(pos, closestPlant.Position, 40)
local size = aware.judgesize(closestPlant.Size,Vector3.new(6,10,6))
plantText =size.. " "..aware.judgeobject(closestPlant).." is " ..dist.. " to the " ..dir
end
if numPlants > 1 then
if context==nil then
return plantText, aware.judgeamnt(numPlants).." of other plants are scattered around"
else
plantText = plantText ..context.. aware.judgeamnt(numPlants).." of other plants are scattered around"
end
end
return plantText
end
local function describeEnemies2(context)
local enemyText = ""
if closestEnemy then
local dist, dir = aware.judgedistance(pos, closestEnemy.HumanoidRootPart.Position, 60)
enemyText = aware.judgeobject(closestEnemy,root.Parent).. " is " ..dist.. " to the " ..dir
end
if numEnemies > 1 then
if context==nil then
return enemyText,aware.judgeamnt(numEnemies).." enemies are lurking nearby"
else
enemyText = enemyText ..context.. aware.judgeamnt(numEnemies).." enemies are lurking nearby"
end
end
return enemyText
end
local function describePlayers2(context)
local enemyText = ""
if closestPlayer and closestPlayer~=player then
local dist, dir = aware.judgedistance(pos, closestPlayer.Character.HumanoidRootPart.Position, 80)
enemyText = aware.judgeobject(closestPlayer,game.Players:GetPlayerFromCharacter(root.Parent)).. " is " ..dist.. " to the " ..dir
elseif closestPlayer~=nil and closestPlayer==player then enemyText="I can see you right here"
end
if numPlayers > 1 then
if context==nil then
return enemyText,aware.judgeamnt(numPlayers).." of players are nearby"
else
enemyText = enemyText ..context.. aware.judgeamnt(numPlayers).." of players are nearby"
end
end
return enemyText
end
local function describeNPCs2(context)
local npcText = ""
if closestNPC then
local dist, dir = aware.judgedistance(pos, closestNPC.HumanoidRootPart.Position, 80)
npcText = aware.judgeobject(closestNPC,root.Parent)..
" is " ..dist.. " to the "
..dir
end
if numNPCs > 1 then
if context==nil then
return npcText,aware.judgeamnt(numNPCs).." of strangers are in the area"
else
npcText = npcText ..context.. aware.judgeamnt(numNPCs).." strangers are in the area"
end
end
return npcText
end
local descStrings = {}
local opener={"I can see that, ","I notice that, ","I observe that, ","It is apparent that, "}
local descTrees2 = describeTrees2(", and their are ")
local descPlants2 = describePlants2(", and their are ")
local descRubble2 = describeRubble2(", and their are ")
local descEnemies2 = describeEnemies2(", and their are ")
local descNPCs2 = describeNPCs2(", and their are ")
local descPlayers2 = describePlayers2(", and their are ")
local descChests2 = describeChests2(", and their are ")
local descGroundItems2 = describeGroundItems2(", and their are ")
local descHouses2 = describeHouses2(", and their are ")
local descDungeons2 = describeDungeons2(", and their are ")
if root.Parent:FindFirstChild("Humanoid") then
local Person=root.Parent.Humanoid.DisplayName
local selfrecognition= "I am "..Person.."."
local Greetings=personalities.CallPersonality(Person)
table.insert(descStrings, selfrecognition)
end
if descTrees2~="" then
table.insert(descStrings, ""..descTrees2)
end
if descPlants2~="" then
table.insert(descStrings, ""..descPlants2)
end
if descRubble2~="" then
table.insert(descStrings, ""..descRubble2)
end
if descEnemies2~="" then
table.insert(descStrings, ""..descEnemies2)
end
if descNPCs2~="" then
table.insert(descStrings, ""..descNPCs2)
end
if descPlayers2~="" then
table.insert(descStrings, ""..descPlayers2)
end
if descChests2~="" then
table.insert(descStrings, ""..descChests2)
end
if descGroundItems2~="" then
table.insert(descStrings, ""..descGroundItems2)
end
if descHouses2~="" then
table.insert(descStrings, ""..descHouses2)
end
if descDungeons2~="" then
table.insert(descStrings, ""..descDungeons2)
end
local descStrings2 = {}
local tre,tree2=describeTrees2()
local plan,plan2=describePlants2()
local rub,rub2=describeRubble2()
local enem,enem2=describeEnemies2()
local npc1,npc2=describeNPCs2()
local plr1,plr2=describePlayers2()
local chest,ches2=describeChests2()
local g1,g2=describeGroundItems2()
local hous,house=describeHouses2()
local dung,dungeon=describeDungeons2()
local struc,struc2=describestructures2()
local function DetermineGoal()
local interest=""
if closestPlayer~="" then
if player~=plr1 then
interest=interest.." I can see that "..plr1..""
elseif player~=nil then
local plrinter={
"I see you before me now,",
"I'm aware of your presence,",
"You stand before me,",
"I see you now,",
"You are in my sight,",
"I have you in my view,",
"You are here with me,",
"I can sense you,",
"I can spot you "..player.Name..",",
""..player.Name.." is that your name?",
"I can see you "..player.Name..",",
""..player.Name..", I know who you are.",
"I can sense you "..player.Name..",",
""..player.Name..", do you know who I am?",
"I can observe you "..player.Name..",",
""..player.Name..", what are you doing here?",
"I can notice you "..player.Name..",",
""..player.Name..", do you have a purpose here?"
}
interest=interest..plrinter[chatmodule.mathrandom(1,#plrinter)]
end
end
if enem~="" then
local enemt={" Watch out, there is "..enem.."",
""..enem.."",
" There is "..enem.."",
" I notice "..enem.."",
" I believe there is "..enem.."",
" Be careful, "..enem.."",
" I see "..enem.."",
" I suspect there is "..enem.."",
" Beware of "..enem.."."
}
interest=interest..enemt[chatmodule.mathrandom(1,#enemt)]
end
if npc1~="" then
if closestPlayer and interest~="" then
interest=interest..", and"
end
local npct={" I'm aware of my peer, "..aware.judgeobject(closestNPC)..",",
" "..npc1.."",
" I notice that "..npc1.."",
" I can see my colleague, "..aware.judgeobject(closestNPC)..",",
" "..npc1.." is in my view.",
" I observe that "..npc1.."",
" I can sense my ally, "..aware.judgeobject(closestNPC)..",",
" "..npc1.." is within my range.",
" I detect that "..npc1.."",
" I can spot another adventurer, "..aware.judgeobject(closestNPC)..","
}
interest=interest..npct[chatmodule.mathrandom(1,#npct)]
end
if closestDungeon then
--if not npc1 and interest~="" then
-- interest=interest..", we "
--else
-- interest=interest.." We "
--end
if interest~="" then
interest=interest.."."
end
local strut={" We are in a place called "..aware.judgeobject(closestDungeon).."",
"I believe, we are in an area called "..aware.judgeobject(closestDungeon).."",
""..aware.judgeobject(closestDungeon).."... I believe that's what this place is called",
"This area is called "..aware.judgeobject(closestDungeon).."",
"If I recall correctly this place is known as "..aware.judgeobject(closestDungeon).."",
"If my navigation skills are correct, this area is called "..aware.judgeobject(closestDungeon).."",
"This place is known as "..aware.judgeobject(closestDungeon).."",
""..aware.judgeobject(closestDungeon).." is the name of this land.",
"According to my map, this place is called "..aware.judgeobject(closestDungeon).."",
"I have heard that this place is called "..aware.judgeobject(closestDungeon).."",
""..aware.judgeobject(closestDungeon)..", that's the name of this place.",
"This location is called "..aware.judgeobject(closestDungeon).."",
"From what I know, this place is known as "..aware.judgeobject(closestDungeon).."",
"My compass tells me that this area is called "..aware.judgeobject(closestDungeon).."",
"I have learned that this place is called "..aware.judgeobject(closestDungeon).."",
""..aware.judgeobject(closestDungeon)..", that's the name of this area.",
"This spot is called "..aware.judgeobject(closestDungeon).."",
"Based on my information, this place is known as "..aware.judgeobject(closestDungeon).."",
"My guidebook says that this area is called "..aware.judgeobject(closestDungeon).."",
"I have been told that this place is called "..aware.judgeobject(closestDungeon)..""}
interest=interest..strut[chatmodule.mathrandom(1,#strut)]
end
if struc~="" then
if interest~="" then
interest=interest.."."
end
interest=interest.." Their is a "..struc
end
if chest~="" then
if interest~="" then
interest=interest.."."
end
interest=interest.." I notice a "..chest..""
end
if g1~="" then
if interest~="" then
interest=interest..","
end
interest=interest..g1
end
if hous~="" then
if struc and interest~="" then
interest=interest.."."
end
interest=interest.." I can see a "..hous..""
end
if tree2 then
if interest~="" then
interest=chatmodule.randomizeString(interest..". Additionally, t")
else
interest=interest.."T"
end
interest=interest.."heir are "..tree2
end
if plan2 then
if interest~="" then
interest=interest..","
else
interest=interest.." Their are "
end
interest=interest..""..plan2..""
end
if interest~="" then
interest=interest.."."
end
return interest
end
--example enemyText = aware.judgeobject(closestEnemy.Parent).. " is " ..dist.. " to the " ..dir
--return enemyText,aware.judgeamnt(numPlayers).." of players are nearby"
-- enemyText = enemyText ..context.. aware.judgeamnt(numPlayers).." of players are nearby"
-- Remove any nil values
local finalStrings = {}
local paragraphstring=""
for i,str in ipairs(descStrings) do
if str ~= "" then
table.insert(finalStrings, opener[math.random(1,#opener)]..str..".")
if i~=#descStrings then
paragraphstring=paragraphstring..str..", "
else
paragraphstring=paragraphstring..str..". "
end
end
end
table.insert(finalStrings,DetermineGoal())
if paragraphstring~="" then
paragraphstring=paragraphstring.."."
table.insert(finalStrings,paragraphstring)
end
-- Join the strings together
return finalStrings
end
local d1=describeSurroundings(pos)
local d2=describeSurroundings2(pos)
local syntheticdata= function()
for i,str in ipairs(d1) do
if str ~= "" then
table.insert(d2, str)
--paragraphstring=paragraphstring..str..", "
end
end
for i,str in ipairs(d2) do
if str ~= "" then
d2[i]=chatmodule.randomizeStringLight(str,syntheticdatasynonms)
--paragraphstring=paragraphstring..str..", "
end
end
return d2
end
return syntheticdata(),closestEnemy
--,
--{
-- closestPlant = closestPlant,
-- numPlants = numPlants,
-- plantsize = plantsize,
-- closestTree = closestTree,
-- numTrees = numTrees,
-- closestStructure = closestStructure,
-- numStructures = numStructures,
-- structuresize = structuresize,
-- closestEnemy = closestEnemy,
-- numEnemies = numEnemies,
-- closestNPC = closestNPC,
-- numNPCs = numNPCs,
-- closestPlayer = closestPlayer,
-- numPlayers = numPlayers,
-- closestRubble = closestRubble,
-- numRubble = numRubble,
-- closestChest = closestChest,
-- numChests = numChests,
-- closestGroundItem = closestGroundItem,
-- numGroundItems = numGroundItems,
-- closestHouse = closestHouse,
-- numHouses = numHouses,
-- housesize,
-- closestDungeon = closestDungeon,
-- numDungeons = numDungeons,
-- dungsize = dungsize
--}
end
return aware
Also, this is the video that inspired this!
This is a old video of my AI in Action!
I’m currently using this with Zephyr 7b with a experiment to inject the system message with the awareness! It’s been very successful!
Some updates to this library is that it is very optimized and can be very useful for tracking objects in your game! I personally use this as a easy module for getting nearest objects and to describe the surroundings to inject into the system message of a LLM
Here’s an example of code used to inject AI with the awareness
function cm.ZephyrStory(person,personal,Playername,quer)
-- Define the API URL and the authorization header
local API_URL = "https://api-inference.huggingface.co/models/HuggingFaceH4/zephyr-7b-beta"
local headers = {Authorization = bearer}
-- Define the HttpService
local HttpService = game:GetService("HttpService")
-- Define a function that takes an input and queries the model
local function queryModel(input)
-- Create a payload table with the input
local payload = {inputs = input}
-- Encode the payload table into a JSON string
local payloadJSON = HttpService:JSONEncode(payload)
-- Send a POST request to the API URL with the header and the payload
local response = HttpService:PostAsync(API_URL, payloadJSON, Enum.HttpContentType.ApplicationJson, false, headers)
-- Decode the response into a table
print(response)
-- local responseTable = HttpService:JSONDecode(response)
-- Return the response table
return response --Get JSON res[pmse]
end
local personality=personal[1]
local awarobserve=personal[2]
-- Test the function with an example input
local input = "<|system|>\n You are a roleplaying as a "..personality..", you are charismatic and friendly, your name is "..person..". You have a avatar and you are the brain. "..awarobserve.."</s>\n<|"..Playername.."|>\n"..quer.."</s>\n<|assistant|>"
local output = queryModel(input)
print(output)
--local str=format_response(output[1].generated_text)
--print(str)
--local outputtabl=cm.extractDialogue(str)
-- Print the output
return output --parseConversation(str)
end