Advertisement
podoko_Lua

UNO [v1.01]

May 9th, 2014
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.63 KB | None | 0 0
  1. --[[    UNO v1.01
  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 à "..playerL[playerA]["name"].." de jouer.", 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.     if name == playerL[playerA]["name"] and ig then
  67.         if string.sub(call, 0, 4) == "pass" then
  68.             giveCards (idN, tonumber(string.sub(call, 6)))
  69.            
  70.             endT()
  71.         else
  72.             local c = playerL[idN]["cards"][tonumber(call)]
  73.            
  74.             if valide(c) then
  75.                 if c.value == "+2" then
  76.                     endT()
  77.                     giveCards ( playerA, 2)
  78.                 elseif c.value == "+4" then
  79.                     endT()
  80.                     giveCards (playerA, 4)
  81.                 elseif c.value == "Ø" then
  82.                     endT()
  83.                 elseif c.value == "↔" then
  84.                     sens = -sens
  85.                 end
  86.            
  87.             table.insert(paquet, c)
  88.             table.remove(playerL[idN]["cards"], tostring(call))
  89.  
  90.             endT()
  91.             end
  92.            
  93.         end
  94.         for id, tab in ipairs(playerL) do
  95.             ui.updateTextArea (0, geneTJ(id), tab.name)
  96.         end
  97.     end
  98. end
  99.  
  100.  
  101.  
  102.  
  103.  
  104. function geneTJ (id)
  105.     local s =""
  106.     for k, v in ipairs(playerL[id]["cards"]) do
  107.         s = s.."   <"..v.color.."><a href='event:"..tostring(k).."'>"..v.value.."</a>"
  108.     end
  109.  
  110.     return "<p align='center'><b>"..s.."   </b></p>"
  111. end
  112.  
  113. function geneTA ()
  114.     local c = paquet[#paquet]
  115.     return "<p align='center'><font size='20'><"..c.color.."><b>"..c.value.."</b></N></font></a>"
  116.    
  117. end
  118.  
  119. function geneTL ()
  120.     local s =""
  121.     for id, tab in ipairs(playerL) do
  122.         s = s..tab.name.." : "..#tab.cards.."\n"
  123.     end
  124.     return s
  125. end
  126.  
  127.  
  128.  
  129. function valide (tab)
  130.     local c = paquet[#paquet]
  131.     return (c.value == tab.value) or (c.color == tab.color) or (tab.color == "ROSE") or (c.color == "ROSE")
  132. end
  133.  
  134. function endT ()
  135.    
  136.     ui.updateTextArea(-1, geneTA(), nil)
  137.     if #playerL[playerA]["cards"] == 0 then
  138.         ui.addPopup (1, 0, "<p align='center'>"..playerL[playerA]["name"].." vient de gagner !!\nFélicitations à lui</p>", nil, 300, 150, 200, true)
  139.         ig = false
  140.     end
  141.     if sens == -1 then playerA = (playerA-2)%#playerL +1 else playerA = (playerA%#playerL)+1 end
  142.     ui.updateTextArea(-2, "C'est à "..playerL[playerA]["name"].." de jouer", nil)
  143.     ui.updateTextArea(-4, geneTL(), nil)
  144.    
  145.    
  146. end
  147.  
  148. function giveCards (idP, nb)
  149.     table.insert(playerL[idP]["cards"], paquet[1])
  150.     table.remove(paquet, 1)
  151.     if nb > 1 then giveCards(idP, nb-1) end
  152. end
  153.  
  154.  
  155.  
  156.  
  157.  
  158. function findId (name)
  159.     for id, tab in ipairs(playerL) do
  160.         if tab["name"] == name then return id end
  161.     end
  162. end
  163.  
  164.  
  165.  
  166. function eventPopupAnswer (id, name, answer)
  167.     if (answer == "yes") and (ig ~= true) then
  168.         table.insert(playerL, {["name"]=name, ["cards"]={} })
  169.     end
  170. end
  171.  
  172.  
  173.  
  174. function eventChatCommand (name, command)
  175.     if name == admin then
  176.         if command == "new" then
  177.             playerA = 1
  178.             cartes = {}
  179.             paquet = {}
  180.             sens = 1
  181.             init()
  182.             ig = true
  183.         elseif command == "init" then
  184.             playerL = {}
  185.             playerA = 1
  186.             cartes = {}
  187.             paquet = {}
  188.             sens = 1
  189.             ig = false
  190.         elseif (string.sub(command, 1, 3) == "inv") and (ig ~= true) then
  191.             ui.addPopup(1, 1, admin.." t'invite à faire une partie de UNO. Tu acceptes ?", string.sub(command, 5), 350, 180, 200, true)
  192.         end
  193.     end
  194. end
  195.  
  196. eventChatCommand (admin, "init")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement