• 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 Error in my script... TFS 0.4

bolero

MikeHere
Joined
Apr 13, 2009
Messages
1,146
Reaction score
12
Location
Venezuela
This is the error >.<

20j4xp3.jpg




Here is my script!!

Lua:
-- by vDk, klekSu
local config = {
    lottery_hour = "45 Min", -- Time to next lottery (real time you set on globalevents.xml, its only for broadcast message.)
    rewards_id = {2494, 2472, 2514, 2195, 2470, 2656, 7895, 2160}, -- Rewards ID
    crystal_counts = 20, -- used only if on rewards_id you have crystal coins (ID: 2160).
    website = "yes" -- Do you have `lottery` table in your database?
    }
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 = 0
                if(random_item == 2160) then
                        doPlayerAddItem(winner, random_item, config.crystal_counts)
                        doBroadcastMessage('[SISTEMA DE LOTERIA] Ganador: '.. getCreatureName(winner) ..', Premio: '.. config.crystal_counts ..' '.. item_name ..'s! Felicidades! (Siguiente Loteria En '.. config.lottery_hour ..')')
                else
                        doBroadcastMessage('[SISTEMA DE LOTERIA] Ganador: '.. getCreatureName(winner) ..', Premio: '.. item_name ..'! Felicidades! (Siguiente Loteria En '.. 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
    return TRUE
end
 
Code:
-- by vDk, klekSu
local t = {
	lottery_hour = "45 Min", -- Time to next lottery (real time you set on globalevents.xml, it's only for broadcast message.)
	rewards_id = {2494, 2472, 2514, 2195, 2470, 2656, 7895, 2160}, -- Rewards ID
	stackable_amount = 20,
	website = true -- Do you have `lottery` table in your database?
}
function onThink(interval, lastExecution)
	local list = getPlayersOnline()
	local winner, item = list[math.random(#list)], t.rewards_id[math.random(#t.rewards_id)]
	local stackable = getItemInfo(item).stackable
	doPlayerAddItem(winner, item, stackable and t.stackable_amount or 1)
	doBroadcastMessage('[SISTEMA DE LOTERIA] Ganador: '.. getCreatureName(winner) ..', Premio: '.. (stackable and t.stackable_amount ..' ' or '') .. (stackable and getItemInfo(item).plural or getItemNameById(item)) .. '! Felicidades! (Siguiente Loteria En '.. t.lottery_hour ..')')
	if t.website then
		db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(item) .."', '".. getConfigValue('worldId') .."');")
	end
	return true
end
 
Trying to reproduce under same conditions:
Code:
local list = {}
return list[math.random(#list)]
Code:
input:2: bad argument #1 to 'random' (interval is empty)
For some reason your getPlayersOnline() returned an empty table.
 
Worked perfectly on 0.3.6pl1
Try the mod version:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<mod name="Lottery" enabled="yes">
	<config name="lottery_config"><![CDATA[
		t = {
			lottery_hour = "45 Min", -- Time to next lottery (you set the real time on interval, it's only for the broadcast message.)
			rewards_id = {2494, 2472, 2514, 2195, 2470, 2656, 7895, 2160}, -- ID's of rewards
			stackable_amount = 20, -- amount, if this it's a stackable item
			website = true -- Do you have `lottery` table in your database?
		}
	]]></config>
	<globalevent name="lottery" interval="2700" event="buffer"><![CDATA[
		domodlib('lottery_config')
		local list = getPlayersOnline()
		if #list > 0 then
			local winner, item = list[math.random(#list)], t.rewards_id[math.random(#t.rewards_id)]
			local stackable = getItemInfo(item).stackable
			doPlayerAddItem(winner, item, stackable and t.stackable_amount or 1)
			doBroadcastMessage('[SISTEMA DE LOTERIA]\nGanador: '.. getCreatureName(winner) ..',\nPremio: '.. (stackable and t.stackable_amount ..' ' or '') .. (stackable and getItemInfo(item).plural or getItemNameById(item)) .. '!\nFelicidades!\n(Siguiente Loteria En '.. t.lottery_hour ..')')
			if t.website then
				db.executeQuery("INSERT INTO `lottery` (`name`, `item`, `world_id`) VALUES ('".. getCreatureName(winner) .."', '".. getItemNameById(item) .."', '".. getConfigValue('worldId') .."');")
			end
		end
		return true
	]]></globalevent>
</mod>
If it's still the same error, then it's a bug with 0.4
 
Multiply interval with 1000, because it's in milliseconds in 0.4
Code:
	<globalevent name="lottery" interval="2700[B][COLOR="Red"]000[/COLOR][/B]" event="buffer"><![CDATA[
 
If I want 45minutes how miliseconds need put? 4500000??
ffs.

45 * 60 * 1000

I have to quote myself <_<:
Multiply interval with 1000, because it's in milliseconds in 0.4
Code:
	<globalevent name="lottery" interval="[SIZE="7"]2700[B][COLOR="Red"]000[/COLOR][/B][/SIZE]" event="buffer"><![CDATA[
ۤ
ۤ
 
Back
Top