Skip to content

Commit

Permalink
Revert actor change from BotBrain. (#1461)
Browse files Browse the repository at this point in the history
Revert actor usage due to little performance change and overhead.
  • Loading branch information
fxeP1 authored Mar 27, 2024
1 parent 4e9561d commit 1edcca3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 47 deletions.
33 changes: 10 additions & 23 deletions MainModule/Server/Core/Functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ return function(Vargs, GetEnv)
foundNum += 1
end
end

if foundNum == 0 and useFakePlayer then
local ran, name = pcall(service.Players.GetNameFromUserIdAsync, service.Players, matched)
if ran or allowUnknownUsers then
Expand Down Expand Up @@ -376,7 +376,7 @@ return function(Vargs, GetEnv)
local p = getplr(v)
local character = p.Character
local Head = character and character:FindFirstChild("Head")

if Head and p and p ~= plr and plr:DistanceFromCharacter(Head.Position) <= num then
table.insert(players,p)
plus()
Expand Down Expand Up @@ -454,7 +454,7 @@ return function(Vargs, GetEnv)

if chatMod then
return require(chatMod)
elseif isTextChat then
elseif isTextChat then
return false
end
return nil
Expand Down Expand Up @@ -982,7 +982,7 @@ return function(Vargs, GetEnv)
end
end
end;

SetAtmosphere = function(prop,value)
if service:FindFirstChildWhichIsA("Atmosphere")[prop] ~= nil then
service:FindFirstChildWhichIsA("Atmosphere")[prop] = value
Expand Down Expand Up @@ -1145,21 +1145,8 @@ return function(Vargs, GetEnv)

local oldArchivable = char.Archivable
char.Archivable = true
local rawClone = char:Clone()
local clone = char:Clone()
char.Archivable = oldArchivable
local clone = Instance.new("Actor")

clone.PrimaryPart = rawClone.PrimaryPart
clone.WorldPivot = rawClone.WorldPivot
--clone:ScaleTo(rawClone:GetScale())

for k, v in ipairs(rawClone:GetAttributes()) do
clone:SetAttribute(k, v)
end

for _, v in ipairs(rawClone:GetChildren()) do
v.Parent = clone
end

for i = 1, num do
local new = clone:Clone()
Expand Down Expand Up @@ -1418,16 +1405,16 @@ return function(Vargs, GetEnv)
end
end
end;
AddJoinFilter = function(name, func)

AddJoinFilter = function(name, func)
if server.Variables.PlayerJoinFilters[name] then
error(string.format("The Join Filter %s already exists!", name))
else
server.Variables.PlayerJoinFilters[name] = func
end
end;
RemoveJoinFilter = function(name)

RemoveJoinFilter = function(name)
if server.Variables.PlayerJoinFilters[name] then
server.Variables.PlayerJoinFilters[name] = nil
end
Expand Down Expand Up @@ -1615,4 +1602,4 @@ return function(Vargs, GetEnv)
task.spawn(xpcall, function()
server.Functions.NuclearExplode = require(server.Dependencies.FastNuke);
end, warn)
end
end
47 changes: 23 additions & 24 deletions MainModule/Server/Dependencies/Assets/BotBrain.rbxmx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
<Meta name="ExplicitAutoJoints">true</Meta>
<External>null</External>
<External>nil</External>
<Item class="Script" referent="RBXC732856BD1794030BD81DBF4DAF91A37">
<Item class="Script" referent="RBX32EFA7A0E4844F57B93C144597270446">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<SecurityCapabilities name="Capabilities">0</SecurityCapabilities>
<bool name="DefinesCapabilities">false</bool>
<bool name="Disabled">true</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">BotBrain</string>
<token name="RunContext">0</token>
<string name="ScriptGuid">{996E9DAB-6244-4310-B1DA-34783184C4A3}</string>
<token name="RunContext">1</token>
<string name="ScriptGuid">{57C75EF3-A7BD-4721-AC2E-EF182347E0A6}</string>
<ProtectedString name="Source"><![CDATA[local char = script.Parent
local event = script.Event

Expand All @@ -19,7 +21,7 @@ local Debris = game:GetService("Debris")

local hum = char:FindFirstChildOfClass("Humanoid") or char:WaitForChild("Humanoid")
local head = char:FindFirstChild("Head")
local torso = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
local torso = char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
local larm = char:FindFirstChild("Left Arm") or char:FindFirstChild("LeftLowerArm")
local rarm = char:FindFirstChild("Right Arm") or char:FindFirstChild("RightLowerArm")
local lleg = char:FindFirstChild("Left Leg") or char:FindFirstChild("LeftLowerLeg")
Expand Down Expand Up @@ -109,13 +111,13 @@ end
local function canSee(targCFrame)
local myPos = getCFrame().Position
local targetPos = targCFrame.Position

local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {char, props.Target}
rayParams.FilterType = Enum.RaycastFilterType.Exclude

local result = workspace:Raycast(myPos, (targetPos - myPos).Unit, rayParams)

if result and result.Instance then
return false
else
Expand All @@ -142,13 +144,11 @@ end

local function doAttack(v)
if props.Attack and not props.isDead and v == props.Target then
task.synchronize()
local foundHumanoid = v:FindFirstChildOfClass("Humanoid")
if foundHumanoid and validTarget(v) then
tagHumanoid(foundHumanoid, hum)
foundHumanoid:TakeDamage(props.Damage)
end
task.desynchronize()
end
end

Expand All @@ -160,7 +160,7 @@ end

getPath = function()
local targetPos

if props.Target and props.Target.Parent then
local target = props.Target:FindFirstChild("HumanoidRootPart") or props.Target:FindFirstChild("Torso") or props.Target:FindFirstChild("UpperTorso")
if target then
Expand All @@ -172,7 +172,7 @@ getPath = function()
else
targetPos = CFrame.new(props.PatrolZone+Vector3.new(math.random(-props.PatrolDist,props.PatrolDist),0,math.random(-props.PatrolDist,props.PatrolDist)))
end

if not props.isDead and not props.Computing then
if canSee(targetPos) then
props.AutoCompute = true
Expand All @@ -183,13 +183,13 @@ getPath = function()
else
props.Computing = true
props.AutoCompute = false

local pathf = PathfindingService:ComputeSmoothPathAsync(
getCFrame().Position,
targetPos.Position,
500
)

path = {}
path = pathf:GetPointCoordinates()
props.LastCompute = os.clock()
Expand All @@ -202,27 +202,27 @@ end

local function walkPath()
local myPos = getCFrame().Position

local coord = path[currentInd]
if coord then
current = coord
currentInd = currentInd+1

if hum ~= nil and hum:IsA("Humanoid") then
hum:MoveTo(current)

jumpCheck()
if (current.Y - getCFrame().Position.Y) > 2.5 then
hum.Jump = true
elseif (current.Y - getCFrame().Position.Y) < -2.5 then
hum:MoveTo(current+Vector3.new(2,0,2))
end

if #path>2 then
repeat task.wait(0.1) until path[currentInd] ~= coord or (getCFrame().Position - coord).Magnitude < 2.5
end
end

if currentInd == #path then
props.AutoCompute = true
end
Expand All @@ -247,18 +247,15 @@ local function init()
str.Value = props.SpecialKey

hum.Died:Connect(function()
task.synchronize()
Debris:AddItem(char, 1)
props.isDead = true
end)

task.desynchronize()

while task.wait(1/30) and not props.isDead do
if char and hum and not props.isDead then
updateBot()
else
task.synchronize()
props.isDead = true
Debris:AddItem(char, 1)
break
Expand All @@ -267,7 +264,7 @@ local function init()
end

local function doToucher(part)
part.Touched:ConnectParallel(function(hit)
part.Touched:Connect(function(hit)
if hit and hit:IsA("BasePart") and hit.Parent and hit.Parent:IsA("Model") and hit.Parent:FindFirstChildOfClass("Humanoid") and hit.Parent ~= script.Parent then
doAttack(hit.Parent)
end
Expand All @@ -291,13 +288,15 @@ end)]]></ProtectedString>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
</Properties>
<Item class="BindableEvent" referent="RBXBA58843F5106435DBFDFC20DDDBD1D51">
<Item class="BindableEvent" referent="RBXE8190E3CC2124BDB9256DCE153451865">
<Properties>
<BinaryString name="AttributesSerialize"></BinaryString>
<SecurityCapabilities name="Capabilities">0</SecurityCapabilities>
<bool name="DefinesCapabilities">false</bool>
<string name="Name">Event</string>
<int64 name="SourceAssetId">-1</int64>
<BinaryString name="Tags"></BinaryString>
</Properties>
</Item>
</Item>
</roblox>
</roblox>

0 comments on commit 1edcca3

Please sign in to comment.