【dp插件】随机点券道具
刚进贴吧第一次分享就是这个东西,炒炒冷饭,后面优化了一下 可以自定义概率 ```-- 点券增加券(不用就删掉这一大段)!
item_handler = 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
``` 你不是天天搞frida,咋又玩dp了呀
直接random随机数啊 开头和结尾的三个点也需要吗,我记得结尾一般都是到end 请问这个是道具还是刷图掉落之类的
页:
[1]