• 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 TFS 0.3 - Create Random npc.

Kuantikum

Member
Joined
Jul 3, 2015
Messages
219
Solutions
1
Reaction score
20
Hello,

I need to select 1 npc at random. I was trying something like that:

Lua:
local npcs = {
            {"Raymund Headley", {x = 3037, y = 1692, z = 7}},
            {"Charlie Anselm", {x = 3035, y = 1698, z = 7}},
            {"Nolan Peter", {x = 3040, y = 1699, z = 7}},
            {"Sanford Fulk", {x = 3040, y = 1699, z = 6}},
            {"Paulina Megan", {x = 3035, y = 1693, z = 6}},
            {"Regena Loraine", {x = 3042, y = 1692, z = 6}},
            {"Hettie Sibyl", {x = 3037, y = 1692, z = 8}},
            {"Harmonie Rainbow", {x = 3041, y = 1697, z = 5}},
            {"Flossie Cherise", {x = 3032, y = 1702, z = 7}},
            {"Joetta Mabella", {x = 3038, y = 1694, z = 8}},
        }

        for i = 1, 5 do
            table.remove(npcs, getRandom(1, #npcs))
        end

        for _, npc in pairs(npcs) do
            doCreateNpc(npc[1], npc[2])
        end
        npcs = table.clear(npcs)

Can you help me? tyty
 
Lua:
local npcs = {
    {name = "Raymund Headley", pos = {x = 3037, y = 1692, z = 7}},
    {name = "Charlie Anselm", pos = {x = 3035, y = 1698, z = 7}},
    {name = "Nolan Peter", pos = {x = 3040, y = 1699, z = 7}},
    {name = "Sanford Fulk", pos = {x = 3040, y = 1699, z = 6}},
    {name = "Paulina Megan", pos = {x = 3035, y = 1693, z = 6}},
    {name = "Regena Loraine", pos = {x = 3042, y = 1692, z = 6}},
    {name = "Hettie Sibyl", pos = {x = 3037, y = 1692, z = 8}},
    {name = "Harmonie Rainbow", pos = {x = 3041, y = 1697, z = 5}},
    {name = "Flossie Cherise", pos = {x = 3032, y = 1702, z = 7}},
    {name = "Joetta Mabella", pos = {x = 3038, y = 1694, z = 8}},
}

local randomNpc = npcs[math.random(1, #npcs)]
doCreateNpc(randomNpc.name, randomNpc.pos)
There you go
 
Last edited:
Lua:
local npcs = {
    {name = "Raymund Headley", pos = {x = 3037, y = 1692, z = 7}},
    {name = "Charlie Anselm", pos = {x = 3035, y = 1698, z = 7}},
    {name = "Nolan Peter", pos = {x = 3040, y = 1699, z = 7}},
    {name = "Sanford Fulk", pos = {x = 3040, y = 1699, z = 6}},
    {name = "Paulina Megan", pos = {x = 3035, y = 1693, z = 6}},
    {name = "Regena Loraine", pos = {x = 3042, y = 1692, z = 6}},
    {name = "Hettie Sibyl", pos = {x = 3037, y = 1692, z = 8}},
    {name = "Harmonie Rainbow", pos = {x = 3041, y = 1697, z = 5}},
    {name = "Flossie Cherise", pos = {x = 3032, y = 1702, z = 7}},
    {name = "Joetta Mabella", pos = {x = 3038, y = 1694, z = 8}},
}

local randomNpc = npcs[getRandom(1, #npcs)]
doCreateNpc(randomNpc.name, randomNpc.pos)
There you go
local randomNpc = npcs[math.random(#npcs)]
 
local randomNpc = npcs[math.random(#npcs)]
I'm so used to the fact that these outdated engines use doStupidStuff functions instead of metatables that I went with the flow and used his function instead xD

ps:
I'm aware that math.random is not a part of his engine, no need to point that out
 
Last edited:
Back
Top