Advertisement
Bolodefchoco_LUAXML

[Script] Social Network (Alpha)

Feb 12th, 2017
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.27 KB | None | 0 0
  1. --Bolodefchoco
  2. --2015
  3.  
  4. --[[ Functions ]]--
  5.     --[[ Serialization ]]--
  6. serialization={table={},string={}}
  7. serialization.table.tostring=function(t)
  8.     local str=""
  9.     for index,value in next,t do
  10.         local prefix,tbOption=(type(value)=="string" and "_@" or type(value)=="boolean" and "_!" or type(value)=="number" and "_#" or type(value)=="table" and "_%" or ""),(type(value)~="table" and tostring(value) or "+&"..serialization.table.tostring(value):gsub(";","?").."&-")
  11.         str = str..':'..tostring(index)..prefix..tbOption..";"
  12.     end
  13.     return str
  14. end
  15. serialization.string.totable=function(s)
  16.     local list={}
  17.     for str in s:gmatch("(.-);") do
  18.         local varName,valueType,value=str:match(':(.-)_(%p)(.+)')
  19.         if varName~=nil then
  20.             varName=tonumber(varName) or varName
  21.             if valueType=="@" then
  22.                 list[varName]=tostring(value)
  23.             elseif valueType=="!" then
  24.                 list[varName]=value=="true"
  25.             elseif valueType=="#" then
  26.                 list[varName]=tonumber(value)
  27.             elseif valueType=="%" then
  28.                 list[varName]={serialization.string.totable(value:gsub("+&",""):gsub("&-",""):gsub("%?",";"))}
  29.             end
  30.         end
  31.     end
  32.     return list
  33. end
  34.     --[[ Tables ]]--
  35. table.concat=function(t,sep,i,j)
  36.     i=i or 1;
  37.     j=j or #t;
  38.     sep=sep or "";
  39.     local _="";
  40.     for k,v in next,t do
  41.         if k>=i and k<=j then
  42.             _=_..v..sep
  43.         end
  44.     end
  45.     return _:sub(1,#_-#sep)
  46. end
  47. table.destroy=function(_table,value)
  48.     for _,__ in next,_table do
  49.         if value==__ then table.remove(_table,_);break
  50.         end
  51.     end
  52. end
  53. table.find=function(_table,value)
  54.     local _,__=false,nil
  55.     for ___,____ in next,_table do
  56.         if value==____ then
  57.             _=true;__=___;break
  58.         end
  59.     end
  60.     return _,__
  61. end
  62.     --[[ Strings ]]--
  63. string.equal=function(string1,string2)
  64.     string1,string2=string.split(string1,1,"%S"),string.split(string2,1,"%S")
  65.     local _=#string1>#string2 and #string2 or #string1
  66.     local __,___=0,0
  67.     for ____=1,_ do
  68.         if string1[____]==string2[____] then __=__+1
  69.         else ___=___+1 end
  70.     end
  71.     return __>=___,__/#string1*100
  72. end
  73. string.nick=function(player)
  74.     local _=1
  75.     if player:find("^%p") then _=2 end
  76.     return player:sub(1,_):upper()..player:sub(_+1):lower()
  77. end
  78. string.split=function(string,_type,split)
  79.     local _={}
  80.     for __ in string.gmatch(string,(_type==0 and '[^'..(split or '%s')..']+' or _type==1 and split)) do
  81.         table.insert(_,__)
  82.     end
  83.     return _
  84. end
  85.     --[[ addEvent ]]--
  86. event={}
  87. addEvent=function(v,f)
  88.     local c=0
  89.     v=v:lower()
  90.     event[v]=event[v] or {}
  91.     for _ in next,event[v] do
  92.         c = c + 1
  93.     end
  94.     event[v]["e"..c+1]=f
  95.     return "e"..c+1
  96. end
  97. do
  98.     for e,f in next,{
  99.         "Loop",
  100.         "TextAreaCallback",
  101.         "PopupAnswer",
  102.         "ChatMessage",
  103.     } do
  104.         _G["event"..f]=function(...)
  105.             for g,h in next,event[f:lower()] or {} do
  106.                 h(...)
  107.             end
  108.         end
  109.     end
  110. end
  111. --[[ Tables ]]--
  112. interface={
  113.     [1] = "main",
  114.     [2] = "updateNews",
  115.     [3] = "timelines",
  116.     [4] = "friends",
  117.     [5] = "profile",
  118.     [6] = "search",
  119.     [7] = "chat",
  120. }
  121. system={}
  122. mice={}
  123.     --[[ News ]]--
  124. system.news={
  125.     [1] = "$ is more expensive than £",
  126.     [2] = "Dilma sucked Lula, said TV Globo",
  127.     [3] = "Satan is the newest god!",
  128.     [4] = "Bolodefchoco has the biggest dick ever, says Sasha Grey",
  129. }
  130. --[[ Variables ]]--
  131.     --[[ Timers ]]--
  132. system.newsTimer = os.time() + 20000
  133. --[[ Interfaces ]]--
  134. do
  135.     for id,f in next,interface do
  136.         interface[f] = function(...)
  137.             local values = {...}
  138.             local text = ui.addTextArea
  139.             local n = values[1]
  140.             if id == 1 then -- Main
  141.                 text(0,"",n,5,2,790,500,1,1,1)
  142.                 text(1,"",n,318,130,25,25,0x324650,1,1)
  143.                 text(2,"<font size='20'><J>☎",n,318,129,30,30,0x324650,1,0)
  144.                 text(3,"",n,359,130,25,25,0x324650,1,1)
  145.                 text(4,"",n,30,105,740,20,0x192f39,0x192f39,1)
  146.                 text(5,"",n,5,24,790,72,0x2e6581,0x2e6581,1)
  147.                 text(6,"<p align='center'><font size='35'>TFM SCNetwork ©",n,5,36,790,50,0x324650,1,0)
  148.                 text(7,"<p align='center'><font size='25'><V><a href='event:timelines'>Timelines</a>",n,5,174,200,35,0x224557,0x224557,1)
  149.                 text(8,"<p align='center'><font face='Impact' size='25'><V><a href='event:@"..n.."'>"..n,n,5,134,245,35,0x103e55,0x103e55,1)
  150.                 text(9,"<p align='center'><font size='25'><V><a href='event:friends'>Friends</a>",n,5,214,200,35,0x224557,0x224557,1)
  151.                 text(10,"<p align='center'><font size='25'><V><a href='event:chat'>Chat</a>",n,5,254,200,34,0x224557,0x224557,1)
  152.                 text(11,"<p align='center'><font size='25'><V><a href='event:search'>Search</a>",n,5,294,200,35,0x224557,0x224557,1)
  153.                 text(12,"<p align='center'><font size='25'><V>??????",n,5,334,200,35,0x224557,0x224557,1)
  154.                 text(13,"<font size='20'><J>★",n,359,129,30,30,0x324650,1,0)
  155.                 text(14,"[News] : "..system.news[math.random(#system.news)],n,40,105,720,30,0x192f39,0x192f39,0)
  156.             end
  157.             if id == 2 then -- updateNews
  158.                 ui.updateTextArea(14,"[News] : "..system.news[math.random(#system.news)],n)
  159.             end
  160.             if id == 3 then -- Timelines
  161.                 local e = values[2]
  162.                 if not e then
  163.                     local txt = ""
  164.                     for i,v in next,mice[n].timelines[1] do
  165.                         txt = (type(v)=="table" and v[2] or v) .. '\n' .. txt
  166.                     end
  167.                     if #txt > 1999 then
  168.                         mice[n].timelines[1] = {}
  169.                         txt = ""
  170.                     end
  171.                     text(15,"<G><B>[<U><BL><a href='event:newpost'>Publicar</a></BL> ||| <BL><a href='event:resettimelines'>Reset Page</a></BL></U>]</B></G>\n\n"..txt,n,232,185,555,205,0x1c3d3c,0x1c3d3c,1)
  172.                 else
  173.                     ui.removeTextArea(15,n)
  174.                 end
  175.             end
  176.             if id == 4 then -- Friends
  177.                 local e = values[2]
  178.                 if not e then
  179.                     local friendlist={}
  180.                     table.sort(mice[n].friends[1])
  181.                     for i = 1,#mice[n].friends[1] do
  182.                         local name = mice[n].friends[1][i]
  183.                         table.insert(friendlist,(tfm.get.room.playerList[name] and "<PT>" or "<R>").."<a href='event:@"..name.."'>"..name.."</a> "..(table.find(mice[name].friends[1],n) and "<VP>" or "<R>").."•")
  184.                     end    
  185.                     text(16,"",n,232,185,555,205,0x224462,0x224462,1)
  186.                     text(17,(#friendlist>0 and table.concat(friendlist,'\n',1,15) or "<BL>Empty :("),n,233,185,555,205,1,1,0)
  187.                     text(18,table.concat(friendlist,'\n',16,31) or "",n,377,185,132,205,1,1,0)
  188.                     text(19,table.concat(friendlist,'\n',32,47) or "",n,521,185,132,205,1,1,0)
  189.                     text(20,table.concat(friendlist,'\n',48,63) or "",n,665,185,132,205,1,1,0)
  190.                 else
  191.                     for i = 16,20 do
  192.                         ui.removeTextArea(i,n)
  193.                     end
  194.                 end
  195.             end
  196.             if id == 5 then -- Profile
  197.                 local p,e = values[2],values[3]
  198.                 if not e and mice[p] then
  199.                     local register,friends,lastConnection = mice[p].profile[1],#mice[p].friends[1],mice[p].profile[4]
  200.                     local nickname = (mice[p].profile[2]=="" and (n==p and "<BV><a href='event:addnickname'>Adicionar</a>" or "-") or (n==p and "<a href='event:addnickname'>" or "")..mice[p].profile[2]..(n==p and "</a>" or ""))
  201.                     local gender = mice[p].profile[3]..(n==p and " <J>(<N><a href='event:gender1'>Indefinido</a> <G>| <CH><a href='event:gender2'>Masc.</a> <G>| <S><a href='event:gender3'>Fem.</a><J>)" or "")
  202.                     local publications,likedPublications,sharedPublications = mice[p].actions[1],mice[p].actions[2],mice[p].actions[3]
  203.                     text(21,"<p align='center'><font face='Impact' size='25'><V>"..p.." "..(n==p and "" or (table.find(mice[n].friends[1],p) and "<J><a href='event:unadd_"..p.."'>★</a></font>" or "<font size='20'><VP><a href='event:add_"..p.."'>★</a></font>")).."<J>\n<font size='15' face='Calibri,Verdana'><p align='left'><J><B>Data de registro : </B><V>"..register.."\n<J><B>Apelido : </B><V>"..nickname.."\n<J><B>Gênero : </B><V>"..gender.."\n<J><B>Amigos : </B><V>"..friends.."\n<J><B>Publicações : </B><V>"..publications.."\n<J><B>Publicações curtidas : </B><V>"..likedPublications.."\n<J><B>Publicações compartilhadas : </B><V>"..sharedPublications.."\n<J><B>Última vez online : </B><V>"..lastConnection,n,355,185,300,205,0x505553,0x455a4e,1,true)
  204.                 else
  205.                     ui.removeTextArea(21,n)
  206.                 end
  207.             end
  208.             if id == 6 then -- Search
  209.                 local found,e = values[2],values[3]
  210.                 if not e then
  211.                     text(22,"",n,396,205,250,50,0x212E35,0x212E35,1)
  212.                     ui.addPopup(1,2,"",n,396,207,250)
  213.                     text(23,"",n,376,188,25,185,0x37385b,0x37385b,1,true)
  214.                     text(24,"",n,640,188,25,185,0x37385b,0x37385b,1,true)
  215.                     text(25,"\n<p align='center'><PT>Search a nickname below!</p>",n,393,188,251,30,0x37385b,0x37385b,1,true)
  216.                     text(26,found or "",n,403,247,243,126,0x37385b,0x37385b,1,true)
  217.                 else
  218.                     for i = 22,26 do
  219.                         ui.removeTextArea(i,n)
  220.                     end
  221.                     ui.addPopup(1,2,"",n,-3500,-3500)
  222.                 end
  223.             end
  224.             if id == 7 then -- Chat
  225.                 local e = values[2]
  226.                 if not e then
  227.                     text(27,"",n,232,185,555,205,0x3d1c29,0x3d1c29,1,true)
  228.                 else
  229.                     ui.removeTextArea(27,n)
  230.                 end
  231.             end
  232.         end
  233.     end
  234. end
  235. --[[ Events ]]--
  236.     --[[ Timer ]]--
  237. addEvent("Loop",function()
  238.     if os.time()>system.newsTimer then
  239.         system.newsTimer = os.time() + 20000
  240.         table.foreach(tfm.get.room.playerList,interface.updateNews)
  241.     end
  242. end)
  243.     --[[ Welcome ]]--
  244. addEvent("Loop",function(currentTime)
  245.     if currentTime % 5 == 0 then
  246.         ui.setMapName("<BL>"..("@"):rep(15).."<BV> Welcome to the TFM SCNewtwork <BL>"..("@"):rep(15).."<")
  247.     else
  248.         ui.setMapName("<")
  249.     end
  250. end)
  251.     --[[ Mice - NewPlayer ]]--
  252. eventNewPlayer=function(n)
  253.     if not mice[n] then
  254.         mice[n] = {
  255.             profile = {
  256.                 [1] = os.date("%d/%m/%Y"), -- Register
  257.                 [2] = "", -- Nickname
  258.                 [3] = "Indefinido", -- Gender
  259.                 [4] = os.date("%X"), -- Last Connection
  260.                 [5] = false,
  261.             },
  262.             friends = {
  263.                 [1] = {}, -- List
  264.                 [2] = false,
  265.             },
  266.             timelines = {
  267.                 [1] = {},
  268.                 [2] = false,
  269.                 [3] = "",
  270.                 [4] = "",
  271.             },
  272.             search = false,
  273.             actions = {
  274.                 [1] = 0, -- Plublications
  275.                 [2] = 0, -- Liked Publications
  276.                 [3] = 0, -- Shared Publications
  277.             },
  278.             chats = false,
  279.         }
  280.     end
  281.     mice[n].profile[4] = os.date("%X")
  282.     interface.main(n)
  283. end
  284. eventPlayerLeft=function(n)
  285.     mice[n].profile[4]=os.date("%X")
  286. end
  287. table.foreach(tfm.get.room.playerList,eventNewPlayer)
  288.     --[[ Open / Close ]]--
  289. addEvent("TextAreaCallback",function(_,n,command)
  290.     if command == 'timelines' then
  291.         interface.timelines(n,mice[n].timelines[2])
  292.         mice[n].timelines[2] = not mice[n].timelines[2]
  293.     end
  294.     if command == 'friends' then
  295.         interface.friends(n,mice[n].friends[2])
  296.         mice[n].friends[2] = not mice[n].friends[2]
  297.     end
  298.     if command:sub(1,1) == "@" then
  299.         command = command:sub(2)
  300.         interface.profile(n,command,mice[n].profile[5])
  301.         mice[n].profile[5] = not mice[n].profile[5]
  302.     end
  303.     if command:sub(1,6) == 'gender' then
  304.         local genders = {'Indefinido','Masculino','Feminino'}
  305.         local id = tonumber(command:sub(7))
  306.         mice[n].profile[3] = genders[id]
  307.         interface.profile(n,n,false)
  308.     end
  309.     if command == 'resettimelines' then
  310.         interface.timelines(n,false)
  311.     end
  312.     if command == 'chat' then
  313.         interface.chat(n,mice[n].chats)
  314.         mice[n].chats=not mice[n].chats
  315.     end
  316. end)
  317.     --[[ Popup / Timelines ]]--
  318. addEvent("TextAreaCallback",function(_,n,c)
  319.     if c == 'addnickname' then
  320.         interface.profile(n,n,true)
  321.         ui.addPopup(0,2,"Digite aqui seu apelido.",n,360,278,293)
  322.     end
  323.     if c == 'search' then
  324.         interface.search(n,'',mice[n].search)
  325.         mice[n].search = not mice[n].search
  326.     end
  327.     if c=='newpost' then
  328.         interface.timelines(n,true)
  329.         ui.addPopup(2,2,"Digite aqui a sua publicação",n,360,278,293)
  330.     end
  331.     if c:sub(1,9)=='likepost_' or c:sub(1,10)=='sharepost_' then
  332.         _c = tonumber(c:match('._(%d+)'))
  333.         local _table = mice[n].timelines[1][_c]
  334.         local name = _table[1]
  335.         local l = (c:sub(1,4)=='like' and 'curtiu' or c:sub(1,5)=='share' and 'compartilhou' or "")
  336.         local t = "<V><B>[<a href='event:@"..n.."'>"..n.."</a>]</B><J> "..l.." a publicação de <V><a href='event:@"..name.."'>"..name.."</a> <BL><B>[<a href='event:post_".._c.."'>".._table[3]:sub(1,10)..(#_table[3]>10 and "</a><J>...</J>" or "</a>").."]</B></BL>"
  337.         table.insert(mice[n].timelines[1],t)
  338.         table.foreach(tfm.get.room.playerList,function(x) if table.find(mice[x].friends[1],n) then table.insert(mice[x].timelines[1],t) end end)
  339.         local numb=(c:sub(1,1)=='l' and 2 or 3);mice[n].actions[numb]=mice[n].actions[numb]+1
  340.         interface.timelines(n,false)
  341.     end
  342.     if c:sub(1,10)=='quotepost_' then
  343.         mice[n].timelines[4] = c
  344.         c = tonumber(c:match('._(%d+)'))
  345.         local _table = mice[n].timelines[1][c]
  346.         local name = _table[1]
  347.         if mice[n].timelines[3]=="" then
  348.             ui.addPopup(3,2,"Digite aqui seu comentário.",n,360,278,293)
  349.         else
  350.             local t = "<V><B>[<a href='event:@"..n.."'>"..n.."</a>]</B><J> citou a publicação de <V><a href='event:@"..name.."'>"..name.."</a> <BL><B>[<a href='event:post_"..c.."'>".._table[3]:sub(1,10)..(#_table[3]>10 and "</a><J>...</J>" or "</a>").."]</B> : </BL><VP>"..(mice[n].timelines[3] or "")
  351.             table.insert(mice[n].timelines[1],t)
  352.             table.foreach(tfm.get.room.playerList,function(x) if table.find(mice[x].friends[1],n) then table.insert(mice[x].timelines[1],t) end end)
  353.         end
  354.     end
  355. end)
  356.     --[[ Post ]]--
  357. addEvent("TextAreaCallback",function(_,n,c)
  358.     if c:sub(1,5)=='post_' then
  359.         c = tonumber(c:match('._(%d+)'))
  360.         local _table = mice[n].timelines[1][c]
  361.         local name = _table[1]
  362.         ui.updateTextArea(15,"<G><B>[<U><BL><a href='event:resettimelines'>Voltar</a></BL></U>]</B></G>\n\n<J>From <V>"..name.." <BL> : \n ".._table[3] or "-",n)
  363.     end
  364. end)
  365.     --[[ Friend List ]]--
  366. addEvent("TextAreaCallback",function(_,n,c)
  367.     if c:sub(1,4)=='add_' then
  368.         c = c:sub(5)
  369.         table.insert(mice[n].friends[1],c)
  370.         interface.profile(n,c,false)
  371.     end
  372.     if c:sub(1,6)=='unadd_' then
  373.         c = c:sub(7)
  374.         table.destroy(mice[n].friends[1],c)
  375.         interface.profile(n,c,false)
  376.     end
  377. end)
  378.     --[[ Popup ]]--
  379. addEvent("PopupAnswer",function(i,n,c)
  380.     if i==0 then
  381.         if c ~= nil then
  382.             local nick=string.split(c,1,'%S')
  383.             mice[n].profile[2]=string.nick(table.concat(nick)):sub(1,(string.find(nick[1],"%p") and 13 or 12))
  384.         end
  385.         interface.profile(n,n,false)
  386.     end
  387.     if i==1 then
  388.         c=string.nick(c)
  389.         local t = ""
  390.         for i,v in next,mice do
  391.             local bo,pe = string.equal(i,c)
  392.             if pe > 40 and #c>2 and i~=n then
  393.                 t = t .. ("<G>_"):rep(10)..("\n<J>Name : <V><a href='event:@"..i.."'>"..i.."</a>\n<J>Apelido : <V>%s\n<J>Amigos : <V>%s\n<J>Última vez online: <J>%s"):format((mice[i].profile[2]~="" and mice[i].profile[2] or '<R>-<R>'),#mice[i].friends[1],mice[i].profile[4]) .. '\n'
  394.             end
  395.         end
  396.         if mice[n].search then
  397.             interface.search(n,(t~="" and t or "<R>No results"),false)
  398.         end
  399.     end
  400.     if i==2 then
  401.         if #c > 4 then
  402.             local txt = "<V><B>[<a href='event:@"..n.."'>"..n.."</a>]</B><J> publicou : <N><a href='event:post_"..(#mice[n].timelines[1]+1).."'>"..c:sub(1,35)..(#c>35 and "</a><J>..." or "</a>").." <G><B>|</B> <BV><a href='event:likepost_"..(#mice[n].timelines[1]+1).."'>Curtir</a> <G>| <BV><a href='event:sharepost_"..(#mice[n].timelines[1]+1).."'>Compartilhar</a> <G>| <BV><a href='event:quotepost_"..(#mice[n].timelines[1]+1).."'>Citar</a>"
  403.             mice[n].actions[1] = mice[n].actions[1] + 1
  404.             table.insert(mice[n].timelines[1],{n,txt,c})
  405.             table.foreach(tfm.get.room.playerList,function(x) if table.find(mice[x].friends[1],n) then table.insert(mice[x].timelines[1],{n,txt,c}) end end)
  406.         end
  407.         interface.timelines(n,false)
  408.     end
  409.     if i==3 and #c>1 then
  410.         mice[n].timelines[3] = c:sub(1,50) .. (#c>50 and "<R>..." or "")
  411.         eventTextAreaCallback(nil,n,mice[n].timelines[4])
  412.         mice[n].timelines[3] = ""
  413.         interface.timelines(n,false)
  414.     end
  415. end)
  416.     --[[ Chat Commands ]]--
  417. addEvent("ChatMessage",function(n,c)
  418.     local p = string.split(c,0)
  419.     if p[1]:lower() == "open" or p[1]:lower() == "close" then
  420.         p[1] = p[1]:lower()
  421.         p[2] = p[2]:lower()
  422.         local x = {"timelines","friends","search",mice[n].timelines[2],mice[n].friends[2],mice[n].search}
  423.         local bo,pos = table.find(x,p[2])
  424.         if bo then
  425.             if x[pos+3]==(p[1]=="close" and true or false) then
  426.                 eventTextAreaCallback(nil,n,p[2])
  427.             end
  428.         end
  429.     end
  430.     if p[1]:lower() == "profile" then
  431.         if p[2] and #p[2]>3 then
  432.             p[2] = string.nick(p[2])
  433.             if tfm.get.room.playerList[p[2]] then
  434.                 eventTextAreaCallback(nil,n,'@'..p[2])
  435.             end
  436.         else
  437.             eventTextAreaCallback(nil,n,'@'..n)
  438.         end
  439.     end
  440.     if p[1]:lower() == "new" and p[2]:lower() == "post" then
  441.         if mice[n] then
  442.             eventChatMessage(n,"open timelines")
  443.             eventTextAreaCallback(nil,n,'newpost')
  444.         end
  445.     end
  446.     if p[1]:lower() == "add" or p[1]:lower() == "unadd" then
  447.         p[1] = p[1]:lower()
  448.         if p[2] and #p[2]>3 then
  449.             p[2] = string.nick(p[2])
  450.             if mice[p[2]] then 
  451.                 eventChatMessage(n,"profile "..p[2])
  452.                 eventTextAreaCallback(nil,n,p[1].."_"..p[2])
  453.             end
  454.         end
  455.     end
  456.     if p[1]:lower() == "search" and p[2] then
  457.         eventChatMessage(n,"open search")
  458.         eventPopupAnswer(1,n,p[2])
  459.     end
  460. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement