<mod name="Lottery System" version="1.5" author="vDk" contact="[email protected]" enabled="yes">
<config name="lottery_config"><![CDATA[
config = {
lottery_hour = "1 Hour", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
rewards_id = {8922, 8910, 2472, 2514, 2160}, -- Rewards ID
crystal_counts = 10, -- Used only if on rewards_id is crystal coin (ID: 2160).
website = "no" -- Only if you have php scripts and table `lottery` in your database!
}
]]></config>
<globalevent name="lottery" interval="5000" event="script"><![CDATA[
domodlib('lottery_config')
function onThink(interval, lastExecution)
if(getWorldCreatures(0) == 0)then
return true
end
local list = {}
for i, tid in ipairs(getPlayersOnline()) do
list[i] = tid
end
local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. config.crystal_counts .. " " .. getItemNameById(random_item) .. "s! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
else
doBroadcastMessage("[LOTTERY SYSTEM] Winner: " .. getCreatureName(winner) .. ", Reward: " .. getItemNameById(random_item) .. "! Congratulations! (Next Lottery in " .. config.lottery_hour .. ")")
doPlayerAddItem(winner, random_item, 1)
end
if(config.website == "yes") then
db.executeQuery("INSERT INTO `lottery` (`name`, `item`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(random_item) .."');")
end
return true
end
]]></globalevent>
</mod>
local ITEMS =
{
[1] = {3971}, -- charmer tiara
[2] = {3963}, -- templar scytheblade
[3] = {2195} -- boots of haste
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
for k, v in pairs(ITEMS) do
if(isInArray(k, math.random(100))) then
local item = doCreateItemEx(cid, v, 1)
if(doPlayerAddItemEx(cid, item) ~= RETURNVALUE_NOERROR) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_CONTAINERNOTENOUGHROOM)
else
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(k).name .. ".", MESSAGE_EVENT_ADVANCE)
end
end
end
return true
end
<action [action, unique, item]id="XXXX" event="script" value="other/randomitem.lua"/>
local ITEMS =
{
[1] = {3971}, -- charmer tiara
[2] = {3963}, -- templar scytheblade
[3] = {2195} -- boots of haste
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
for k, v in pairs(ITEMS) do
if(math.random(100) == k) then
local backpack = doCreateItemEx(cid, v, 1)
if(doPlayerAddItemEx(cid, backpack) ~= RETURNVALUE_NOERROR) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_CONTAINERNOTENOUGHROOM)
else
doPlayerBroadcastMessage(cid, "The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(k).name .. " ")
end
end
end
return true
end
Updated. Try now.
Why not, then how I'm supposed to check the value of math.random?![]()
local ITEMS = {3971, 3963, 2195}
function onUse(cid, item, fromPosition, itemEx, toPosition)
local random = ITEMS[math.random(1, #ITEMS)]
if(doPlayerAddItem(cid, random, 1) ~= RETURNVALUE_NOERROR) then
doPlayerSendDefaultCancel(cid, RETURNVALUE_CONTAINERNOTENOUGHROOM)
else
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(random).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
end
return true
end
--Daniel Couillard: Blood BlvD Ot.
function onUse(cid, item, frompos, item2, topos)
---Config---
--ADD ITEM IDS HERE--
local itemOneID =
local itemTwoID =
local itemThreeID =
local itemFourID =
local itemFiveID =
local rand = math.random(1,5)
--/Config---
if item.itemid == item.itemid then
if rand == 1 then
doPlayerAddItem(cid,itemOneID,1)
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(itemOneID).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
elseif rand == 2 then
doPlayerAddItem(cid,itemTwoID,1)
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(itemTwoID).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
elseif rand == 3 then
doPlayerAddItem(cid,itemThreeID,1)
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(itemThreeID).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
elseif rand == 4 then
doPlayerAddItem(cid,itemFourID,1)
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(itemFourID).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
elseif rand == 5 then
doPlayerAddItem(cid,itemFiveID,1)
doBroadcastMessage("The player " .. getCreatureName(cid) .. " won a " .. getItemInfo(itemFiveID).name .. ".", MESSAGE_EVENT_ADVANCE)
doRemoveItem(item.uid, 1)
else
end
end
return true
end