local mapName = getbaseinfo(actor, 3) or "" -- 获取地图名称
local targetMapName4 = "上古战场" -- 你的目标地图名称
-- 2. 判断是否在目标地图
if mapName == targetMapName4 then
-- 获取当前杀怪数量
local currentKillCount = lib:getvalueb(actor, "u32") or 0
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-03-12 00:34:29 |
👁️ 阅读: 19
```lua
local mapName = getbaseinfo(actor, 3) or "" -- 获取地图名称
local targetMapName4 = "上古战场" -- 你的目标地图名称
-- 2. 判断是否在目标地图
if mapName == targetMapName4 then
-- 生成1-100的随机数
local randomNum = math.random(1, 100)
-- 25%概率判断
if randomNum <= 25 then
-- 获取当前杀怪数量
local currentKillCount = lib:getvalueb(actor, "u32") or 0
p(lib:getvalueb(actor, "u32"))
currentKillCount = tonumber(currentKillCount) or 0
-- 增加杀怪数量
currentKillCount = currentKillCount + 1
-- 保存到玩家变量
lib:setvalueb(actor, "u32", currentKillCount)
-- 显示消息
lib:msg(actor, "你在上古战场已获得碎片:" .. currentKillCount)
end
end
```
主要修改:
1. 添加了 `math.random(1, 100)` 生成1-100的随机数
2. 增加了 `if randomNum <= 25 then` 判断,只有25%的概率会执行杀怪计数逻辑
3. 保持了原有的地图判断和变量操作逻辑
这样修改后,只有25%的几率会让U32变量+1,符合你的需求。
```lua
local mapName = getbaseinfo(actor, 3) or "" -- 获取地图名称
local targetMapName4 = "上古战场" -- 你的目标地图名称
-- 2. 判断是否在目标地图
if mapName == targetMapName4 then
-- 生成1-100的随机数
local randomNum = math.random(1, 100)
-- 25%概率判断
if randomNum <= 25 then
-- 获取当前杀怪数量
local currentKillCount = lib:getvalueb(actor, "u32") or 0
p(lib:getvalueb(actor, "u32"))
currentKillCount = tonumber(currentKillCount) or 0
-- 增加杀怪数量
currentKillCount = currentKillCount + 1
-- 保存到玩家变量
lib:setvalueb(actor, "u32", currentKillCount)
-- 显示消息
lib:msg(actor, "你在上古战场已获得碎片:" .. currentKillCount)
end
end
```
主要修改:
1. 添加了 `math.random(1, 100)` 生成1-100的随机数
2. 增加了 `if randomNum <= 25 then` 判断,只有25%的概率会执行杀怪计数逻辑
3. 保持了原有的地图判断和变量操作逻辑
这样修改后,只有25%的几率会让U32变量+1,符合你的需求。
← 返回问答库