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

Lua (Math.random items / math.random level / math.random skills / math.random oufit).script

bury

Active Member
Joined
Jul 27, 2008
Messages
421
Solutions
7
Reaction score
25
Hello!

I'm using TFS 0.4

Could be possible to do this script? player clicks an action or say a talkaction and:

1- Replace the firstitems.lua items for some others in a math.random list (local items = [id], [id2], [id3]....) so for example 5 people click the action and get different set (depending on vocation too). I dont know if there is any function for replacing items.

2- Get a random level from a list.

3- Get random skills from a list (depending on voc too)

4- Get random outfit (not addons) also, changing the color.

So by one click you can find different players in some seconds.

If this script is hard maybe could you just help me a bit with the math.random system?

Anyway, I could even pay for it if it's much work.

Thanks you!

EDIT: About level and skills, maybe with a from ... to ... would be better.
 
Last edited:
Hello!

I'm using TFS 0.4

Could be possible to do this script? player clicks an action or say a talkaction and:

1- Replace the firstitems.lua items for some others in a math.random list (local items = [id], [id2], [id3]....) so for example 5 people click the action and get different set (depending on vocation too). I dont know if there is any function for replacing items.

2- Get a random level from a list.

3- Get random skills from a list (depending on voc too)

4- Get random outfit (not addons) also, changing the color.

So by one click you can find different players in some seconds.

If this script is hard maybe could you just help me a bit with the math.random system?

Anyway, I could even pay for it if it's much work.

Thanks you!

EDIT: About level and skills, maybe with a from ... to ... would be better.
Easy.
But I need to know what firstitems.lua looks like.
Can you post it?
 
My friend a list is like arrays you can Index them this way: list[Index]

So items_list[math.random(1, #items_list + 1)]

 
Easy.
But I need to know what firstitems.lua looks like.
Can you post it?


This is my firstitems.lua (what I want is to keep this script, but then once you get that items, could replace them with math random items). And then the other math randoms:

firstitems.lua

Lua:
local storage = 67777
function onLogin(cid)
    local config = {
        voc_items = {
            { -- SORC
                {2190}, -- wand of vortex
                {2175}, -- spellbook
                {8820}, -- mage hat
                {8819} -- mage robe
            },
            { -- DRUID
                {2182}, -- snakebite rod
                {2175}, -- spellbook
                {8820}, -- mage hat
                {8819} -- mage robe
            },
            { -- PALADIN
                {2399}, -- throwing star
                {2530}, -- copper shield
                {2480}, -- legion helmet
                {2464} -- chain armor
            },
            { -- KNIGHT
                {2409}, -- serpent sword
                {2530}, -- copper shield
                {2480}, -- legion helmet
                {2464} -- chain armor
            }
        },
        all_items = {
            {2468}, -- studded legs
            {3982} -- leather boots
        },
        extra_items = {
            {2789, 15},
            {7731},
            {5710},
            {2160}
        },
        knight_weapons = {
            {2423}, -- clerical mace
            {2429} -- barbarian axe
        },
        paladin_weapons = {
            {2544}, -- arrow
            {2545}, -- poison arrow
            {2456}, -- bow
            {2389} -- spear
    }
    }
    if getPlayerGroupId(cid) < 3 then
        if getPlayerStorageValue(cid, storage) == -1 then
            local common = config.voc_items[getPlayerVocation(cid)]
            if common ~= nil then
                for _, v in ipairs(common) do
                    doPlayerAddItem(cid, v[1], v[2] or 1)
                end
            end
            
            local all = config.all_items
            if all ~= nil then
                for _, v in ipairs(all) do
                    doPlayerAddItem(cid, v[1], v[2] or 1)
                end
            end
            
            local extra = config.extra_items
            local bp = doPlayerAddItem(cid, 1988, 1)
            if extra ~= nil then
                for _, v in ipairs(extra) do
                    doAddContainerItem(bp, v[1], v[2] or 1)
                end
            end
            
            local weapons = config.knight_weapons
            if weapons ~= nil then
                for _, w in ipairs(weapons) do
                    if isKnight(cid) then
                        doAddContainerItem(bp, w[1], w[2] or 1)
                    end
                end
            end
            
            local weapons = config.paladin_weapons
            if weapons ~= nil then
                for _, w in ipairs(weapons) do
                    if isPaladin(cid) then
                        doAddContainerItem(bp, w[1], w[2] or 1)
                    end
                end
            end
            
            setPlayerStorageValue(cid, storage, 1)
        end
    end
    return true
end
 
I didn't test this as I'm not at home but this script should do the job:

Lua:
local storage = 67777
local given_items = {}
local random_items = { 2195, 2254, 2345, 2367 } -- just replace with your item ids, add as many as you need

local function replace_items(cid)
    for i = 1, #given_items do
        doPlayerRemoveItem(cid, given_items[i], 1)
        doPlayerAddItem(cid, random_items(math.random(1, #random_items), 1)
    end
end

function onLogin(cid)
    local config = {
        voc_items = {
            { -- SORC
                {2190}, -- wand of vortex
                {2175}, -- spellbook
                {8820}, -- mage hat
                {8819} -- mage robe
            },
            { -- DRUID
                {2182}, -- snakebite rod
                {2175}, -- spellbook
                {8820}, -- mage hat
                {8819} -- mage robe
            },
            { -- PALADIN
                {2399}, -- throwing star
                {2530}, -- copper shield
                {2480}, -- legion helmet
                {2464} -- chain armor
            },
            { -- KNIGHT
                {2409}, -- serpent sword
                {2530}, -- copper shield
                {2480}, -- legion helmet
                {2464} -- chain armor
            }
        },
        all_items = {
            {2468}, -- studded legs
            {3982} -- leather boots
        },
        extra_items = {
            {2789, 15},
            {7731},
            {5710},
            {2160}
        },
        knight_weapons = {
            {2423}, -- clerical mace
            {2429} -- barbarian axe
        },
        paladin_weapons = {
            {2544}, -- arrow
            {2545}, -- poison arrow
            {2456}, -- bow
            {2389} -- spear
    }
    }
   
    if getPlayerGroupId(cid) < 3 then
        if getPlayerStorageValue(cid, storage) == -1 then
            local common = config.voc_items[getPlayerVocation(cid)]
            if common ~= nil then
                for _, v in ipairs(common) do
                    doPlayerAddItem(cid, v[1], v[2] or 1)
                    table.insert(given_items, v[1])
                end
            end
           
            local all = config.all_items
            if all ~= nil then
                for _, v in ipairs(all) do
                    doPlayerAddItem(cid, v[1], v[2] or 1)
                    table.insert(given_items, v[1])
                end
            end
           
            local extra = config.extra_items
            local bp = doPlayerAddItem(cid, 1988, 1)
            if extra ~= nil then
                for _, v in ipairs(extra) do
                    doAddContainerItem(bp, v[1], v[2] or 1)
                    table.insert(given_items, v[1])
                end
            end
           
            local weapons = config.knight_weapons
            if weapons ~= nil then
                for _, w in ipairs(weapons) do
                    if isKnight(cid) then
                        doAddContainerItem(bp, w[1], w[2] or 1)
                        table.insert(given_items, w[1])
                    end
                end
            end
           
            local weapons = config.paladin_weapons
            if weapons ~= nil then
                for _, w in ipairs(weapons) do
                    if isPaladin(cid) then
                        doAddContainerItem(bp, w[1], w[2] or 1)
                        table.insert(given_items, w[1])
                    end
                end
            end
           
            setPlayerStorageValue(cid, storage, 1)
        end
    end
   
    replace_items(cid)
   
    return true
end
 
@kuhi

Thanks! But that works as an action? I mean, the firstitems.lua is still on the script.

What I want is that some players are created and get the firstitems.lua but another will be able of replacing that firstitems.lua for other items by clicking an item or saying a !word.

After the items:


2- Get a random level from a list.

3- Get random skills from a list (depending on voc too)

4- Get random outfit (not addons) also, changing the color.
 
Back
Top