• 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 Help tile guild members online

gmstrikker

Well-Known Member
Joined
Jul 30, 2014
Messages
458
Solutions
1
Reaction score
50
MNAj2X4.png


My tile need guild members online, but dont work so fine :(
lib/050-function
Code:
function getGuildMembers(GuildId)local players,query ={},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = "..GuildId..");")
  if(query:getID()~=-1)then
  repeat
 table.insert(players,query:getDataString("name"))untilnot query:next()
 query:free()
  end
  return#players > 0 and players or falseend

dominarcitys.lua movements
Code:
local config = {
  level = 50,
  count = 1,
  messages = {
  [12000] = "A guild %s está penetrando no castelo.",
  [12001] = "A guild %s já está dentro do castelo.",
  [12002] = "A guild %s está perto de conquistar o castelo."
  }
}
function table.insert(table, value)
  table[#table + 1] = value
end
function getGuildOnlineMembers(guildId)
  local pid, ip = {}, {}
  for _, cid in pairs(getPlayersOnline()) do
  if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
  table.insert(pid, cid)
  table.insert(ip, getPlayerIp(cid))
  end
  end
  return pid
end
function onStepIn(cid, item, position, fromPosition)
  if not isPlayer(cid) then return true end
  if item.actionid == 12000 then
  if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
  doPlayerSendCancel(cid, "Você precisa estar em guild ou sua guild precisa ter no minimo "..config.count.." jogadores level "..config.level.." ou mais.")
  doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
  doTeleportThing(cid, fromPosition, true)
  return true
  end
  end
  if getGlobalStorageValue(item.actionid + 4819) < os.time() then
  broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
  setGlobalStorageValue(item.actionid + 4819, os.time() + 10)
  end
  doCreatureSetSkullType(cid,3)
  return true
end
 
Code:
local config = {
    level = 50,
    count = 1,
    messages = {
        [12000] = "A guild %s está penetrando no castelo.",
        [12001] = "A guild %s já está dentro do castelo.",
        [12002] = "A guild %s está perto de conquistar o castelo."
    },
    actionId = {12000, 4819}
}

function tableInsert(table, value)
    -- technically this doesn't need to be #table + 1, it can just be #table
    table[#table + 1] = value
end

function onStepIn(cid, item, position, fromPosition)

    local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

    local function getGuildOnlineMembers(guildId)

        for _, cid in pairs(getPlayersOnline()) do           
            if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
                tableInsert(pid, cid)
                tableInsert(ip, getPlayerIp(cid))
            end
        end
        return pid
    end

    if not isPlayer(cid) then
        return true
    end

    if item.actionid == config.actionId[1] then
        if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
            doPlayerSendCancel(cid, "Você precisa estar em guild ou sua guild precisa ter no minimo "..config.count.." jogadores level "..config.level.." ou mais.")
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            doTeleportThing(cid, fromPosition, true)
            return true
        end
    end

    if getGlobalStorageValue(item.actionid + config.actionId[2]) < os.time() then
        broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
        setGlobalStorageValue(item.actionid + config.actionId[2], os.time() + 10)
    end
    doCreatureSetSkullType(cid, 3)
    return true
end

I didn't edit the code below, I just corrected the structure because in its previous state it won't execute properly.
Code:
function getGuildMembers(GuildId)
    local players, query = {}, db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = "..GuildId..");")
    if(query:getID() ~= -1)then
        repeat
            table.insert(players, query:getDataString("name"))
        until not query:next()
        query:free()
    end
    return #players > 0 and players or false
end
 
Last edited:
Code:
local config = {
    level = 50,
    count = 1,
    messages = {
        [12000] = "A guild %s está penetrando no castelo.",
        [12001] = "A guild %s já está dentro do castelo.",
        [12002] = "A guild %s está perto de conquistar o castelo."
    },
    actionId = {12000, 4819}
}

function tableInsert(table, value)
    -- technically this doesn't need to be #table + 1, it can just be #table
    table[#table + 1] = value
end

function onStepIn(cid, item, position, fromPosition)

    local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

    local function getGuildOnlineMembers(guildId)

        for _, cid in pairs(getPlayersOnline()) do          
            if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
                tableInsert(pid, cid)
                tableInsert(ip, getPlayerIp(cid))
            end
        end
        return pid
    end

    if not isPlayer(cid) then
        return true
    end

    if item.actionid == config.actionId[1] then
        if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
            doPlayerSendCancel(cid, "Você precisa estar em guild ou sua guild precisa ter no minimo "..config.count.." jogadores level "..config.level.." ou mais.")
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            doTeleportThing(cid, fromPosition, true)
            return true
        end
    end

    if getGlobalStorageValue(item.actionid + config.actionId[2]) < os.time() then
        broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
        setGlobalStorageValue(item.actionid + config.actionId[2], os.time() + 10)
    end
    doCreatureSetSkullType(cid, 3)
    return true
end

I didn't edit the code below, I just corrected the structure because in its previous state it won't execute properly.
Code:
function getGuildMembers(GuildId)
    local players, query = {}, db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = "..GuildId..");")
    if(query:getID() ~= -1)then
        repeat
            table.insert(players, query:getDataString("name"))
        until not query:next()
        query:free()
    end
    return #players > 0 and players or false
end


I think it's work now, ty to help me again
 
Code:
local config = {
    level = 50,
    count = 1,
    messages = {
        [12000] = "A guild %s está penetrando no castelo.",
        [12001] = "A guild %s já está dentro do castelo.",
        [12002] = "A guild %s está perto de conquistar o castelo."
    },
    actionId = {12000, 4819}
}

function tableInsert(table, value)
    -- technically this doesn't need to be #table + 1, it can just be #table
    table[#table + 1] = value
end

function onStepIn(cid, item, position, fromPosition)

    local pid, ip = {}, {} -- now they will hold the values generated by get getGuildOnlineMembers

    local function getGuildOnlineMembers(guildId)

        for _, cid in pairs(getPlayersOnline()) do          
            if getPlayerGuildId(cid) == guildId and getPlayerLevel(cid) >= config.level and not isInArray(ip, getPlayerIp(cid)) then
                tableInsert(pid, cid)
                tableInsert(ip, getPlayerIp(cid))
            end
        end
        return pid
    end

    if not isPlayer(cid) then
        return true
    end

    if item.actionid == config.actionId[1] then
        if getPlayerGuildId(cid) < 1 or #getGuildOnlineMembers(getPlayerGuildId(cid)) < config.count then
            doPlayerSendCancel(cid, "Você precisa estar em guild ou sua guild precisa ter no minimo "..config.count.." jogadores level "..config.level.." ou mais.")
            doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
            doTeleportThing(cid, fromPosition, true)
            return true
        end
    end

    if getGlobalStorageValue(item.actionid + config.actionId[2]) < os.time() then
        broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
        setGlobalStorageValue(item.actionid + config.actionId[2], os.time() + 10)
    end
    doCreatureSetSkullType(cid, 3)
    return true
end

I didn't edit the code below, I just corrected the structure because in its previous state it won't execute properly.
Code:
function getGuildMembers(GuildId)
    local players, query = {}, db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = "..GuildId..");")
    if(query:getID() ~= -1)then
        repeat
            table.insert(players, query:getDataString("name"))
        until not query:next()
        query:free()
    end
    return #players > 0 and players or false
end

A error my bro :(

GtQQI5c.png
 
A error my bro :(

GtQQI5c.png
What is ACTIONID of item that you step in? (what is configured in movements.xml) because error is in this line:
PHP:
broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
and for 99% it means that you try to get element of config.messages with ID that does not exist (other then 12000, 12001, 12002)
 
What is ACTIONID of item that you step in? (what is configured in movements.xml) because error is in this line:
PHP:
broadcastMessage(config.messages[item.actionid]:format(getPlayerGuildName(cid)))
and for 99% it means that you try to get element of config.messages with ID that does not exist (other then 12000, 12001, 12002)

So ty :)
 
Back
Top