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

Raid Chance

GuilleMoniz

New Member
Joined
Dec 5, 2016
Messages
23
Reaction score
3
Im trying to use/create a chance raid system. I dont like the margin shit one. I need to be like for example. Every 3h there's 25% chance of raid sucess. that could be aweasome. I tried to add "change = 25" but that simple doesnt work at all

Anyone have a better idea?
 
Solution
I'm new to math.randomseed(), just read a little bit but wondering if your usage here is to just to make sure the functions generates new math.random numbers everytime?

Well let's say everytime the time is update (every millisecond) the "random" is changed, if you use a static number (aka never changes) the random won't change.
If you have / add math.randomseed(os.time()) into global.lua you won't need it in other scripts.

[08/08/2017 18:41:12] [Error - GlobalEvent Interface]
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:eek:nThink
[08/08/2017 18:41:12] Description:
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:10: attempt to index global 'Game' (a nil value)
[08/08/2017 18:41:12] stack...
You can handle raids by lua in globalevents with intervals.

Can you give me a example? Im pretty new about programing... Im doing well creating the map and stuff (working in a 8.60 right now for a few months) Im playing this game already for 13 years, I quit being top 16 global 1 year ago and I want to create a real tibia server with what players really love to do :p
 
Can you give me a example? Im pretty new about programing... Im doing well creating the map and stuff (working in a 8.60 right now for a few months) Im playing this game already for 13 years, I quit being top 16 global 1 year ago and I want to create a real tibia server with what players really love to do :p
Please read the rules of the support thread man, people can't help much without knowing the server version and also if you want someone to create a script for you then you should post in requests.

That said, this was created based off tfs 1.2 so it might not work but you get the idea.

Lua:
local raids = {"Orc Raid", "Troll Raid"}

function onTime(interval)
    local pick = math.random(1, #raids)
    Game.startRaid(raids[pick])
    Game.broadcastMessage(""..raids[pick].." has started!", MESSAGE_STATUS_WARNING)
    table.remove(raids, pick)
    return true
end
 
Please read the rules of the support thread man, people can't help much without knowing the server version and also if you want someone to create a script for you then you should post in requests.

That said, this was created based off tfs 1.2 so it might not work but you get the idea.

Lua:
local raids = {"Orc Raid", "Troll Raid"}

function onTime(interval)
    local pick = math.random(1, #raids)
    Game.startRaid(raids[pick])
    Game.broadcastMessage(""..raids[pick].." has started!", MESSAGE_STATUS_WARNING)
    table.remove(raids, pick)
    return true
end

Im so sorry. I am using tfs 1.0 server 8.60 global
Yep I want something like that lol. Where do I should add this script? Glogalevent?

I wanted something totally random, like for example: Like the normal raid system the server is using now but I would love to add a chance function...

right now is like:
<raid name="Morgaroth" file="Morgaroth.xml" interval2="30" margin="1000" enabled="yes"/>

They work with a time chance max and I dont really like it, I wanted something like "every 3h the server try to run the script, but it have only 30% of chance to sucess"... that way is gonna be totally random, also I want to be able to chance the % of chance of course.

Do you get the idea? I dont know If i examplain myself well... I hate the margin/interval shit lol
 
Im so sorry. I am using tfs 1.0 server 8.60 global
Yep I want something like that lol. Where do I should add this script? Glogalevent?

I wanted something totally random, like for example: Like the normal raid system the server is using now but I would love to add a chance function...

right now is like:
<raid name="Morgaroth" file="Morgaroth.xml" interval2="30" margin="1000" enabled="yes"/>

They work with a time chance max and I dont really like it, I wanted something like "every 3h the server try to run the script, but it have only 30% of chance to sucess"... that way is gonna be totally random, also I want to be able to chance the % of chance of course.

Do you get the idea? I dont know If i examplain myself well... I hate the margin/interval shit lol

Yes globalevents, set it to an interval of 3 hours then add ex this;
Lua:
math.randomseed(os.time)
-- function onInterval(...)

if math.random(100) <= 30 then
    -- code to execute the raid
end
 
Yes globalevents, set it to an interval of 3 hours then add ex this;
Lua:
math.randomseed(os.time)
-- function onInterval(...)

if math.random(100) <= 30 then
    -- code to execute the raid
end

Youll gonna laugh but I dont know how lol.. I am horrible adding new stuff (I usually just copy and paste already working scripts)... Because I just like to map and stuff and I am pretty new. So basically what I need to do to set it to work?

I need to create a new .lua on globalevents only with that right? or I am wrong? and how I set that to work with the raid stuff? how should the line will be like?

Something like that?
<raid name="Morgaroth" file="Morgaroth.xml" interval2="10800" chance="30" enabled="yes"/>

I am ashamed, I tried to figure how to set the raids work for 4 days already and I can't... I never ask for help but right now im getting crazy hahaha
 
Youll gonna laugh but I dont know how lol.. I am horrible adding new stuff (I usually just copy and paste already working scripts)... Because I just like to map and stuff and I am pretty new. So basically what I need to do to set it to work?

I need to create a new .lua on globalevents only with that right? or I am wrong? and how I set that to work with the raid stuff? how should the line will be like?

Something like that?
<raid name="Morgaroth" file="Morgaroth.xml" interval2="10800" chance="30" enabled="yes"/>

I am ashamed, I tried to figure how to set the raids work for 4 days already and I can't... I never ask for help but right now im getting crazy hahaha

Go to the server directory.
Enter data/globalevents/
In globalevents.xml add this;
XML:
<globalevent name="customRaids" interval="10800000" script="custom/raids.lua" />

Then enter /data/ and create (if it dosn't exist) a folder called custom.
Then in there create a file called raids.lua, open that file.
And in that file add this;
Lua:
local raids = {"Orc Raid", "Troll Raid"}

math.randomseed(os.time())
function onThink(interval, lastExecution)
    if math.random(100) >= 100 then
        return false
    end

    local pick = math.random(1, #raids)
    Game.startRaid(raids[pick])
    Game.broadcastMessage(raids[pick] .. " has started!", MESSAGE_STATUS_WARNING)
    table.remove(raids, pick)

    return true
end
 
Last edited:
Go to the server directory.
Enter data/globalevents/
In globalevents.xml add this;
XML:
<globalevent name="customRaids" interval="10800000" script="custom/raids.lua" />

Then enter /data/ and create (if it dosn't exist) a folder called custom.
Then in there create a file called raids.lua, open that file.
And in that file add this;
Lua:
local raids = {"Orc Raid", "Troll Raid"}

math.randomseed(os.time)
function onThink(interval, lastExecution)
    if math.random(100) >= 100 then
        return false
    end

    local pick = math.random(1, #raids)
    Game.startRaid(raids[pick])
    Game.broadcastMessage(raids[pick] .. " has started!", MESSAGE_STATUS_WARNING)
    table.remove(raids, pick)

    return true
end

[08/08/2017 18:27:47] [Error - GlobalEvent Interface]
[08/08/2017 18:27:47] data/globalevents/scripts/custom/raids.lua
[08/08/2017 18:27:47] Description:
[08/08/2017 18:27:47] data/globalevents/scripts/custom/raids.lua:3: bad argument #1 to 'randomseed' (number expected, got function)
[08/08/2017 18:27:47] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/custom/raids.lua)


That happened, theres a way to fix it?
 
[08/08/2017 18:27:47] [Error - GlobalEvent Interface]
[08/08/2017 18:27:47] data/globalevents/scripts/custom/raids.lua
[08/08/2017 18:27:47] Description:
[08/08/2017 18:27:47] data/globalevents/scripts/custom/raids.lua:3: bad argument #1 to 'randomseed' (number expected, got function)
[08/08/2017 18:27:47] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/custom/raids.lua)


That happened, theres a way to fix it?

Missed (), updated the script
 
Go to the server directory.
Enter data/globalevents/
In globalevents.xml add this;
XML:
<globalevent name="customRaids" interval="10800000" script="custom/raids.lua" />

Then enter /data/ and create (if it dosn't exist) a folder called custom.
Then in there create a file called raids.lua, open that file.
And in that file add this;
Lua:
local raids = {"Orc Raid", "Troll Raid"}

math.randomseed(os.time())
function onThink(interval, lastExecution)
    if math.random(100) >= 100 then
        return false
    end

    local pick = math.random(1, #raids)
    Game.startRaid(raids[pick])
    Game.broadcastMessage(raids[pick] .. " has started!", MESSAGE_STATUS_WARNING)
    table.remove(raids, pick)

    return true
end

I'm new to math.randomseed(), just read a little bit but wondering if your usage here is to just to make sure the functions generates new math.random numbers everytime?
 
Missed (), updated the script


[08/08/2017 18:41:12] [Error - GlobalEvent Interface]
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:eek:nThink
[08/08/2017 18:41:12] Description:
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:10: attempt to index global 'Game' (a nil value)
[08/08/2017 18:41:12] stack traceback:
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:10: in function <data/globalevents/scripts/custom/raids.lua:4>
[08/08/2017 18:41:12] [Error - GlobalEvents::think] Couldn't execute event: customRaids

Ok it worket! haha but when It try to launch the raid, an error appear
 
I'm new to math.randomseed(), just read a little bit but wondering if your usage here is to just to make sure the functions generates new math.random numbers everytime?

Well let's say everytime the time is update (every millisecond) the "random" is changed, if you use a static number (aka never changes) the random won't change.
If you have / add math.randomseed(os.time()) into global.lua you won't need it in other scripts.

[08/08/2017 18:41:12] [Error - GlobalEvent Interface]
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:eek:nThink
[08/08/2017 18:41:12] Description:
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:10: attempt to index global 'Game' (a nil value)
[08/08/2017 18:41:12] stack traceback:
[08/08/2017 18:41:12] data/globalevents/scripts/custom/raids.lua:10: in function <data/globalevents/scripts/custom/raids.lua:4>
[08/08/2017 18:41:12] [Error - GlobalEvents::think] Couldn't execute event: customRaids

Ok it worket! haha but when It try to launch the raid, an error appear

Game.startRaid(...)
Is not added = "oudated TFS"

Either update to 1.2 / 1.3 or add this; Move /raid to talkactions · otland/forgottenserver@78fdaea · GitHub
 
Solution
If you want to you can use my raids.lua. I wrote it some months ago. For some other project, but in the end it wasnt used.
Raid system · thexamx/elysium@08717c5 · GitHub

This one looks more like my original idea. but It brings an error (idk if is because i'm using tfs 1.0)
C++:
[09/08/2017 11:19:37] [Error - GlobalEvent Interface]
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua
[09/08/2017 11:19:37] Description:
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua:3: attempt to call global 'Position' (a nil value)
[09/08/2017 11:19:37] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/raids.lua)
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua:1: unexpected symbol near '+'
[09/08/2017 11:19:37] Reloaded global events.

There's a way to fix it and use with tfs 1.0 server 8.60?
 
This one looks more like my original idea. but It brings an error (idk if is because i'm using tfs 1.0)
C++:
[09/08/2017 11:19:37] [Error - GlobalEvent Interface]
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua
[09/08/2017 11:19:37] Description:
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua:3: attempt to call global 'Position' (a nil value)
[09/08/2017 11:19:37] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/raids.lua)
[09/08/2017 11:19:37] data/globalevents/scripts/raids.lua:1: unexpected symbol near '+'
[09/08/2017 11:19:37] Reloaded global events.

There's a way to fix it and use with tfs 1.0 server 8.60?

Did you change it? Post it in that case.

Im not 100% sure if 1.0 had used the old table system for positions or not.
 
Did you change it? Post it in that case.

Im not 100% sure if 1.0 had used the old table system for positions or not.

Not really, I just remove the "+" after the error but is still not working
C++:
local raids = {
    -- Bosses
    [1]  = {type = 'BOSS', position = Position(998, 1006, 7), monster = 'demodras', message = 'Demodras has spawned', chance = 30},
    [2]  = {type = 'BOSS', position = Position(998, 1006, 7), monster = 'orshabaal', chance = 40},
    [3]  = {type = 'BOSS', position = Position(998, 1006, 7), monster = 'ferumbras', chance = 30},
   
    -- Raids fromPos, toPos
    [4] = {type = 'NORMAL', fromPos = Position(997, 1005, 7), toPos = Position(1009, 1014, 7), monsters = {'orc', 'orc Spearman', 'orc warrior'}, count = 10, message = 'orcs raid', chance = 20},
    [5] = {type = 'NORMAL', fromPos = Position(997, 1005, 7), toPos = Position(1009, 1014, 7), monsters = 'demon', count = 10, message = 'demons raid', chance = 50},
}

function onThink(interval, lastExecution, thinkInterval)
    local table = raids[math.random(#raids)]
   
    if math.random(100) > table.chance then
        return true
    end
   
    if table.type == 'BOSS' then
        local tileCreature = Tile(table.position):getTopCreature()
        if tileCreature and tileCreature:isMonster() and tileCreature:getName():lower() == table.monster then
            return true
        else
            Game.createMonster(table.monsters, table.position, true, false)
            if table.message ~= nil then
                broadcastMessage(table.message, MESSAGE_EVENT_ADVANCE)
            end   
        end
    elseif table.type == 'NORMAL' then
        for i = 1, table.count do
            local randomPosition = Position(math.random(table.fromPos.x, table.toPos.x), math.random(table.fromPos.y, table.toPos.y), table.fromPos.z)
            if type(table.monsters) == 'string' then
                Game.createMonster(table.monsters, randomPosition, true, false)
            else
                Game.createMonster(table.monsters[math.random(#table.monsters)], randomPosition, true, false)
            end
        end
        if table.message ~= nil then
            broadcastMessage(table.message, MESSAGE_EVENT_ADVANCE)
        end   
    end
   
    return true
end

Yeah I guess i can't use on 1.0, because I dont see any error but im kinda new in scripts lol
 
Back
Top