• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Support on script globalevent

anotapreta

New Member
Joined
Mar 12, 2010
Messages
104
Reaction score
0
Support on script
i have errors

Lua:
-- {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"} exemplo


local config = {
lottery_hour = "10 Minutes", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
rewards_id = {8303}, -- Rewards ID
crystal_counts = 10, -- used only if on rewards_id you have crystal coins (ID: 2160).
website = "yes", -- Do you have `lottery` table in your database?
days = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"} -- days the weekend
}


function onThink(interval, lastExecution)

local players = getPlayersOnline()
local list = {}
for i, tid in ipairs(players) do
list[i] = tid 
end

local winner = list[math.random(1, #list)]
local random_item = config.rewards_id[math.random(1, #config.rewards_id)]
local item_name = getItemNameById(random_item)
local world = tonumber(getPlayerWorldId(winner))
local level = tonumber(getPlayerLevel(winner))

local maxgroupid = 2
local group = tonumber(getPlayerGroupId(winner))










// Only 50% of the online players(top leveis) have chance for win on lottery 

local str = nil
local limit = local limit = math.floor(#players / 2)
local query = db.getResult("SELECT `name`,`level` FROM `players` WHERE `group_id` <= 3 and `online` = 1 ORDER BY level DESC;")
local list = {}
for i = 1, limit do
str = query:getDataString("name")
list[i] = str
query:next()
end

local strX = nil
local limit = local limit = math.floor(#players / 2)
local query = db.getResult("SELECT `name`,`level` FROM `players` WHERE `group_id` <= 3 ORDER BY level DESC;")
local listX = {}
for i = 1, limit do
strX = query:getDataString("level")
listX[i] = strX
query:next()
end


    if getCreatureName(winner) ~= list[1] and getCreatureName(winner) ~= list[2] and getCreatureName(winner) ~= list[3] and getCreatureName(winner) ~= list[4] and getCreatureName(winner) ~= list[5] and getCreatureName(winner) ~= list[6] and getCreatureName(winner) ~= list[7] and getCreatureName(winner) ~= list[8] and getCreatureName(winner) ~= list[9] and getCreatureName(winner) ~= list[10] then


doBroadcastMessage('[LOTTERY SYSTEM] Winner: NO! ' .. getCreatureName(winner) .. ' did not win, because is needed to be among the top '..limit..' in level.')

  else
// Only 50% of the online players(top leveis) have chance for win on lottery 










if #list >= 10 and isInArray(config.days, os.date("%A")) then
if level >= 50 and group <= maxgroupid then
if(random_item == 2160) then
doPlayerAddItem(winner, random_item, config.crystal_counts)
doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: '.. config.crystal_counts ..' '.. item_name ..'s! Congratulations! (Next Lottery in '.. config.lottery_hour ..')')
else

doBroadcastMessage('[LOTTERY SYSTEM] Winner: '.. getCreatureName(winner) ..', Reward: '.. item_name ..'! 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`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. item_name .."', '".. world .."');")
end
end
end

// Only 50% of the online players(top leveis) have chance for win on lottery 
end
// Only 50% of the online players(top leveis) have chance for win on lottery 

return TRUE
end




Formula: total online/2 = Number of players with change for win on lottery
Sample: i have 20 online

20 / 2 = 10
Sample:
local limit = math.floor(#players / 2)

players = 10 >>> local limit = 10
only 10 players TOP Level (ONLINE) on server have chance for win on lottery

I tried to do, but it is very difficult.becuse need use:

I NEED HELP for i, tid in ipairs(players) do AND I NO KNOW
thanks
rep+




Basically I want to add this part to the above script.
Lua:
local str = nil
local limit = 10
local query = db.getResult("SELECT `name`,`level` FROM `players` WHERE `group_id` <= 3 and `online` = 1 ORDER BY level DESC;")
local list = {}
for i = 1, limit do
str = query:getDataString("name")
list[i] = str
query:next()
end
 
local strX = nil
local limit = 10
local query = db.getResult("SELECT `name`,`level` FROM `players` WHERE `group_id` <= 3 ORDER BY level DESC;")
local listX = {}
for i = 1, limit do
strX = query:getDataString("level")
listX[i] = strX
query:next()
end
 
 
    if getCreatureName(winner) ~= list[1] and getCreatureName(winner) ~= list[2] and getCreatureName(winner) ~= list[3] and getCreatureName(winner) ~= list[4] and getCreatureName(winner) ~= list[5] and getCreatureName(winner) ~= list[6] and getCreatureName(winner) ~= list[7] and getCreatureName(winner) ~= list[8] and getCreatureName(winner) ~= list[9] and getCreatureName(winner) ~= list[10] then
 
 
doBroadcastMessage('[LOTTERY SYSTEM] Winner: NO! ' .. getCreatureName(winner) .. ' did not win, because is needed to be among the top '..limit..' in level.')
 
  else


TFS 0.4 >> 9.54
 
Last edited:
Back
Top