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

LOTTERY SYSTEM FOR PROMOTED

nilvagner

Long live the otland.net
Joined
May 3, 2010
Messages
118
Reaction score
3
Location
Brazil
Can anyone help me with this script?
I need him to deliver the items, only for promoted players.


Lua:
local lottery = GlobalEvent("lottery")

local config = {
    interval = "5 minutes.",
    rewards = {
    [3040] = 3,     -- GOLD NUGGET
    [3053] = 1,     -- TIME RING
    [2995] = 1,     -- PIGGY BANK
    [8072] = 1,     -- SPELLBOOK OF ENLIGHTENMENT
    [7367] = 1,     -- ENCHANTED SPEAR
    [8043] = 1,     -- FOCUS CAPE
    [3725] = 12,     -- BROWN MUSHROOMS
    [5710] = 1,     -- LIGHT SHOVEL
    [3567] = 1,     -- BLUE ROBE
    [2995] = 1,     -- PIGGY BANK
    [3055] = 1,     -- PLATINUM AMULET
    [5908] = 1,     -- OBSIDIAN KNIFE
    [3414] = 1     -- MASTERMIND SHIELD
    },
    website = false
}

function lottery.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("Congratulations " .. winner:getName() .. " won " .. name .. ". Next lottery in " .. config.interval .. "")

    return true
end

lottery:interval(300000) --- Exemple: 60000 = 1 minute.
lottery:register()

Since now. Thanks!
 
Can anyone help me with this script?
I need him to deliver the items, only for promoted players.


Lua:
local lottery = GlobalEvent("lottery")

local config = {
    interval = "5 minutes.",
    rewards = {
    [3040] = 3,     -- GOLD NUGGET
    [3053] = 1,     -- TIME RING
    [2995] = 1,     -- PIGGY BANK
    [8072] = 1,     -- SPELLBOOK OF ENLIGHTENMENT
    [7367] = 1,     -- ENCHANTED SPEAR
    [8043] = 1,     -- FOCUS CAPE
    [3725] = 12,     -- BROWN MUSHROOMS
    [5710] = 1,     -- LIGHT SHOVEL
    [3567] = 1,     -- BLUE ROBE
    [2995] = 1,     -- PIGGY BANK
    [3055] = 1,     -- PLATINUM AMULET
    [5908] = 1,     -- OBSIDIAN KNIFE
    [3414] = 1     -- MASTERMIND SHIELD
    },
    website = false
}

function lottery.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("Congratulations " .. winner:getName() .. " won " .. name .. ". Next lottery in " .. config.interval .. "")

    return true
end

lottery:interval(300000) --- Exemple: 60000 = 1 minute.
lottery:register()

Since now. Thanks!
only promoted vocations (id > 4)
Lua:
local lottery = GlobalEvent("lottery")

local config = {
    interval = "5 minutes.",
    rewards = {
    [3040] = 3,     -- GOLD NUGGET
    [3053] = 1,     -- TIME RING
    [2995] = 1,     -- PIGGY BANK
    [8072] = 1,     -- SPELLBOOK OF ENLIGHTENMENT
    [7367] = 1,     -- ENCHANTED SPEAR
    [8043] = 1,     -- FOCUS CAPE
    [3725] = 12,     -- BROWN MUSHROOMS
    [5710] = 1,     -- LIGHT SHOVEL
    [3567] = 1,     -- BLUE ROBE
    [2995] = 1,     -- PIGGY BANK
    [3055] = 1,     -- PLATINUM AMULET
    [5908] = 1,     -- OBSIDIAN KNIFE
    [3414] = 1     -- MASTERMIND SHIELD
    },
    website = false
}

function lottery.onThink(interval)
    local players = {}
    for _, player in ipairs(Game.getPlayers()) do
        if not player:getGroup():getAccess() then
           if player:getVocation():getId() > 4 then
               table.insert(players, player)
           end
        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("Congratulations " .. winner:getName() .. " won " .. name .. ". Next lottery in " .. config.interval .. "")

    return true
end

lottery:interval(300000) --- Exemple: 60000 = 1 minute.
lottery:register()
 
Thanks for the help my dear!

Now I will search how to add this function:

{itemId = 3725, minCount = 1, maxCount = 12, chance = 999}, -- -- BROWN MUSHROOMS
{itemId = 3040, minCount = 1, maxCount = 6, chance = 1000} -- GOLD NUGGET
 
@Shadow_ Only valid with 4 main vocations, but as there can be as many promotion levels it's not as easy :)
I thoguht that there's already some function but there's even no way to get "fromvoc" attribute of vocation via LUA.
But as first vocations has "fromvoc" set to itselft we could utilize that (check if demotedVocation ID is same as current vocation ID)
We could create some function on Player and there's already something similar on Vocation:

Lua:
function Vocation.getBase(self)
    local base = self
    while base:getDemotion() do
        base = base:getDemotion()
    end
    return base
end

Lua:
function Player.isPromoted(self)
   local vocation = self:getVocation()
   local baseVocationId = vocation:getBase():getId()
   return vocation:getId() ~= baseVocationId
end
Or to limit number of getDemotion calls, simply check vocation:getDemotion():getId() ~= vocation:getId()

As currently NPC's in TFS utilize some storageValue to check whether player is promoted, it's not realy guaranted that all possible code paths that are to promote players do set it, so maybe worth to propose, or maybe i'm totaly wrong :D
 
Last edited:
@Shadow_ Only valid with 4 main vocations, but as there can be as many promotion levels it's not as easy :)
I thoguht that there's already some function but there's even no way to get "fromvoc" attribute of vocation via LUA.
But as first vocations has "fromvoc" set to itselft we could utilize that (check if demotedVocation ID is same as current vocation ID)
We could create some function on Player and there's already something similar on Vocation:

Lua:
function Vocation.getBase(self)
    local base = self
    while base:getDemotion() do
        base = base:getDemotion()
    end
    return base
end

Lua:
function Player:isPromoted()
   local vocation = self:getVocation()
   local baseVocationId = vocation:getBase():getId()
   return vocation:getId() ~= baseVocationId
end
Or to limit number of getDemotion calls, simply check vocation:getDemotion():getId() ~= vocation:getId()

As currently NPC's in TFS utilize some storageValue to check whether player is promoted, it's not realy guaranted that all possible code paths that are to promote players do set it, so maybe worth to propose, or maybe i'm totaly wrong :D
You said promoted players

Promoted means this promotion have base Promotion (whatever the promotion level)
1,2,3,4 non promoted (not included in the lottery)
5,6,7,8 standard promotion (included)
9,10,11,12,13,14,15,16,1000000 to infinity promotions included

so i don't really get what you mean.
 
Yes and if you’re not promoted then getBase() would always return same vocation (fromvoc points to same voc):
Code:
Vocation(1):getBase() // 1
Vocation(2):getBase() // 2
Vocation(3):getBase() // 3
Vocation(4):getBase() // 4

And for all the other vocations (whatever promotion level) call ‘getBase()’ would always return some vocation which is different from self (fromvoc attribute)

Ofc its only a theory as I didn’t tried this code yet ;)
 
People! I don't know much about scripting...
I need the lottery system to deliver only to these vocations:

<vocation id="5" clientid="13" baseid="1" name="Master Sorcerer"
<vocation id="6" clientid="14" baseid="2" name="Elder Druid"
<vocation id="7" clientid="12" baseid="3" name="Royal Paladin"
<vocation id="8" clientid="11" baseid="4" name="Elite Knight"

Thanks for all the help!
 
@lursky

Can you help me with this function:


{itemId = 3725, minCount = 1, maxCount = 12, chance = 999}, -- -- BROWN MUSHROOMS {

itemId = 3040, minCount = 1, maxCount = 6, chance = 1000 } -- GOLD NUGGE


To insert in my file
Thank you very much! I have no knowledge in this area, and I need to insert a chance in some items for the beginner player.
 
Back
Top