Tenha em mente que o dummy é R6, e que o que eu quero é um sistema individual pra cada…
- User
Tenha em mente que o dummy é R6, e que o que eu quero é um sistema individual pra cada um, pois lidaremos com multiplos tipos de npcs no futuro, o gear fica filho direto do character, ou tem uma forma melhor de fazer esse sistema, por exemplo, deixando a ferramenta em alguma pasta sepaarada
Assistant
Aqui está uma versão otimizada do sistema com as melhorias solicitadas:
Estrutura do Sistema (Organização)
ServerScriptService/ ├── NPCManager.lua ├── NPCBase.lua └── Tools/ ├── Tool1.lua └── Tool2.lua LocalScripts/ └── NPCToolHandler.lua1. Script Principal (ServerScriptService/NPCManager.lua)
-- Servidor: Gerenciamento dos NPCs local ServerScriptService = game:GetService("ServerScriptService") local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local NPCManager = {} local NPCs = {} -- Criação de NPC base local function createNPC(npcType, position) local npcModel = Instance.new("Model") npcModel.Name = "NPC_" .. npcType npcModel.PrimaryPart = Instance.new("Part") npcModel.PrimaryPart.Size = Vector3.new(2, 2, 1) npcModel.PrimaryPart.Anchored = false npcModel.PrimaryPart.CanCollide = true npcModel.PrimaryPart.Material = Enum.Material.Plastic npcModel.PrimaryPart.Position = position npcModel.PrimaryPart.Parent = workspace -- Criação de pasta de equipamentos local gearFolder = Instance.new("Folder") gearFolder.Name = "Gear" gearFolder.Parent = npcModel -- Criação do humanoide local humanoid = Instance.new("Humanoid") humanoid.Name = "Humanoid" humanoid.Parent = npcModel -- Criação do root part local rootPart = Instance.new("Part") rootPart.Name = "HumanoidRootPart" rootPart.Size = Vector3.new(2, 1, 1) rootPart.Anchored = false rootPart.CanCollide = true rootPart.Material = Enum.Material.Plastic rootPart.Position = position + Vector3.new(0, 2, 0) rootPart.Parent = npcModel -- Configurações do humanoide humanoid.WalkSpeed = 16 humanoid.MaxHealth = 100 humanoid.Health = 100 humanoid.RootPart = rootPart -- Carrega a ferramenta específica local tool = ReplicatedStorage.Tools:FindFirstChild(npcType) if tool then local toolClone = tool:Clone() toolClone.Parent = gearFolder end -- Adiciona ao array NPCs[npcModel] = { model = npcModel, humanoid = humanoid, gear = gearFolder } return npcModel end -- Seguir jogador local function followPlayer(npcData, player) local humanoid = npcData.humanoid local rootPart = humanoid.RootPart while true do if not player or not player.Character then break end local playerRoot = player.Character:FindFirstChild("HumanoidRootPart") if playerRoot then local distance = (rootPart.Position - playerRoot.Position).Magnitude if distance < 20 then humanoid:MoveTo(playerRoot.Position) else humanoid:MoveTo(rootPart.Position) end end wait(0.1) end end -- Evento de player adicionado Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local spawnPosition = Vector3.new(math.random(-50, 50), 5, math.random(-50, 50)) local npcModel = createNPC("Tool1", spawnPosition) -- Inicia o seguimento followPlayer(NPCs[npcModel], player) end) end) -- Limpeza de NPCs game:GetService("RunService").Heartbeat:Connect(function() for npcModel, data in pairs(NPCs) do if not npcModel or not npcModel.Parent then data.gear:Destroy() data.model:Destroy() NPCs[npcModel] = nil end end end) return NPCManager2. Ferramentas (ReplicatedStorage/Tools/Tool1.lua)
-- Ferramenta básica para NPC local tool = Instance.new("Tool") tool.Name = "Tool1" tool.RequiresHandle = true local handle = Instance.new("Part") handle.Name = "Handle" handle.Size = Vector3.new(1, 1, 1) handle.Material = Enum.Material.Neon handle.Color = Color3.fromRGB(0, 255, 0) handle.Anchored = true handle.Parent = tool local mesh = Instance.new("BlockMesh") mesh.Parent = handle mesh.Scale = Vector3.new(1, 1, 1) tool.Parent = ReplicatedStorage.Tools3. Script de Controle (LocalScript/NPCToolHandler.lua)
-- Cliente: Controle da ferramenta do NPC local Players = game:GetService("Players") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local function onToolUsed(tool) print("Ferramenta usada: " .. tool.Name) -- Adicione lógica de uso aqui end -- Verifica se há ferramentas no NPC local function checkNPCTools() local npc = character:FindFirstChild("NPC_") if npc then local gearFolder = npc:FindFirstChild("Gear") if gearFolder then for _, tool in ipairs(gearFolder:GetChildren()) do if tool:IsA("Tool") then tool.Equipped:Connect(function() onToolUsed(tool) end) end end end end end -- Monitora mudanças no personagem character:WaitForChild("HumanoidRootPart") checkNPCTools() -- Atualiza quando o personagem muda player.CharacterAdded:Connect(function(newCharacter) newCharacter.HumanoidRootPart.Changed:Connect(checkNPCTools) checkNPCTools() end)Melhorias Principais:
-
Organização por Pasta:
- Cada NPC tem uma pasta "Gear" com suas ferramentas
- Ferramentas são armazenadas em
ReplicatedStorage/Tools/
-
Sistema Modular:
- Cada tipo de NPC pode ter sua própria ferramenta
- Adição de novos tipos é simples (basta criar nova ferramenta em
Tools/)
-
R6 Compatibility:
- Usa
HumanoidRootPartcorretamente para NPCs R6 - Não depende de partes específicas como "Torso"
- Usa
-
Escalabilidade:
- Pode ser expandido para diferentes tipos de NPCs
- Facilidade de adicionar novas funcionalidades
-
Segurança:
- Ferramentas são clonadas no lado do servidor
- Controle de uso é feito no cliente
Como Usar:
- Crie pastas e scripts conforme a estrutura
- Adicione novas ferramentas em
ReplicatedStorage/Tools/ - Modifique
NPCManager.luapara criar diferentes tipos de NPCs - O sistema automaticamente carrega a ferramenta correta para cada NPC
Este sistema permite que você crie múltiplos tipos de NPCs com diferentes ferramentas, mantendo a organização e escalabilidade para futuras expansões.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.