SK

getGroupNameById(groupId)

Por Skymagnum, 24 de abr. de 2013 em Mods, funções e outros

5
1.3k
SkymagnumS
24 de abril de 2013 às 22:32

Ela retorna o nome do grupo do char ou seja, god, cm, etc...

 

function getGroupNameById(groupId)

   local file = io.open("data/lib/groups.xml", "r")
   local name = "name"

   for info in file:read("*a"):gmatch("<groups(.-)</groups>") do
      if tonumber(info:match("group id=\"(.-)"\")) == groupId then
            local name = info:match(name .. "=\"(.-)\""):lower()
            return tostring(name)
      end
   end

   file:close()

   return nil
end

 

if getGroupNameById(getPlayerGroupId(cid)) == "god" then
return true
else
return false
end

lembrando que a checagem deve sempre estar em minúscula.

correto:

"god"

incorreto:

"God"


É isso ai flws.

caoticC
25 de abril de 2013 às 11:32

Você pode usar o for no gmatch e ir procurando o groupId.

Mais não seria mais fácil você já inserir na string do gtmach o que você procura tipo (""..id.."(.-)...")

 

local t = "Ola EHEHEHE"
for i in t:gmatch("Ola(.*)") do
print(i)
end

 

Editado Abril 25 por caotic

SkymagnumS
25 de abril de 2013 às 13:43

Sim, tentei desse jeito só que deu uns erros lá.

MatheusGladM
25 de abril de 2013 às 18:41

Tente usar somente o string.match assim.

 

file:read("*a"):match("<group id=\"" .. groupId .. "\" name=\"(.-)\"")

 

Isso deve retornar o nome do grupo.

SkymagnumS
25 de abril de 2013 às 18:51

Tente usar somente o string.match assim.

 

file:read("*a"):match("<group id=\"" .. groupId .. "\" name=\"(.-)\"")

 

Isso deve retornar o nome do grupo.

Vlw, eu usei de um jeito diferente que tava dando erro n sei pq lol