• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

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...
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

Below function onThink ..
Add this;
LUA:
print(Position(100, 100, 7))

It should print out userdata or table, if it's nil you need to change all the positions to this;
LUA:
{ x = 100, y = 100, z = 7 }
 

Similar threads

Back
Top