Roblox · Захват флага · урок 7
Последние штрихи: выдача брони на базе, оружие из раздела «Оружие» и публикация.
Синим — что добавляем на этом уроке.
Workspace └─ Bases → Синие (Model) └─ ArmorGiver (Part) └─ ArmorScript (Script) StarterPack └─ оружие (Tool) — из раздела «Оружие»
Где: Workspace → Bases → Синие → ArmorGiver · Script
Зачем: Выдаёт броню.
-- деталь, выдающая броню
local giver = script.Parent
-- сколько здоровья добавляет
local BONUS = 100
-- касание
giver.Touched:Connect(function(hit)
-- персонаж
local character = hit.Parent
-- Humanoid
local humanoid = character:FindFirstChildOfClass("Humanoid")
-- не игрок, погиб или броня уже есть
if not humanoid or humanoid.Health <= 0 or character:GetAttribute("Armor") then return end
-- туловище R15 или R6
local torso = character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
-- нет туловища
if not torso then return end
-- у этого персонажа броня есть (после смерти — снова нет)
character:SetAttribute("Armor", true)
-- больше максимум
humanoid.MaxHealth += BONUS
-- полное здоровье
humanoid.Health = humanoid.MaxHealth
-- нагрудник
local plate = Instance.new("Part")
-- имя
plate.Name = "ArmorPlate"
-- чуть больше туловища
plate.Size = torso.Size + Vector3.new(0.3, 0.1, 0.3)
-- цвет как у выдачи
plate.Color = giver.Color
-- металл
plate.Material = Enum.Material.Metal
-- не мешает ходить
plate.CanCollide = false
-- лучи сквозь
plate.CanQuery = false
-- без веса
plate.Massless = true
-- на туловище
plate.CFrame = torso.CFrame
-- сварка
local weld = Instance.new("WeldConstraint")
-- туловище
weld.Part0 = torso
-- нагрудник
weld.Part1 = plate
-- в нагрудник
weld.Parent = plate
-- в персонажа
plate.Parent = character
-- конец функции
end)Запусти Play (или Run) и убедись:
Roblox · Capture the flag · lesson 7
Final touches: armor at the base, weapons from the Weapons section, and publishing.
Blue — what we add in this lesson.
Workspace └─ Bases → Синие (Model) └─ ArmorGiver (Part) └─ ArmorScript (Script) StarterPack └─ оружие (Tool) — from the Weapons section
Where: Workspace → Bases → Синие → ArmorGiver · Script
Why: Gives armor.
-- the part that gives armor
local giver = script.Parent
-- how much health it adds
local BONUS = 100
-- touch
giver.Touched:Connect(function(hit)
-- the character
local character = hit.Parent
-- Humanoid
local humanoid = character:FindFirstChildOfClass("Humanoid")
-- not a player, dead or already has armor
if not humanoid or humanoid.Health <= 0 or character:GetAttribute("Armor") then return end
-- the R15 or R6 torso
local torso = character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
-- no torso
if not torso then return end
-- this character has armor (after death — none again)
character:SetAttribute("Armor", true)
-- a higher maximum
humanoid.MaxHealth += BONUS
-- full health
humanoid.Health = humanoid.MaxHealth
-- the chest plate
local plate = Instance.new("Part")
-- name
plate.Name = "ArmorPlate"
-- slightly bigger than the torso
plate.Size = torso.Size + Vector3.new(0.3, 0.1, 0.3)
-- the same color as the giver
plate.Color = giver.Color
-- metal
plate.Material = Enum.Material.Metal
-- doesn't get in the way
plate.CanCollide = false
-- rays pass through
plate.CanQuery = false
-- weightless
plate.Massless = true
-- on the torso
plate.CFrame = torso.CFrame
-- the weld
local weld = Instance.new("WeldConstraint")
-- the torso
weld.Part0 = torso
-- the chest plate
weld.Part1 = plate
-- into the chest plate
weld.Parent = plate
-- into the character
plate.Parent = character
-- end of function
end)Press Play (or Run) and make sure: