• 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!

TFS 1.2 Lottery System

God Mythera

Veteran OT User
Joined
Aug 11, 2012
Messages
2,048
Solutions
2
Reaction score
256
Location
United States
So i am using this lottery system, but i dont believe it works with TFS 1.2 i am trying to make it so GM's and God's cannot get lottery rewards

Could someone possibly help me? ;d

data/globalevents/scripts/lottery.lua
Code:
--[[
    ACCOUNT_TYPE_NORMAL = 1,
    ACCOUNT_TYPE_TUTOR = 2,
    ACCOUNT_TYPE_SENIORTUTOR = 3,
    ACCOUNT_TYPE_GAMEMASTER = 4,
    ACCOUNT_TYPE_GOD = 5

]]

local config = {
    interval = "1 hour",
    rewards = {[2160] = 5},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function onThink(interval)
    if Game.getPlayerCount() == 0 then
        return true
    end

    local players = {}

    for _, player in ipairs(Game.getPlayers()) do
        if player:getAccountType() <= 2 then
            table.insert(players, player)
        end
    end

    local winner  = players[math.random(#players)]

    local items = {}
    for itemid, count in pairs(config.rewards) do
        items[#items + 1] = itemid
    end

    local itemid = items[math.random(1, #items)]
    local amount = config.rewards[itemid]
    winner:addItem(itemid, amount)

    local it   = ItemType(itemid)
    local name = ""
    if amount == 1 then
        name = it:getArticle() .. " " .. it:getName()
    else
        name = amount .. " " .. it:getPluralName()
    end

    broadcastMessage("[LOTTERY SYSTEM] " .. winner:getName() .. " won " .. name .. "! Congratulations! (Next lottery in " .. config.interval .. ")")

    if config.website then
        db.query("INSERT INTO `lottery` (`name`, `item`) VALUES (\"".. db.escapeString(winner:getName()) .."\", \"".. db.escapeString(it:getName()) .."\");")
    end
    return true
end

data/xml/groups.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>
 
Last edited:
Could someone possibly help me? ;d
change this:
Code:
for _, player in ipairs(Game.getPlayers()) do
if player:getAccountType() <= 2 then
table.insert(players, player)
end
end
to
Code:
    for k, v in ipairs(Game.getPlayers()) do
        if not v:getGroup():getAccess() then
        table.insert(players, v)
        end
    end
your mistakes here:
1. accountType does not mean gruop or access.
2. avoid use keyword player to variables in tfs 1.x scripts, it's a userdata, which means lua maybe in some cases will cannot concatenate the table, since it's another table, tho in this case i don't know if player userdata is returned.
3. is easier to get if is player a super user by using getGroup():getAccess(), since it returns a boolean instead a int like accountGetType.
 
Last edited:
change this:
Code:
for _, player in ipairs(Game.getPlayers()) do
if player:getAccountType() <= 2 then
table.insert(players, player)
end
end
to
Code:
    for k, v in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
        table.insert(players, v)
        end
    end
your mistakes here:
1. accountType does not mean gruop or access.
2. avoid use keyword player to variables in tfs 1.x scripts, it's a userdata, which means lua maybe in some cases will cannot concatenate the table, since it's another table, tho in this case i don't know if player userdata is returned.
3. is easier to get if is player a super user by using getGroup():getAccess(), since it returns a boolean instead a int like accountGetType.
Thanks i will test it when my server is online later :p
 
Well i tested it and it didnt work :| i will just try to get a working lottery system later. I am sure it works but i dont want GM's getting rewards.
 
change this:
Code:
for _, player in ipairs(Game.getPlayers()) do
if player:getAccountType() <= 2 then
table.insert(players, player)
end
end
to
Code:
    for k, v in ipairs(Game.getPlayers()) do
        if not v:getGroup():getAccess() then
        table.insert(players, v)
        end
    end
your mistakes here:
1. accountType does not mean gruop or access.
2. avoid use keyword player to variables in tfs 1.x scripts, it's a userdata, which means lua maybe in some cases will cannot concatenate the table, since it's another table, tho in this case i don't know if player userdata is returned.
3. is easier to get if is player a super user by using getGroup():getAccess(), since it returns a boolean instead a int like accountGetType.
The problem here is this this code returns a number so if this returns anything except nil the value of v will not be inserted into the players table.
Code:
if not v:getGroup():getAccess() then
Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>
Since both his gamemaster and god groups contain an access level of 1 you would simply assign the the condition as so.
Code:
if v:getGroup():getAccess() < 1 then
 
Last edited:
The problem here is this this code returns a number so if this returns anything except nil the value of v will not be inserted into the players table.
Code:
if not v:getGroup():getAccess() then
Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>
Since both his gamemaster and god groups contain an access level of 1 you would simply assign the the condition as so.
Code:
if v:getGroup():getAccess() < 1 then
I will try this thanks.
 
The problem here is this this code returns a number so if this returns anything except nil the value of v will not be inserted into the players table.
Code:
if not v:getGroup():getAccess() then
Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
</groups>
Since both his gamemaster and god groups contain an access level of 1 you would simply assign the the condition as so.
Code:
if v:getGroup():getAccess() < 1 then
So i tried it and GM's still get reward :\

Code:
11:17 [LOTTERY SYSTEM] GM Oblivion won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
11:47 [LOTTERY SYSTEM] Dr Snuggles won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
12:17 [LOTTERY SYSTEM] Slinky won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
12:47 [LOTTERY SYSTEM] GM Oblivion won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
13:17 [LOTTERY SYSTEM] Slappyninja won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
13:47 [LOTTERY SYSTEM] Ivory won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
14:17 [LOTTERY SYSTEM] Syth won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
14:47 [LOTTERY SYSTEM] Ruforan won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
15:17 [LOTTERY SYSTEM] Ownez won 3 crystal coins! Congratulations! (Next lottery in 30 minutes)
 
whats ur script?
Code:
--[[
    ACCOUNT_TYPE_NORMAL = 1,
    ACCOUNT_TYPE_TUTOR = 2,
    ACCOUNT_TYPE_SENIORTUTOR = 3,
    ACCOUNT_TYPE_GAMEMASTER = 4,
    ACCOUNT_TYPE_GOD = 5

]]

local config = {
    interval = "30 minutes",
    rewards = {[2160] = 3},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function onThink(interval)
    if Game.getPlayerCount() == 0 then
        return true
    end

    local players = {}

    for _, player in ipairs(Game.getPlayers()) do
        if player:getAccountType() <= 1 then
            table.insert(players, player)
        end
    end

    local winner  = players[math.random(#players)]

    local items = {}
    for itemid, count in pairs(config.rewards) do
        items[#items + 1] = itemid
    end

    local itemid = items[math.random(1, #items)]
    local amount = config.rewards[itemid]
    winner:addItem(itemid, amount)

    local it   = ItemType(itemid)
    local name = ""
    if amount == 1 then
        name = it:getArticle() .. " " .. it:getName()
    else
        name = amount .. " " .. it:getPluralName()
    end

    broadcastMessage("[LOTTERY SYSTEM] " .. winner:getName() .. " won " .. name .. "! Congratulations! (Next lottery in " .. config.interval .. ")")

    if config.website then
        db.query("INSERT INTO `lottery` (`name`, `item`) VALUES (\"".. db.escapeString(winner:getName()) .."\", \"".. db.escapeString(it:getName()) .."\");")
    end
    return true
end
 
try changing
player:getAccountType() <= 1
to
player:getAccountType() == 0 and not player:getGroup():getAccess()
also after local winner = ~ add
print(winner:getAccountType(), winner:getGroup():getAccess()) and tell me what it prints when/if a gm wins
 
i know that, but his code shouldnt be giving it to gms from the start, but for some reason it seems to do
also in add exclude gms like this could return errors while indexing winner as a player if there is no players but gms, the code that i provide has no problems, i'll rework a bit this code later, he must be doing wrongly what i said.
 
also in add exclude gms like this could return error while indexing winner as a player if there is no players only but gms.
if definitely will throw errors if there are no players, he should change
local winner = players[math.random(#players)]
to something like
local participants = #players
if participants <= 0 then
return false
end
local winner = player[math.random(participants)]
or something along those lines
 
@God Mythera
Code:
local config = {
    interval = "30 minutes",
    rewards = {[2160] = 3},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end

    local c = #players
    if c <= 0 then
        return true
    end

    local winner  = players[math.random(#players)]

    local items = {}
    for itemid, count in pairs(config.rewards) do
        items[#items + 1] = itemid
    end

    local itemid = items[math.random(1, #items)]
    local amount = config.rewards[itemid]
    winner:addItem(itemid, amount)

    local it   = ItemType(itemid)
    local name = ""
    if amount == 1 then
        name = it:getArticle() .. " " .. it:getName()
    else
        name = amount .. " " .. it:getPluralName()
    end

    broadcastMessage("[LOTTERY SYSTEM] " .. winner:getName() .. " won " .. name .. "! Congratulations! (Next lottery in " .. config.interval .. ")")

    if config.website then
        db.query("INSERT INTO `lottery` (`name`, `item`) VALUES (\"".. db.escapeString(winner:getName()) .."\", \"".. db.escapeString(it:getName()) .."\");")
    end
    return true
end
try it, i see no reason why it wouldnt work.
 
@God Mythera
Code:
local config = {
    interval = "30 minutes",
    rewards = {[2160] = 3},
    -- [itemid] = count; [2160] = 50 - it gives 50 crystal coins
    website = false
}

function onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
            table.insert(players, player)
        end
    end

    local c = #players
    if c <= 0 then
        return true
    end

    local winner  = players[math.random(#players)]

    local items = {}
    for itemid, count in pairs(config.rewards) do
        items[#items + 1] = itemid
    end

    local itemid = items[math.random(1, #items)]
    local amount = config.rewards[itemid]
    winner:addItem(itemid, amount)

    local it   = ItemType(itemid)
    local name = ""
    if amount == 1 then
        name = it:getArticle() .. " " .. it:getName()
    else
        name = amount .. " " .. it:getPluralName()
    end

    broadcastMessage("[LOTTERY SYSTEM] " .. winner:getName() .. " won " .. name .. "! Congratulations! (Next lottery in " .. config.interval .. ")")

    if config.website then
        db.query("INSERT INTO `lottery` (`name`, `item`) VALUES (\"".. db.escapeString(winner:getName()) .."\", \"".. db.escapeString(it:getName()) .."\");")
    end
    return true
end
try it, i see no reason why it wouldnt work.
Ok i will try i in a bit thanks.
 
Back
Top