楼主: 李静官

[未归类主题(有空慢慢分)] 【LUA】3.3.5a随机属性LUA脚本

  [复制链接]

528

时沙

0

精华

44

主题

声望: 1541   虚弱: 0

Lv.4(锻造者)

炉石瓦格里的标记

发表于 2026-2-5 09:22:52 | 显示全部楼层
  1. -- 修复版:随机附魔核心脚本
  2. function RollEnchant(item)
  3.     local rarityRoll = math.random(100)  -- 补local,规范变量作用域
  4.     local itemClass = ""
  5.     if (item:GetClass() == 2) then
  6.         itemClass = "WEAPON"
  7.     elseif (item:GetClass() == 4) then
  8.         itemClass = "ARMOR"
  9.     else
  10.         return nil  -- 非武器/护甲直接返回,避免无效查询
  11.     end
  12.     -- 修复MYSQL判断NULL的语法:NULL不能用=,必须用IS NULL;增加括号保证逻辑优先级
  13.     local tier = 1
  14.     if rarityRoll <= 44 then
  15.         tier = 1
  16.     elseif rarityRoll <= 64 then
  17.         tier = 2
  18.     elseif rarityRoll <= 79 then
  19.         tier = 3
  20.     elseif rarityRoll <= 92 then
  21.         tier = 4
  22.     else
  23.         tier = 5
  24.     end
  25.     -- 重构查询语句:修复NULL判断+括号分组逻辑+拼接itemSubClass
  26.     local itemSubClass = item:GetSubClass()
  27.     local queryStr = string.format(
  28.         "SELECT enchantID FROM item_enchantment_random_tiers WHERE tier=%d AND ( (exclusiveSubClass IS NULL AND class='%s') OR exclusiveSubClass=%d OR class='ANY' ) ORDER BY RAND() LIMIT 1",
  29.         tier, itemClass, itemSubClass
  30.     )
  31.     local query = WorldDBQuery(queryStr)
  32.     if query then  -- 增加空判断,避免查询无结果时报错
  33.         return query:GetUInt32(0)
  34.     else
  35.         return nil
  36.     end
  37. end
  38. function OnLoot(event, player, item, count)
  39.     local slotBools = {}
  40.     local slotIDs = {}
  41.     local its = 0  -- 附魔槽位ID(服务端附魔槽位对应不同数值)
  42.     -- 修复:后续判断统一用对应roll变量,原脚本错误用boolRoll2判断3/4槽位
  43.     local boolRoll1 = math.random(100)
  44.     if boolRoll1 >= 60 then
  45.         slotBools[1] = true
  46.         slotIDs[1] = RollEnchant(item)
  47.     else
  48.         slotBools[1] = false
  49.     end
  50.     local boolRoll2 = math.random(100)
  51.     if boolRoll2 >= 65 and slotBools[1] then
  52.         slotBools[2] = true
  53.         slotIDs[2] = RollEnchant(item)
  54.     else
  55.         slotBools[2] = false
  56.     end
  57.     local boolRoll3 = math.random(100)
  58.     if boolRoll3 >= 70 and slotBools[2] then  -- 修复:用boolRoll3而非boolRoll2
  59.         slotBools[3] = true
  60.         slotIDs[3] = RollEnchant(item)
  61.     else
  62.         slotBools[3] = false
  63.     end
  64.     local boolRoll4 = math.random(100)
  65.     if boolRoll4 >= 75 and slotBools[3] then  -- 修复:用boolRoll4而非boolRoll2
  66.         slotBools[4] = true
  67.         slotIDs[4] = RollEnchant(item)
  68.     else
  69.         slotBools[4] = false
  70.     end
  71.     -- 给物品添加附魔:仅武器/护甲生效,遍历有效槽位
  72.     if slotBools[1] and (item:GetClass() == 2 or item:GetClass() == 4) then
  73.         for i, id in ipairs(slotIDs) do
  74.             if id then  -- 过滤无效的附魔ID
  75.                 if its == 2 then
  76.                     its = its + 3  -- 槽位间隔(服务端定制逻辑,保留)
  77.                 end
  78.                 if slotBools[i] then
  79.                     item:SetEnchantment(id, its)  -- SetEnchantment(附魔ID, 槽位ID)
  80.                     its = its + 1
  81.                 end
  82.             end
  83.         end
  84.     end
  85. end
  86. -- 注册拾取事件:32 = PLAYER_EVENT_ON_LOOT_ITEM(玩家拾取物品时触发)
  87. RegisterPlayerEvent(32, OnLoot)
复制代码
回复

使用道具 举报

528

时沙

0

精华

44

主题

声望: 1541   虚弱: 0

Lv.4(锻造者)

炉石瓦格里的标记

发表于 2026-2-5 09:23:14 | 显示全部楼层

2个核心问题 修复了下
[发帖际遇]: xuheng12得到一根金属香蕉,与泰奶奶达成某种不可告人的交易,获得71 金币. 幸运榜 / 衰神榜
回复

使用道具 举报

快速回复 返回顶部 返回列表