• สินค้าทั้งหมด
  • Studio
  • คู่มือการใช้งาน
  • เพิ่มศัตรูใหม่
  • ฟังก์ชันภายใน
  • แก้ปัญหาศัตรูหาย
  • Client Exports
  • Server Exports
Docs > Dungeon > เพิ่มศัตรูใหม่

ขั้นตอนการเพิ่ม Enemy#

  1. สร้างไฟล์ .lua ใหม่ในโฟลเดอร์ mrft_dungeon/config/enemies
  2. คัดลอก Template ด้านล่างไปใส่ในไฟล์
  3. แก้ค่า self.unique, self.name, self.model, ค่าสถานะ และ Logic ของศัตรูตามต้องการ

ค่า self.unique ต้องไม่ซ้ำกับ Enemy ตัวอื่น เพราะระบบใช้ค่านี้ระบุตัวตนของศัตรู

Enemy Template#

enemies = enemies or {}

local self = {}
self.unique = "ENEMY_UNIQUE_HERE" --! สำคัญ: ห้ามตั้ง unique ซ้ำกัน
self.name = "ENEMY_NAME_HERE" -- ชื่อที่จะแสดง
self.model = `ENEMY_MODEL_HERE` -- โมเดล
self.spawnRateWeight = 1 -- โอกาสที่จะเกิด
self.dungeons = {1, 2} -- จะเกิดที่ดันเจี้ยนไหนบ้าง
self.participation = 10 -- ผู้เล่นต้องมีส่วนร่วมทำดาเมจกี่ % ถึงจะมีโอกาสได้ไอเทมดรอป
self.rewards = { -- รางวัลที่จะได้จากการฆ่า
    {name = "REWARD_1", count = {1, 2}, chance = 100, tier = 2}
}

self.health = {350, 400} -- เลือด
self.skill_points = {4, 6} -- Point สกิล 2 ที่จะได้รับ
self.ultimate_points = {2, 3} -- Point สกิลอัลติ ที่จะได้รับ
self.healthBarOffset = {x = 0.0, y = 0.0, z = 1.0}
self.targetOffset = {x = 0.0, y = 0.0, z = 0.0}
self.scale = {x = 1.0, y = 1.0, z = 1.0} -- ขนาดตัวละครของศัตรู
self.faceCamera = false -- ศัตรูจะหันไปทางหน้าผู้เล่นตลอด (ถ้าเปิดจะไม่สามารถใช้งาน self.scale ได้)
self.moveRate = 1.5 -- ความเร็วในการเดิน
self.suspicious_distance = 50.0  -- ระยะที่จะระวังตัว (ทำให้ฉลาดขึ้นและรู้สึกตัวไวขึ้น)
self.see_distance = 20.0 -- ระยะที่จะเห็นผู้เล่น
self.attack_distance = 20.0 -- ถ้าเป็นศัตรูที่โจมตีระยะใกล้ แนะนำให้ตั้งเท่ากับ self.see_distance
self.attack_cooldown = 2000
self.interval = { --? ตัวเลขน้อย NPC จะฉลาดขึ้นแต่จะกินทรัพยากรสูงขึ้นเช่นกัน
    sleep = 10000,
    idle = 5000,
    notice = 3000
}

if not IsDuplicityVersion() then
    function self.setup(myPed)

    end

    function self.onDead(myPed)

    end

    function self.noticePlayer(myPed, targetId, IsTarget)

    end

    function self.onAttacked(myPed, targetId, IsTarget, metadata)

    end
else --! Server
    function self.spawn(coords)
        local ped = CreatePed(4, self.model, coords, 0.0, true, true)
        return ped
    end

    function self.onDead(myPed)

    end

    -- เมื่อโดนโจมตีจากผู้เล่น
    function self.onDamaged(myPed, attackerId, damage, damageType)

    end

    -- โจมตีผู้เล่นที่ใกล้ที่สุด
    function self.attack(myPed, closetId, closetPed, distance, coords)

    end

    -- ล่าผู้เล่นที่ใกล้ที่สุด
    function self.move(myPed, closetId, closetPed, distance, coords)

    end

    -- สุ่มเดินเมื่อไม่พบผู้เล่น
    function self.flee(myPed, spawn_coords, coords)

    end

    -- ฟังก์ชั่นนี้จะเรียกใช้ทุกครั้งที่มีการคำนวณ
    function self.tick(myPed)

    end
end

-- Create the enemy
table.insert(enemies, self)
On this page
  • ขั้นตอนการเพิ่ม Enemy
  • Enemy Template