• Q群联盟
  • 暗夜奇迹
  • 机器人
  • Q群联盟
查看:27715|回复:6
收起左侧

入侵事件脚本.Lua

 [复制链接]
回帖奖励10 枚积分 回复本帖可获得 1 枚积分奖励! 每人限 1 次(中奖概率 50%)

TA的专栏

  • 打卡等级:死神戈登

今日最高分:0

今日排行:未上榜

等级头衔

等級:雪人王

活跃状态

30

主题

133

回帖

216

积分

积分货币
祝福
935 颗
灵魂
105 颗
玛雅
24552 颗
元宝
1 锭
积分
1788 枚
注册时间
2023-11-1
最后登录
2025-5-22

联系方式

QQ
QQ

违规信息
违规:5

荣誉勋章

  • Lua Mu
  • LuaMu
发表于 2025-4-14 19:47:12|显示全部楼层|阅读模式
星级打分
  • 1
  • 2
  • 3
  • 4
  • 5
平均分:0  参与人数:0  我的评分:未评



游客,如果您要查看本帖隐藏内容请回复





  1. local function getInvasionSchedules(index, scheduleManager)
  2.   local schedules = {}
  3.   for i = 1, #scheduleManager do
  4.     local row = scheduleManager[i]
  5.     if tonumber(row[1]) == index then
  6.       table.insert(schedules, {
  7.         Year = row[2],
  8.         Month = row[3],
  9.         Day = row[4],
  10.         DoW = row[5],
  11.         Hour = row[6],
  12.         Minute = row[7],
  13.         Second = row[8],
  14.       })
  15.     end
  16.   end
  17.   return schedules
  18. end

  19. local function sendAdminsInvasionNotice(monster, map)
  20.   local indexes = GetMonsterIndexes(monster, map)
  21.   for i = 1, #indexes do
  22.     local index = indexes[i]
  23.     local data = GetMonsterData(index)
  24.     SendAdminsNotice(
  25.       1,
  26.       {"%s Invaded %s (%d, %d)", "%s Invadiu %s (%d, %d)", "%s invadió %s (%d, %d)"},
  27.       {data.name, data.map.name, data.map.x, data.map.y}
  28.     )
  29.   end
  30. end

  31. local function loadInvasions()
  32.   local monsterSetBase = ReadSectionFile("../Data/Monster/MonsterSetBase.txt")
  33.   local invasionSetBase = monsterSetBase[3]
  34.   local invasionManager = ReadSectionFile("../Data/Event/InvasionManager.dat")
  35.   local scheduleManager = invasionManager[0]
  36.   local durationManager = invasionManager[1]
  37.   local monsterManager = invasionManager[3]

  38.   for i = 1, #invasionSetBase do
  39.     local monster = tonumber(invasionSetBase[i][1])
  40.     local map = tonumber(invasionSetBase[i][2])
  41.     local quantity = tonumber(invasionSetBase[i][9])
  42.     local index = getInvasionIndex(monster, monsterManager)
  43.     local duration = getInvasionDuration(index, durationManager)
  44.     local schedules = getInvasionSchedules(index, scheduleManager)
  45.     table.insert(Invasions, {
  46.       Monster = monster,
  47.       Map = map,
  48.       Quantity = quantity,
  49.       LiveCount = quantity,
  50.       Duration = duration,
  51.       Schedules = schedules,
  52.       CurrentSchedule = nil,
  53.     })
  54.   end
  55. end

  56. function ReadScript()
  57.   loadInvasions()
  58.   LogColor(2, string.format(
  59.     "[LUA][InvasionNotice] %d invasions loaded successfully",
  60.     #Invasions
  61.   ))
  62. end

  63. function MonsterDie(index, killerIndex)
  64.   if GetObjectType(index) ~= OBJECT_MONSTER then
  65.     return
  66.   end

  67.   local monster = GetObjectClass(index)
  68.   local map = GetObjectMap(index)
  69.   local invasion = findInvasion(monster, map)
  70.   if not invasion then
  71.     return
  72.   end

  73.   local liveCount = GetMonsterLiveCount(monster, map)
  74.   if (liveCount < invasion.LiveCount) then
  75.     invasion.LiveCount = liveCount
  76.   end
  77.   invasion.LiveCount = invasion.LiveCount - 1

  78.   local monsterName = GetMonsterName(monster)
  79.   local killerName = GetObjectName(killerIndex)
  80.   SendPlayersNotice(
  81.     0,
  82.     {"%s defeated %s [%d/%d]", "%s derrotou %s [%d/%d]", "%s derrotó %s [%d/%d]"},
  83.     {killerName, monsterName, invasion.Quantity - invasion.LiveCount, invasion.Quantity}
  84.   )

  85.   if invasion.LiveCount == 0 then
  86.     invasion.CurrentSchedule = nil
  87.     invasion.LiveCount = invasion.Quantity
  88.     SendPlayersNotice(
  89.       0,
  90.       {"%s is defeated!", "%s foi derrotado(a)!", "%s fue derrotado(a)!"},
  91.       {monsterName}
  92.     )
  93.   end
  94. end

  95. function TimerThread()
  96.   local gameServerCode = GetGameServerCode()
  97.   if (gameServerCode == 40) then
  98.     return
  99.   end

  100.   for i = 1, #Invasions do
  101.     local invasion = Invasions[i]
  102.     local liveCount = GetMonsterLiveCount(invasion.Monster, invasion.Map)
  103.     local currentSchedule = GetTimeUpSchedule(invasion.Schedules, 0)
  104.     if not invasion.CurrentSchedule and liveCount > 0 and currentSchedule then
  105.       invasion.CurrentSchedule = currentSchedule
  106.       local monsterName = GetMonsterName(invasion.Monster)
  107.       local mapName = GetMapName(invasion.Map)
  108.       SendPlayersNotice(
  109.         0,
  110.         {"The %s Invasion has begun in %s!", "A Invasão de %s começou em %s!", "La invasión de %s comenzó en %s!"},
  111.         {monsterName, mapName}
  112.       )
  113.       sendAdminsInvasionNotice(invasion.Monster, invasion.Map)
  114.     elseif invasion.CurrentSchedule then
  115.       local currentSchedule = GetTimeUpSchedule(invasion.Schedules, invasion.Duration)
  116.       if not currentSchedule then
  117.         invasion.CurrentSchedule = nil
  118.         invasion.LiveCount = invasion.Quantity
  119.         local monsterName = GetMonsterName(invasion.Monster)
  120.         SendPlayersNotice(
  121.           0,
  122.           {"%s has gone!", "%s foi embora!", "%s se fue!"},
  123.           {monsterName}
  124.         )
  125.       end
  126.     end
  127.   end
  128. end

  129. BridgeFunctionAttach("OnReadScript", "ReadScript")
  130. BridgeFunctionAttach("OnMonsterDie", "MonsterDie")
  131. BridgeFunctionAttach("OnTimerThread", "TimerThread")

  132. function GetAdmins()
  133.   local admins = {}
  134.   for index = GetMinUserIndex(), GetMaxUserIndex() do
  135.     local isAdmin = CommandCheckGameMasterLevel(index, 2) == 1
  136.     if isAdmin then
  137.       table.insert(admins, index)
  138.     end
  139.   end
  140.   return admins
  141. end

  142. function GetPlayers()
  143.   local players = {}
  144.   for index = GetMinUserIndex(), GetMaxUserIndex() do
  145.     table.insert(players, index)
  146.   end
  147.   return players
  148. end

  149. function SendAdminsNotice(value, message, args)
  150.   local admins = GetAdmins()
  151.   for i = 1, #admins do
  152.     local index = admins[i]
  153.     if (type(message) ~= "string") then
  154.       message = message[GetUserLanguage(index) + 1]
  155.     end
  156.     NoticeSend(index, value, string.format(message, table.unpack(args)))
  157.   end
  158. end

  159. function SendPlayersNotice(value, message, args)
  160.   local players = GetPlayers()
  161.   for i = 1, #players do
  162.     local index = players[i]
  163.     if (type(message) ~= "string") then
  164.       message = message[GetUserLanguage(index) + 1]
  165.     end
  166.     NoticeSend(index, value, string.format(message, table.unpack(args)))
  167.   end
  168. end

  169. function ReadSectionFile(filename)
  170.   local config = {}
  171.   local currentSection = nil
  172.   for line in io.lines(filename) do
  173.     line = line:match("^%s*(.-)%s*$")
  174.     if line ~= "" and not line:match("^//") then
  175.       if line:match("^%d+$") then
  176.         currentSection = tonumber(line)
  177.         if currentSection and not config[currentSection] then
  178.           config[currentSection] = {}
  179.         end
  180.       elseif line == "end" then
  181.         currentSection = nil
  182.       elseif currentSection then
  183.         local row = {}
  184.         for column in line:gmatch("%S+") do
  185.           table.insert(row, column)
  186.         end
  187.         table.insert(config[currentSection], row)
  188.       end
  189.     end
  190.   end
  191.   return config
  192. end

  193. function CheckScheduleTimeUp(schedule, duration)
  194.   local date = os.date("*t")
  195.   local currentTime = os.time({
  196.     year = date.year,
  197.     month = date.month,
  198.     day = date.day,
  199.     hour = date.hour,
  200.     min = date.min,
  201.     sec = 0,
  202.   })
  203.   local scheduleTime = os.time({
  204.     year = (schedule.Year ~= "*" and tonumber(schedule.Year)) or date.year,
  205.     month = (schedule.Month ~= "*" and tonumber(schedule.Month)) or date.month,
  206.     day = (schedule.Day ~= "*" and tonumber(schedule.Day)) or date.day,
  207.     hour = (schedule.Hour ~= "*" and tonumber(schedule.Hour)) or date.hour,
  208.     min = (schedule.Minute ~= "*" and tonumber(schedule.Minute)) or date.min,
  209.     sec = 0,
  210.   })
  211.   local isTimeUp = scheduleTime <= currentTime and (scheduleTime + duration) >= currentTime
  212.   return isTimeUp
  213. end

  214. function GetTimeUpSchedule(schedules, duration)
  215.   for i = 1, #schedules do
  216.     local schedule = schedules[i]
  217.     if (CheckScheduleTimeUp(schedule, duration)) then
  218.       return schedule
  219.     end
  220.   end
  221.   return nil
  222. end

  223. function GetMonsterData(index)
  224.   local map = GetObjectMap(index)
  225.   return {
  226.     index = index,
  227.     name = GetObjectName(index),
  228.     map = {
  229.       name = GetMapName(map),
  230.       x = GetObjectMapX(index),
  231.       y = GetObjectMapY(index),
  232.     }
  233.   }
  234. end

  235. function GetMonsterIndexes(monster, map)
  236.   local indexes = {}
  237.   for index = GetMinMonsterIndex(), GetMaxMonsterIndex() do
  238.     local currentMonster = GetObjectClass(index)
  239.     local currentMap = GetObjectMap(index)
  240.     if monster == currentMonster and (not map or currentMap == map) then
  241.       table.insert(indexes, index)
  242.     end
  243.   end
  244.   return indexes
  245. end

  246. function GetMonsterLiveCount(monster, map)
  247.   local liveCount = 0
  248.   local indexes = GetMonsterIndexes(monster, map)
  249.   for i = 1, #indexes do
  250.     local index = indexes[i]
  251.     local isDead = GetObjectLive(index) <= 0
  252.     if not isDead then
  253.       liveCount = liveCount + 1
  254.     end
  255.   end
  256.   return liveCount
  257. end
复制代码


吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

TA的专栏

  • 打卡等级:天魔菲尼斯

今日最高分:0

今日排行:未上榜

等级头衔

等級:哥布林

活跃状态

0

主题

941

回帖

178

积分

积分货币
祝福
468 颗
灵魂
1 颗
玛雅
38414 颗
元宝
0 锭
积分
956 枚
注册时间
2023-11-27
最后登录
2025-5-23

联系方式

违规信息
违规:0

荣誉勋章

    发表于 2025-4-14 21:40:05|显示全部楼层
    关注一下!
    我要说一句
    吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

    TA的专栏

    • 打卡等级:天魔菲尼斯

    今日最高分:0

    今日排行:未上榜

    等级头衔

    等級:哥布林

    活跃状态

    0

    主题

    943

    回帖

    179

    积分

    积分货币
    祝福
    471 颗
    灵魂
    1 颗
    玛雅
    40785 颗
    元宝
    0 锭
    积分
    962 枚
    注册时间
    2023-11-27
    最后登录
    2025-5-23

    联系方式

    违规信息
    违规:0

    荣誉勋章

      发表于 2025-4-18 08:40:01|显示全部楼层
      吾爱一起玩儿,一个游戏爱好者的聚集地!
      我要说一句
      吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

      TA的专栏

      • 打卡等级:魔鬼戈登

      今日最高分:0

      今日排行:未上榜

      等级头衔

      等級:幼龙

      活跃状态

      2

      主题

      31

      回帖

      28

      积分

      积分货币
      祝福
      2 颗
      灵魂
      17 颗
      玛雅
      1687 颗
      元宝
      0 锭
      积分
      230 枚
      注册时间
      2024-12-31
      最后登录
      2025-4-28

      联系方式

      QQ
      QQ

      违规信息
      违规:0

      荣誉勋章

      勇者大陆炉石

        发表于 2025-4-18 12:56:31|显示全部楼层
        大佬牛逼~~
        我要说一句
        吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!
        回复

        使用道具举报

        TA的专栏

        • 打卡等级:天魔菲尼斯

        今日最高分:0

        今日排行:未上榜

        等级头衔

        等級:哥布林

        活跃状态

        2

        主题

        960

        回帖

        183

        积分

        积分货币
        祝福
        489 颗
        灵魂
        1 颗
        玛雅
        40571 颗
        元宝
        0 锭
        积分
        983 枚
        注册时间
        2023-11-27
        最后登录
        2025-5-22

        联系方式

        违规信息
        违规:0

        荣誉勋章

          发表于 2025-4-19 10:01:46|显示全部楼层
          看帖不回帖都是耍流氓!
          我要说一句
          吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

          TA的专栏

          • 打卡等级:天魔菲尼斯

          今日最高分:0

          今日排行:未上榜

          等级头衔

          等級:哥布林

          活跃状态

          0

          主题

          969

          回帖

          184

          积分

          积分货币
          祝福
          482 颗
          灵魂
          1 颗
          玛雅
          41147 颗
          元宝
          0 锭
          积分
          984 枚
          注册时间
          2023-11-27
          最后登录
          2025-5-23

          联系方式

          违规信息
          违规:0

          荣誉勋章

            发表于 2025-4-19 19:22:02|显示全部楼层
            坚持回帖!
            我要说一句
            吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

            TA的专栏

            • 打卡等级:天魔菲尼斯

            今日最高分:0

            今日排行:未上榜

            等级头衔

            等級:哥布林

            活跃状态

            0

            主题

            940

            回帖

            178

            积分

            积分货币
            祝福
            467 颗
            灵魂
            1 颗
            玛雅
            38540 颗
            元宝
            0 锭
            积分
            954 枚
            注册时间
            2023-11-27
            最后登录
            2025-5-22

            联系方式

            违规信息
            违规:0

            荣誉勋章

              发表于 2025-4-19 19:48:46|显示全部楼层
              奇迹45网,一个特别注重情怀的地方!
              我要说一句
              吾爱一起玩儿,一个游戏爱好者的聚集地!《新会员请仔细阅读入坑须知!发布资源请阅读资源分享规则!》用户组达到[戈登]后可修改此签名!

              本版积分规则