Advertisement
Bolodefchoco_LUAXML

[Script] Share Tribe

Apr 3rd, 2016
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 03/04/2016
  3. --Last update: 26/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Permite que você divulgue sua tribo.
  7.     Commands:
  8.         !
  9.             infotribe --> Liberado apenas ao primeiro jogador na sala que for da tribo X, ele poderá publicar a tribo adicionando uma descrição e quem pode recrutar.
  10.             share --> Publica após fazer o !infotribe
  11.             adm --> Dá a administração da publicação a outro jogador da mesma tribo.
  12.                 Player --> Jogador
  13.             new --> Refaz a publicação do !infotribe
  14.             remove --> Remove a publicação do +Tribes
  15. ]]--
  16.  
  17. table.find=function(list,value)
  18.     local found,keys,times = false,{},0
  19.     for k,v in next,list do
  20.         if type(v) ~= "table" then
  21.             if v == value then
  22.                 found = true
  23.                 keys[#keys+1] = k
  24.                 times = times + 1
  25.             end
  26.         else
  27.             local a,b,c = table.find(v,value)
  28.             if not found then found = a end
  29.             if b then table.insert(keys,table.unpack(b)) end
  30.             if c then times = times + c end
  31.         end
  32.     end
  33.     return found,keys,times
  34. end
  35. string.nick=function(player)
  36.     return player:lower():gsub('%a',string.upper,1)
  37. end
  38. table.destroy=function(list,value)
  39.     for k,v in next,list do
  40.         if v == value then
  41.             table.remove(list,k);break
  42.         end
  43.     end
  44. end
  45.  
  46. mice={}
  47. tribeList={}
  48. tribeShared={}
  49. eventNewPlayer=function(n)
  50.     mice[n]={
  51.         tribe=tfm.get.room.playerList[n].tribeName,
  52.         description={"",""},
  53.         id=99,
  54.         shared=false,
  55.         on=false,
  56.         timer=os.time(),
  57.     }
  58.     if mice[n].tribe ~= nil and not table.is(tribeList,mice[n].tribe) then
  59.         table.insert(tribeList,mice[n].tribe)
  60.         _G[mice[n].tribe:gsub("%s","_").."admin"] = n
  61.     end
  62.     ui.addTextArea(0,"<PT><p align='center'><a href='event:tribelist'>+Tribes",n,745,375,50)
  63. end
  64. table.foreach(tfm.get.room.playerList,eventNewPlayer)
  65. eventPlayerLeft=function(n)
  66.     if table.is(tribeList,mice[n].tribe) then
  67.         _G[mice[n].tribe:gsub("%s","_").."admin"] = nil
  68.         table.destroy(tribeList,mice[n].tribe)
  69.     end
  70. end
  71. eventChatCommand=function(n,c)
  72.     local p={}
  73.     for v in c:gmatch('[^%s]+') do table.insert(p,v) end
  74.     if p[1]:lower()=="infotribe" and mice[n].shared==false and _G[mice[n].tribe:gsub("%s","_").."admin"]==n and mice[n].tribe ~= nil then
  75.         local texts={"Write a short description of your tribe.\n@ = Break line","Quote the leaders of the tribe, or who could recruit someone"}
  76.         local y={30,130}
  77.         for i=0,1 do
  78.             ui.addPopup(i,2,texts[i+1],n,5,y[i+1],790,true)
  79.         end
  80.     end
  81.     if p[1]:lower()=="share" and  _G[mice[n].tribe:gsub("%s","_").."admin"]==n and mice[n].description[1]~="" and mice[n].description[2]~="" then
  82.         mice[n].shared=true
  83.         table.insert(tribeShared,{n,"<J>Tribe Name : <V>"..mice[n].tribe.."\n<J>Description : <PT>"..mice[n].description[1].."\n<R>Leaders : <J>"..mice[n].description[2].."\n<ROSE>Publisher : <a href='event:@"..n.."'>"..n.."</a>"})
  84.     end
  85.     if p[1]:lower()=="adm" and p[2] and mice[n].tribeList == mice[string.nick(p[2])].tribeList and _G[mice[n].tribe:gsub("%s","_").."admin"]==n then
  86.         _G[mice[n].tribe:gsub("%s","_").."admin"] = string.nick(p[2])
  87.     end
  88.     if (p[1]:lower()=="new" or p[1]:lower()=="remove") and _G[mice[n].tribe:gsub("%s","_").."admin"]==n then
  89.         mice[n].shared=false
  90.         for i = 1,2 do
  91.             mice[n].description[i]=""
  92.         end
  93.     end
  94. end
  95. for _,c in next,{'infotribe','share','adm','new','remove'} do
  96.     system.disableChatCommandDisplay(c,true)
  97. end
  98. eventPopupAnswer=function(i,n,c)
  99.     if i == 0 then
  100.         mice[n].description[1] = (#c>10 and c:gsub("%s*@%s*","\n",3) or "<R>No description")
  101.     end
  102.     if i == 1 then
  103.         mice[n].description[2] = (#c>2 and c or "<R>No leaders")
  104.     end
  105. end
  106. F_tribeList=function(n)
  107.     local t = ""
  108.     local d = {}
  109.     for i in next,tribeShared do
  110.         if mice[tribeShared[i][1]].shared == true then
  111.             t = t .. tribeShared[i][2] .. '\n\n'
  112.         else
  113.             table.insert(d,i)
  114.         end
  115.     end
  116.     for i,v in next,d do
  117.         table.remove(tribeShared,v)
  118.     end
  119.     ui.addTextArea(1,t,n,10,30,780,300)
  120. end
  121. eventTextAreaCallback=function(i,n,c)
  122.     if c=='tribelist' then
  123.         if mice[n].on then
  124.             ui.removeTextArea(1,n)
  125.             ui.updateTextArea(0,"<PT><p align='center'><a href='event:tribelist'>+Tribes",n)
  126.         else
  127.             F_tribeList(n)
  128.             ui.updateTextArea(0,"<PT><p align='center'><a href='event:tribelist'>-Tribes",n)
  129.         end
  130.         mice[n].on=not mice[n].on
  131.     end
  132.     if c:sub(1,1)=="@" and os.time()>mice[n].timer and n~=c:sub(2) then
  133.         mice[n].timer = os.time() + 20000
  134.         c = c:sub(2)
  135.         mice[c].id = mice[c].id+1
  136.         ui.addTextArea(mice[c].id,"<J>The player <V>"..n.." <J>want to visit your tribe :)\nName : <V>"..n.."\n<J>Current tribe : <V>"..(mice[n].tribe or "<R>There's no tribe.").."\n<p align='center'><R><a href='event:closemessage'>Close</a>",c)
  137.         ui.addTextArea(10000,"<J>You sent a solicitation to <V>"..c.."<J>, just wait!\n<p align='center'><R><a href='event:closead'>Close</a>",n)
  138.     end
  139.     if c == 'closemessage' then
  140.         ui.removeTextArea(mice[n].id)
  141.         mice[n].id=mice[n].id-1
  142.     end
  143.     if c == 'closead' then
  144.         ui.removeTextArea(10000,n)
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement