Roblox · Захват флага · урок 7

Броня, оружие и публикация

Последние штрихи: выдача брони на базе, оружие из раздела «Оружие» и публикация.

Структура

Синим — что добавляем на этом уроке.

Workspace
└─ Bases → Синие (Model)
   └─ ArmorGiver (Part)
      └─ ArmorScript (Script)
StarterPack
└─ оружие (Tool) — из раздела «Оружие»

Шаги

  1. «ArmorGiver» — кубик у каждой базы, со скриптом «ArmorScript». Коснулся — +100 к максимуму здоровья и нагрудник.
  2. Атрибут Armor ставится персонажу, а не всем сразу: каждый игрок получает броню раз за жизнь.
  3. Оружие: возьми меч или автомат из раздела «Оружие» и положи в StarterPack — оно будет у каждого.
  4. RespawnLocation уже настроен: после смерти игрок появляется у своей базы.
  5. Game Settings → Places → MaxPlayers чётное (например, 10) — команды равные.
  6. File → Publish to Roblox, Game Settings → Permissions → Public.

Скрипты

ArmorScript

Где: 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

Armor, weapons and publishing

Final touches: armor at the base, weapons from the Weapons section, and publishing.

Structure

Blue — what we add in this lesson.

Workspace
└─ Bases → Синие (Model)
   └─ ArmorGiver (Part)
      └─ ArmorScript (Script)
StarterPack
└─ оружие (Tool) — from the Weapons section

Steps

  1. "ArmorGiver" is a cube at each base with a script "ArmorScript". Touch it — +100 max health and a chest plate.
  2. The Armor attribute is set on the character, not on everyone: each player gets armor once per life.
  3. Weapons: take a sword or a rifle from the Weapons section and put it in StarterPack — everyone gets it.
  4. RespawnLocation is already set: after dying the player appears at their base.
  5. Game Settings → Places → an even MaxPlayers (for example 10) — teams are equal.
  6. File → Publish to Roblox, Game Settings → Permissions → Public.

Scripts

ArmorScript

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)

Testing

Press Play (or Run) and make sure: