|
楼主 |
发表于 2024-10-6 13:58:32
|
显示全部楼层
```
-- 点券增加券(不用就删掉这一大段)!
item_handler[202403101] = function(user, item_id)
-- 每个数值和其相对应的概率列表
local values_probabilities = {
{value = 1000, probability = 0.8}, -- 概率为 80%
{value = 2000, probability = 0.10}, -- 概率为 10%
{value = 5000, probability = 0.06}, -- 概率为 6%
{value = 8000, probability = 0.03}, -- 概率为 3%
{value = 10000, probability = 0.01}, -- 概率为 1%
}
-- 计算总概率
local total_probability = 0
for _, data in ipairs(values_probabilities) do
total_probability = total_probability + data.probability
end
-- 生成随机权重
local random_probability = math.random() * total_probability
-- 选择固定数值
local selected_value = nil
local accumulated_probability = 0
for _, data in ipairs(values_probabilities) do
accumulated_probability = accumulated_probability + data.probability
if accumulated_probability >= random_probability then
selected_value = data.value
break
end
end
-- 增加点券并发送通知
user:ChargeCera(selected_value)
local message = string.format("恭喜您获得%d点券!", selected_value)
user:SendNotiPacketMessage(message, 1)
end
``` |
|