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

Daily monster draw with percentage bonus experience and random loot.

ikaro22

New Member
Joined
Dec 17, 2019
Messages
22
Reaction score
0
Good morning, I would like help with a script that would draw a daily monster with X daily experience bonus and random loot between 0 and 40%.

example: image below.

base: tibia 8.60, otx.
 

Attachments

Solution
Lua:
local loot_bonus = math.random(10, 40)  --  10% to 40%
local ignoredList = {1987}
function addBonusLoot(position, name)
        for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            break
        end
    end
        local newRate = (1 + (loot_bonus/100)) * getConfigValue("rateLoot")
        local monsterLoot = getMonsterLootList(name)
        local mainbp = doCreateItemEx(1987, 1)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then...
 
I would like up to 40% of random experience to be random, with the exp and loot bonus being drawn and changed every day. could help me?
 
Lua:
local loot_bonus = math.random(10, 40)  --  10% to 40%
local ignoredList = {1987}
function addBonusLoot(position, name)
        for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            break
        end
    end
        local newRate = (1 + (loot_bonus/100)) * getConfigValue("rateLoot")
        local monsterLoot = getMonsterLootList(name)
        local mainbp = doCreateItemEx(1987, 1)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
            doAddContainerItemEx(corpse.uid, mainbp) 
        end
end

local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat", "spider", "troll", "orc", "minotaur", "dwarf", "elf", "skeleton", "amazon", "valkirie", "dark apprentice", "ghoul", "cyclops", "dwarf guard", "necromancer", "vampire", "werewolf", "dragon", "dragon lord", "wyrm", "giant spider", "hydra", "warlock", "demon"}
local experienceBonus = math.random(10, 40)  --  10% to 40%

function onDeath(cid, corpse, deathList)

local master = getCreatureMaster(cid)
  if (master and master ~= cid) then
    return true
  end

  local boostedMonster = boostedMonstersList[getGlobalStorageValue(BOOSTED_MONSTER)]
    if getCreatureName(cid):lower() == boostedMonster then
    
for i = 1, #deathList do
    
-- exp bonus
    local bonusExperience = getMonsterInfo(getCreatureName(cid)).experience/i * getPlayerRates(deathList[i])[SKILL__LEVEL] * experienceBonus/100
    doPlayerAddExperience(deathList[i], bonusExperience)
    doSendAnimatedText(getPlayerPosition(deathList[i]), bonusExperience, 215)
    
-- loot bonus
    addEvent(addBonusLoot, 10, getCreaturePosition(cid), getCreatureName(cid))
    
end
    
    end
    return true
end
 
Solution
@buchaLL

I installed it as follows:
I put the script in Creaturescripts.
file name:

monsteroftheday_onkill.lua

tag:

<event type="death" name="monsteroftheday_onkill" event="script" value="monsteroftheday_onkill.lua"/>

did not give error in the distro, however I put:

in the monster the tag:

<script>
<event name = "monsteroftheday_onkill" />
</script>

and

BOOSTED_MONSTER location = 56404.

I put the 56404 on the floor in action and uniqueid and the monster of the day didn’t appear like the picture, and the exp bonus and loot bonus.

sorry i'm a layman in script, then i want to make a donation to your person for help, people like you today are rare.
 
Change
local experienceBonus to experienceBonus
local loot_bonus to loot_bonus

globalevents
Lua:
dofile('data/creaturescripts/scripts/your_script_name.lua')

function onThink(cid, interval, lastExecution)
      doSendAnimatedText({x=438,y=503,z=7},""..loot_bonus.."", 244)
      doSendAnimatedText({x=440,y=503,z=7},""..experienceBonus.."", 244)
return true
end

Lua:
function onStartup()
local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat", "spider", "troll", "orc", "minotaur", "dwarf", "elf", "skeleton", "amazon", "valkirie", "dark apprentice", "ghoul", "cyclops", "dwarf guard", "necromancer", "vampire", "werewolf", "dragon", "dragon lord", "wyrm", "giant spider", "hydra", "warlock", "demon"}
local randomMonster = math.random(#boostedMonstersList)
setGlobalStorageValue(BOOSTED_MONSTER, randomMonster)
local spawn = {x = 439, y = 503, z = 7}
    doCreateMonster(boostedMonstersList[randomMonster], spawn)
    print("Today's boosted monster is: " .. boostedMonstersList[randomMonster])
end

XML:
<globalevent name="napisy" interval="1300" event="script" value="words.lua"/>
<globalevent name="daily_monster" type="startup" event="script" value="daily_monster.lua"/>
 
@buchaLL
The experience is not being told friend and in addition I restarted the otserv ten times and did not change the creature.
Post automatically merged:

Still thank you for your help, :).
 

Attachments

Last edited:
To every monster boosted add
XML:
<script>
        <event name="daily_monster_bonus"/>
</script>

globalevents/scripts/words.lua
Lua:
dofile('data/creaturescripts/scripts/daily_monster_bonus.lua')

function onThink(cid, interval, lastExecution)
      doSendAnimatedText({x=438,y=503,z=7},"Loot +"..loot_bonus.."%", 244)
      doSendAnimatedText({x=439,y=503,z=7},"Boosted", 244)
      doSendAnimatedText({x=440,y=503,z=7},"Exp +"..experienceBonus.."%", 244)
return true
end

globalevents/scripts/daily_monster.lua
Lua:
function onStartup()
local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat", "spider", "troll", "orc", "minotaur", "dwarf", "elf", "skeleton", "amazon", "valkirie", "dark apprentice", "ghoul", "cyclops", "dwarf guard", "necromancer", "vampire", "werewolf", "dragon", "dragon lord", "wyrm", "giant spider", "hydra", "warlock", "demon"}
local randomMonster = math.random(#boostedMonstersList)
setGlobalStorageValue(BOOSTED_MONSTER, randomMonster)
local spawn = {x = 439, y = 503, z = 7}  --  monster spawn position
    doCreateMonster(boostedMonstersList[randomMonster], spawn)
    print("Today's boosted monster is: " .. boostedMonstersList[randomMonster])
end

globalevents/globalevents.xml
XML:
<globalevent name="daily_monster" type="startup" event="script" value="daily_monster.lua"/>
<globalevent name="words" interval="1300" event="script" value="words.lua"/>

creaturescripts/scripts/daily_monster.lua
Lua:
function onLogin(cid)
local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat", "spider", "troll", "orc", "minotaur", "dwarf", "elf", "skeleton", "amazon", "valkirie", "dark apprentice", "ghoul", "cyclops", "dwarf guard", "necromancer", "vampire", "werewolf", "dragon", "dragon lord", "wyrm", "giant spider", "hydra", "warlock", "demon"}
local boostedMonster = boostedMonstersList[getGlobalStorageValue(BOOSTED_MONSTER)]
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Today's monster boosted is: "..boostedMonster.."!")
return true
end

creaturescripts/scripts/daily_monster_bonus.lua
Lua:
loot_bonus = 50
ignoredList = {1987}
function addBonusLoot(position, name)
        for i = 0, 255 do
        position.stackpos = i
        corpse = getTileThingByPos(position)
        if corpse.uid > 0 and isCorpse(corpse.uid) then
            break
        end
    end
        local newRate = (1 + (loot_bonus/100)) * getConfigValue("rateLoot")
        local monsterLoot = getMonsterLootList(name)
        local mainbp = doCreateItemEx(1987, 1)
        for i, loot in pairs(monsterLoot) do
            if math.random(1, 100000) <= newRate * loot.chance then
                if #ignoredList > 0 then
                    if (not isInArray(ignoredList, loot.id)) then
                        doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                    end
                else
                    doAddContainerItem(mainbp, loot.id, loot.countmax and math.random(1, loot.countmax) or 1)
                end
            end
            doAddContainerItemEx(corpse.uid, mainbp) 
        end
end

BOOSTED_MONSTER = 56404
boostedMonstersList = {"rat", "spider", "troll", "orc", "minotaur", "dwarf", "elf", "skeleton", "amazon", "valkirie", "dark apprentice", "ghoul", "cyclops", "dwarf guard", "necromancer", "vampire", "werewolf", "dragon", "dragon lord", "wyrm", "giant spider", "hydra", "warlock", "demon"}
experienceBonus = 50

function onDeath(cid, corpse, deathList)

local master = getCreatureMaster(cid)
  if (master and master ~= cid) then
    return true
  end

  local boostedMonster = boostedMonstersList[getGlobalStorageValue(BOOSTED_MONSTER)]
    if getCreatureName(cid):lower() == boostedMonster then
    
for i = 1, #deathList do
    
-- exp bonus
    local bonusExperience = getMonsterInfo(getCreatureName(cid)).experience/i * getPlayerRates(deathList[i])[SKILL__LEVEL] * experienceBonus/100
    doPlayerAddExperience(deathList[i], bonusExperience)
    doSendAnimatedText(getPlayerPosition(deathList[i]), bonusExperience, 215)
    
-- loot bonus
    addEvent(addBonusLoot, 10, getCreaturePosition(cid), getCreatureName(cid))
    
end
    
    end
    return true
end

creaturescripts/creaturescripts.xml
XML:
<event type="login" name="daily_monster" event="script" value="daily_monster.lua"/>
<event type="death" name="daily_monster_bonus" event="script" value="daily_monster_bonus.lua"/>
 
Everything works.
Just change words.lua:
Lua:
dofile('data/creaturescripts/scripts/daily_monster_bonus.lua')
local positions = {
{pos = {x = 2056, y = 2051, z = 7}},
{pos = {x = 2055, y = 2051, z = 7}},
{pos = {x = 2057, y = 2051, z = 7}}
}

function onThink(cid, interval, lastExecution)
   for _, pid in pairs(positions) do
   local t = getSpectators(pid.pos, 7, 5, false)
            if t then
                for _, cid in ipairs(t) do
                    if isPlayer(cid) then
                        doSendAnimatedText(pid.pos, "Loot +"..loot_bonus.."%", TEXTCOLOR_BLUE)
                        doSendAnimatedText(pid.pos, "Boosted", TEXTCOLOR_BLUE)
                        doSendAnimatedText(pid.pos, "Exp +"..experienceBonus.."%", TEXTCOLOR_BLUE)
                    end
                end
            end
   end
return true
end

f39c0f94787f11575ba5d1af506a0764.png
cde97aa5b92359b577effe1ce0b479d0.png
 
Last edited:
Everything works.
Just change words.lua:
Lua:
dofile('data/creaturescripts/scripts/daily_monster_bonus.lua')
local positions = {
{pos = {x = 2056, y = 2051, z = 7}},
{pos = {x = 2055, y = 2051, z = 7}},
{pos = {x = 2057, y = 2051, z = 7}}
}

function onThink(cid, interval, lastExecution)
   for _, pid in pairs(positions) do
   local t = getSpectators(pid.pos, 7, 5, false)
            if t then
                for _, cid in ipairs(t) do
                    if isPlayer(cid) then
                        doSendAnimatedText(pid.pos, "Loot +"..loot_bonus.."%", TEXTCOLOR_BLUE)
                        doSendAnimatedText(pid.pos, "Boosted", TEXTCOLOR_BLUE)
                        doSendAnimatedText(pid.pos, "Exp +"..experienceBonus.."%", TEXTCOLOR_BLUE)
                    end
                end
            end
   end
return true
end

f39c0f94787f11575ba5d1af506a0764.png
cde97aa5b92359b577effe1ce0b479d0.png
Hi, when i start my server always is choose the same monster. ALWAYS is the same. I use that list:
local boostedMonstersList = {"dwarf guard", "squirrel yet", "korova dragon", "phyculos", "mad scientist", "omega lizard", "warchief", "beholder", "barbarian skullhunter", "thornback tortoise", "energy", "azazel", "calmadios","misthur", "monspiet"}


And always is Calmadios
 
Hi, when i start my server always is choose the same monster. ALWAYS is the same. I use that list:
local boostedMonstersList = {"dwarf guard", "squirrel yet", "korova dragon", "phyculos", "mad scientist", "omega lizard", "warchief", "beholder", "barbarian skullhunter", "thornback tortoise", "energy", "azazel", "calmadios","misthur", "monspiet"}


And always is Calmadios
The randomized monster is based off of a global storage at startup.

If you changed the global storage number, you need to do so within all of the scripts.
 
i dont change nothing, only name monsters. And i already restarted globalstorage, always come Calmadios
I can't see the issue in the scripts.. as it appears to work as intended.

Can you give some screenshots of what you currently have setup?
 
lol I don't know, it all looks right.

Everytime you restart the server it should change to a different monster.

If you don't close the server, it won't change.

But if you are still having problems.. we could add a new seed for math.random I guess.

so in the onStartup() script

change this
Lua:
function onStartup()
    local BOOSTED_MONSTER = 56404
to this
Lua:
function onStartup()
    math.randomseed(os.time())
    local BOOSTED_MONSTER = 56404
 
lol I don't know, it all looks right.

Everytime you restart the server it should change to a different monster.

If you don't close the server, it won't change.

But if you are still having problems.. we could add a new seed for math.random I guess.

so in the onStartup() script

change this
Lua:
function onStartup()
    local BOOSTED_MONSTER = 56404
to this
Lua:
function onStartup()
    math.randomseed(os.time())
    local BOOSTED_MONSTER = 56404
to change the monster i need wait 24 hours with TFS online, or when i shutdown and open again will change monster?
 
Back
Top