Advertisement
podoko_Lua

UNO [v1.05]

May 18th, 2014
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.82 KB | None | 0 0
  1. --[[    UNO v1.05
  2.     Pensez à mettre vous mettre en admin (voir ligne 8)
  3.     Liste des commandes :   !inv pseudo => Permet d'inviter un joueur à la prochaine partie
  4.                 !new => Permet de lancer une nouvelle partie
  5.                 !init => Permet de réinitialiser le module (à ne pas utiliser)
  6.   ]]
  7.  
  8. admin = "Pseudo"     -- Remplacez Pseudo par votre pseudo (entre les "")
  9.  
  10.  --------------------------------------
  11.  --  Évitez de toucher à ce qui suit --
  12.  --------------------------------------
  13.  
  14. color = { 'R', 'J', 'V', 'BL' }
  15. special = { "+2" , "↔", "Ø" }
  16.  
  17.  
  18. function initC ()
  19.     for k, v in ipairs(color) do
  20.         for n=1, 19 do
  21.             table.insert(cartes, { ["color"]=v, ["value"]=n%10 })
  22.         end
  23.         for l, w in ipairs(special) do
  24.             table.insert(cartes, { ["color"]=v, ["value"]=w })
  25.         end
  26.     end
  27.     for k=1, 4 do
  28.         table.insert(cartes, { ["color"]="ROSE", ["value"]="+4" })
  29.         table.insert(cartes, { ["color"]="ROSE", ["value"]="C" })
  30.     end
  31. end
  32.  
  33. function initP ()
  34.    
  35.     paquet = {}
  36.     local n = 0
  37.     while #cartes ~= 0 do
  38.         n = math.random(#cartes)
  39.         table.insert(paquet, cartes[n])
  40.         table.remove(cartes, n)
  41.     end
  42. end
  43.  
  44. function init ()
  45.     initC()
  46.     initP()
  47.    
  48.     for id in ipairs(playerL) do
  49.         playerL[id]["cards"]={}
  50.         giveCards(id, 7)
  51.         ui.addTextArea (0, geneTJ (id), playerL[id]["name"], 5, 30, 790, 18, 1, 1, 0.75, true)
  52.     end
  53.     ui.addTextArea (-1, geneTA (), nil, 375, 150, 50, 30, 1, 1, 0.5, true)
  54.     ui.addTextArea (-2, "C'est à <R><b>"..playerL[playerA]["name"].."</b><font color='#C2C2DA'> de jouer.</font>", nil, 75, 60, 200, 20, 1, 1, 0.5, true)
  55.     ui.addTextArea (-3, "<a href='event:pass 1'><b>passer</b></a>", nil, 5, 60, 60, 20, 1, 0, 0.75, true)
  56.     ui.addTextArea (-4, geneTL(), nil, 5, 90, 110, 100, 1, 1, 0.5, true)
  57.    
  58. end
  59.  
  60.  
  61.  
  62.  
  63. function eventTextAreaCallback (id, name, call)
  64.  
  65.     local idN = findId(name)
  66.        
  67.     if name == playerL[playerA]["name"] and ig then
  68.         if string.sub(call, 0, 4) == "pass" then
  69.             giveCards (idN, tonumber(string.sub(call, 6)))
  70.            
  71.             endT()
  72.         else
  73.             local c = playerL[idN]["cards"][tonumber(call)]
  74.            
  75.             if valide(c) then
  76.                 if c.value == "+2" then
  77.                     endT()
  78.                     giveCards ( playerA, 2)
  79.                 elseif c.value == "+4" then
  80.                     endT()
  81.                     giveCards (playerA, 4)
  82.                 elseif c.value == "Ø" then
  83.                     endT()
  84.                 elseif c.value == "↔" then
  85.                     sens = -sens
  86.                 end
  87.            
  88.             table.insert(paquet, c)
  89.             table.remove(playerL[idN]["cards"], tostring(call))
  90.  
  91.             endT()
  92.             end
  93.            
  94.         end
  95.         for id, tab in ipairs(playerL) do
  96.             ui.updateTextArea (0, geneTJ(id), tab.name)
  97.         end
  98.     end
  99. end
  100.  
  101.  
  102.  
  103.  
  104.  
  105. function geneTJ (id)
  106.     local s =""
  107.     for k, v in ipairs(playerL[id]["cards"]) do
  108.         s = s.."   <"..v.color.."><a href='event:"..tostring(k).."'>"..v.value.."</a>"
  109.     end
  110.  
  111.     return "<p align='center'><b>"..s.."   </b></p>"
  112. end
  113.  
  114. function geneTA ()
  115.     local c = paquet[#paquet]
  116.     return "<p align='center'><font size='20'><"..c.color.."><b>"..c.value.."</b></N></font></a>"
  117.    
  118. end
  119.  
  120. function geneTL ()
  121.     local s =""
  122.     for id, tab in ipairs(playerL) do
  123.         s = s..tab.name.." : "..#tab.cards.."\n"
  124.     end
  125.     return s
  126. end
  127.  
  128.  
  129.  
  130. function valide (tab)
  131.     local c = paquet[#paquet]
  132.     return (c.value == tab.value) or (c.color == tab.color) or (tab.color == "ROSE") or (c.color == "ROSE")
  133. end
  134.  
  135. function endT ()
  136.    
  137.     ui.updateTextArea(-1, geneTA(), nil)
  138.     if #playerL[playerA]["cards"] == 0 then
  139.         ui.addPopup (1, 0, "<p align='center'>"..playerL[playerA]["name"].." vient de gagner !!\nFélicitations à lui</p>", nil, 300, 150, 200, true)
  140.         ig = false
  141.     end
  142.     if sens == -1 then playerA = (playerA-2)%#playerL +1 else playerA = (playerA%#playerL)+1 end
  143.     ui.updateTextArea(-2, "C'est à <R><b>"..playerL[playerA]["name"].."</b><font color='#C2C2DA'> de jouer.</font>", nil)
  144.     ui.updateTextArea(-4, geneTL(), nil)
  145.    
  146.    
  147. end
  148.  
  149. function giveCards (idP, nb)
  150.     table.insert(playerL[idP]["cards"], paquet[1])
  151.     table.remove(paquet, 1)
  152.     if nb > 1 then giveCards(idP, nb-1) end
  153. end
  154.  
  155.  
  156.  
  157.  
  158.  
  159. function findId (name)
  160.     for id, tab in ipairs(playerL) do
  161.         if tab["name"] == name then return id end
  162.     end
  163. end
  164.  
  165.  
  166.  
  167. function eventPopupAnswer (id, name, answer)
  168.     if (answer == "yes") and (ig ~= true) then
  169.         table.insert(playerL, {["name"]=name, ["cards"]={} })
  170.     end
  171. end
  172.  
  173.  
  174.  
  175. function eventChatCommand (name, command)
  176.     if name == admin then
  177.         if command == "new" then
  178.             playerA = 1
  179.             cartes = {}
  180.             paquet = {}
  181.             sens = 1
  182.             init()
  183.             ig = true
  184.         elseif command == "init" then
  185.             playerL = {}
  186.             playerA = 1
  187.             cartes = {}
  188.             paquet = {}
  189.             sens = 1
  190.             ig = false
  191.         elseif (string.sub(command, 1, 3) == "inv") and (ig ~= true) then
  192.             ui.addPopup(1, 1, admin.." t'invite à faire une partie de UNO. Tu acceptes ?", string.sub(command, 5), 350, 180, 200, true)
  193.        
  194.         elseif string.sub(command, 1, 4)=="pass" then
  195.             endT()
  196.        
  197.         end
  198.     end
  199. end
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208. eventChatCommand (admin, "init")
  209. eventPopupAnswer (1, admin, "yes")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement