Code:
The problem [getPlayerAccess check]:
Error:
Only player online is a character with access over 1, any ideas why the error occurs? Just getting back into the coding world and thought I did everything right but apparently not, should there be an "else return true" to close the check if there is only admins online?
Lua:
local config = {
lottery_hour = "1 Hour", -- Time to next lottery (only for broadcast message, real time you can set on globalevents.xml)
rewards_id = {2195, 2492, 2160, 7404, 2536, 2656, 2323, 2171, 2169, 2516}, -- Rewards ID
crystal_counts = 2, -- Used only if on rewards_id is crystal coin (ID: 2160).
website = "yes" -- Only if you have php scripts and table `lottery` in your database!
}
function onThink(interval, lastExecution)
if getWorldCreatures(0) > 0 then
local list = {}
for i, tid in ipairs(getPlayersOnline()) do
if getPlayerAccess(cid) <= 2 then
list[i] = tid
end
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
return true
end
The problem [getPlayerAccess check]:
Lua:
if getWorldCreatures(0) > 0 then
local list = {}
for i, tid in ipairs(getPlayersOnline()) do
if getPlayerAccess(cid) <= 2 then
list[i] = tid
end
end
Error:
Code:
[6:40:02.401] [Error - GlobalEvent Interface]
[6:40:02.401] data/globalevents/scripts/lottery.lua:onThink
[6:40:02.402] Description:
[6:40:02.402] (internalGetPlayerInfo) Player not found when requesting player info #1
[6:40:02.402] [Error - GlobalEvent Interface]
[6:40:02.402] data/globalevents/scripts/lottery.lua:onThink
[6:40:02.402] Description:
[6:40:02.402] data/globalevents/scripts/lottery.lua:12: attempt to compare boolean with number
[6:40:02.402] stack traceback:
[6:40:02.402] data/globalevents/scripts/lottery.lua:12: in function <data/globalevents/scripts/lottery.lua:8>
Only player online is a character with access over 1, any ideas why the error occurs? Just getting back into the coding world and thought I did everything right but apparently not, should there be an "else return true" to close the check if there is only admins online?
Last edited: