Guest User

Untitled

a guest
Feb 12th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '#####################
  2. '# UNI script v 1.0  #
  3. '# Author: Morio     #
  4. '#####################
  5.  
  6. 'Commands:
  7. '!uno   - starts a new game (if a game is not being played at the moment)
  8. '!join  - join a game
  9. '!play  - play a card
  10. '!draw  - draw a card from the deck
  11. '!pass  - pass over your turn to the next player (can only be done if you have already drawn a card from the deck
  12. '!stop  - stops the game (for the gamestarter and operators only)
  13. '!help  - shows a list of commands
  14.  
  15.  
  16. Dim Players,TotalCards,CardsInDeck,UnoChannel,GameStarter,NewString,CardOnTop,CardsOnTable,Playerlist,Turn,HasDrawn,HasStarted
  17. Set Players = CreateObject("Scripting.Dictionary")
  18.  
  19. 'all cards found in a deck
  20. TotalCards = "p:0,p:1,p:1,p:2,p:2,p:3,p:3,p:4,p:4,p:5,p:5,p:6,p:6,p:7,p:7,p:8,p:8,p:9,p:9,p:dr2,p:dr2,p:r,p:r,p:s,p:s,b:0,b:1,b:1,b:2,b:2,b:3,b:3,b:4,b:4,b:5,b:5,b:6,b:6,b:7,b:7,b:8,b:8,b:9,b:9,b:dr2,b:dr2,b:r,b:r,b:s,b:s,r:0,r:1,r:1,r:2,r:2,r:3,r:3,r:4,r:4,r:5,r:5,r:6,r:6,r:7,r:7,r:8,r:8,r:9,r:9,r:dr2,r:dr2,r:r,r:r,r:s,r:s,g:0,g:1,g:1,g:2,g:2,g:3,g:3,g:4,g:4,g:5,g:5,g:6,g:6,g:7,g:7,g:8,g:8,g:9,g:9,g:dr2,g:dr2,g:r,g:r,g:s,g:s,y:0,y:1,y:1,y:2,y:2,y:3,y:3,y:4,y:4,y:5,y:5,y:6,y:6,y:7,y:7,y:8,y:8,y:9,y:9,y:dr2,y:dr2,y:r,y:r,y:s,y:s,wild,wild,wild,wild,wd4,wd4,wd4,wd4"
  21. 'put the cards to the deck
  22. CardsInDeck = TotalCards
  23.  
  24. UnoChannel = ""
  25. PlayerList = ""
  26. HasStarted = False
  27. Turn = 0
  28. HasDrawn = False
  29.  
  30. Sub ONTEXT(Message,Channel,Nickname,Host,ServerNumber)
  31.     Message = LCase(Message)
  32.     If not Channel = "#lru" then Exit Sub 'can be used to make the script work on a specific channel only (recommended)
  33.    
  34.     If UnoChannel = "" then
  35.         CardOnTop = ""
  36.         If Message = "!uno" then
  37.             UnoChannel = Channel
  38.             GameStarter = Nickname
  39.             HasStarted = False
  40.             SendCommand "/msg " & Channel & " " & Nickname & " started a game of uno. Type !join to join. The game will start in 30s",ServerNumber
  41.             'start the game after 30s
  42.             SendCommand "/timer unotimer 1 30 /! PlayUNO " & "newgame|"  & UnoChannel & "|" & ServerNumber & "|newgame"
  43.  
  44.             'shuffle the deck
  45.             ArrayShuffle Split(TotalCards,","), True
  46.             CardsInDeck = NewString
  47.  
  48.         End If
  49.     Else
  50.         If Not Channel = UnoChannel then Exit Sub
  51.         If Message = "!join" then AddUnoPlayer Nickname,Channel,ServerNumber 'joining the game
  52.        
  53.         If Left(Message,6) = "!play " and Len(Message) > 6 then 'playing a card
  54.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  55.             If Players.exists(Nickname) then
  56.                 Card = Mid(Message,7)
  57.                 Card = Replace(Card, " ", "")
  58.                 If Left(Card,1) = "w" then
  59.                 Card = Left(Card, Len(Card)-1) & " " & Right(Card, 1)
  60.                 End If
  61.                 If Card = "newgame" then Exit Sub
  62.                 If Not Left(Card,1) = "w" then
  63.                 Card = Left(Card,1) & ":" & Mid(Card,2)
  64.                 End If
  65.                 PlayUNO Nickname,Channel,ServerNumber,Card
  66.             Else
  67.                 SendCommand "/msg " & Channel & " " & Nickname & ": you haven't joined the game yet, type !join to join",ServerNumber
  68.             End If
  69.        
  70.         ElseIf Message = "!draw" and HasDrawn = False then 'drawing a card from the deck
  71.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  72.             NewCard = GetNewCards(1)
  73.             Players.item(Nickname) = Players.item(Nickname) & "," & NewCard
  74.             HasDrawn = True
  75.             If Not NewCard = "" then
  76.                 SendCommand "/notice " & Nickname & " --- You drew: " & AddColors(NewCard),ServerNumber
  77.             Else
  78.                 SendCommand "/msg " & Channel & " Not enough cards in the deck, use !pass to pass your turn",ServerNumber
  79.             End If
  80.         ElseIf Message = "!pass" then 'passing your turn
  81.             If Not Nickname = GetCurrentPlayer(Turn) then Exit Sub
  82.             If HasDrawn = True then
  83.                 If Nickname = Kitsune then
  84.                     SendCommand "/msg " & Channel & " " & Nickname & " Passes hizzle turzzle. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  85.                     SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- Your cards: " & AddColors(Players.item(GetCurrentPlayer(Turn+1))),ServerNumber
  86.                 If Not Nickname = Kitsune then 
  87.                     SendCommand "/msg " & Channel & " " & Nickname & " Passes his turn. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  88.                     SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- Your cards: " & AddColors(Players.item(GetCurrentPlayer(Turn+1))),ServerNumber
  89.                 End If 
  90.                     Turn = Turn + 1
  91.                 HasDrawn = False
  92.             Else
  93.                 SendCommand "/msg " & Channel & " " & Nickname & ": You need to !draw before you can !pass",ServerNumber
  94.             End If
  95.  
  96.         ElseIf Message = "!cards" then 'wiev your cards
  97.             Plays = False
  98.             AllPlayers = Players.keys
  99.                 For i = 0 to UBound(AllPlayers)
  100.                     If Nickname = AllPlayers(i) then
  101.                         Plays = True
  102.                         Exit For
  103.                     End If
  104.                 Next
  105.                 If Plays = True then
  106.                     SendCommand "/notice " & Nickname & " --- Your cards are: " & AddColors(Players.item(Nickname)),ServerNumber
  107.                 Else
  108.                     SendCommand "/notice " & Nickname & " --- you are not in the game, type !join to join",ServerNumber
  109.                 End If
  110.  
  111.         ElseIf Message = "!count" then 'show how many cards each player has
  112.             AllPlayers = Players.keys
  113.             PlayerCount = ""
  114.             For i = 0 to UBound(AllPlayers)
  115.                 NumberOfCards = UBound(Split(Players.item(AllPlayers(i)),",")) + 1
  116.                 If PlayerCount = "" then
  117.                     PlayerCount = AllPlayers(i) & ": " & NumberOfCards
  118.                 Else
  119.                     PlayerCount = PlayerCount & ", " & AllPlayers(i) & ": " & NumberOfCards
  120.                 End If
  121.             Next
  122.             SendCommand "/msg " & Channel & " [" & PlayerCount & "]",ServerNumber
  123.  
  124.         ElseIf Message = "!turn" then 'show whose turn it is
  125.             SendCommand "/msg " & Channel & " Current turn: " & GetCurrentPlayer(Turn),ServerNumber
  126.            
  127.         ElseIf Message = "!quit" then 'quit the game
  128.             AllPlayers = Players.keys
  129.             For i = 0 to UBound(AllPlayers)
  130.                 If AllPlayers(i) = Nickname then RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  131.             Next
  132.         ElseIf Message = "!card"  and HasStarted = True then 'show the top card on the table
  133.             If InStr(CardsOnTable,",") > 0 then
  134.                 TopCard = Left(CardsOnTable,InStr(CardsOnTable,",")-1)
  135.             Else
  136.                 TopCard = CardsOnTable
  137.             End If
  138.  
  139.             If Mid(TopCard,3,1) = "w" then
  140.             CardColor = Left(TopCard,1)
  141.             CardType = Mid(TopCard,3)
  142.                 if CardColor = "b" then
  143.                     NewColor2 = "1,12 BLUE "
  144.                 Elseif CardColor = "g" then
  145.                     NewColor2 = "1,9 GREEN "
  146.                 Elseif CardColor = "y" then
  147.                     NewColor2 = "1,8 YELLOW "
  148.                 Elseif CardColor = "r" then
  149.                     NewColor2 = "1,4 RED "
  150.                 Elseif CardColor = "p" then
  151.                     NewColor2 = "1,13 PINK "
  152.                 End If
  153.                 SendCommand "/msg " & Channel & " The Card on top is: " & GetLongCardName(CardType) & " and the color is: " & NewColor2,ServerNumber
  154.             Else
  155.                 SendCommand "/msg " & Channel & " The Card on top is: " & GetLongCardName(TopCard)
  156.             End If
  157.            
  158.         ElseIf Message = "!stop" and (Nickname = GameStarter or IsOp(Nickname,Channel,ServerNumber))then 'stop the game (gamestarter and operators only)
  159.             SendCommand "/msg " & Channel & " Game stopped by: " & Nickname,ServerNumber
  160.             GameOver Nickname,Channel,False,ServerNumber
  161.             If HasStarted = False then SendCommand "/timer unotimer off",ServerNumber
  162.         ElseIf Message = "!help" then
  163.             SendCommand "/notice " & Nickname & " --- Commands available: !uno, !join, !play, !draw, !pass, !stop",ServerNumber
  164.  
  165.         End If
  166.     End If
  167.    
  168. End Sub
  169.  
  170. 'when changing nickname, your cards are transferred to the new nick, and your turn in the game is preserved
  171. Sub ONNICK(NewNick,OldNick,ServerNumber)
  172.     AllPlayers = Players.keys
  173.     PlayerList = ""
  174.     For i = 0 to UBound(AllPlayers)
  175.         If AllPlayers(i) = OldNick then
  176.             Players.add NewNick, Players.item(OldNick)
  177.             Players.remove(OldNick)
  178.             If OldNick = GameStarter then GameStarter = NewNick
  179.             If PlayerList = "" then
  180.                 PlayerList = NewNick
  181.             Else
  182.                 PlayerList = PlayerList & "," & NewNick
  183.             End If
  184.            
  185.         Else
  186.             If PlayerList = "" then
  187.                 PlayerList = AllPlayers(i)
  188.             Else
  189.                 PlayerList = PlayerList & "," & AllPlayers(i)
  190.             End If
  191.            
  192.         End If
  193.     Next
  194. End Sub
  195.  
  196. 'if you part the channel you quit the game
  197. Sub ONPART(Nickname,Host,Channel,Reason,ServerNumber)
  198.     AllPlayers = Players.keys
  199.     For i = 0 to UBound(AllPlayers)
  200.         If AllPlayers(i) = Nickname then
  201.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  202.         End If
  203.     Next
  204. End Sub
  205.  
  206. 'if you quit from the server, you quit the game
  207. Sub ONQUIT(Nickname,Host,Reason,ServerNumber)
  208.     AllPlayers = Players.keys
  209.     For i = 0 to UBound(AllPlayers)
  210.         If AllPlayers(i) = Nickname then
  211.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  212.         End If
  213.     Next
  214. End Sub
  215.  
  216. 'if you get kicked, you quit the game
  217. Sub ONKICK(Nickname,Host,Channel,WhoKicked,Reason,ServerNumber)
  218.     AllPlayers = Players.keys
  219.     For i = 0 to UBound(AllPlayers)
  220.         If AllPlayers(i) = Nickname then
  221.             RemoveUNOPlayer Nickname,UnoChannel,ServerNumber
  222.         End If
  223.     Next
  224. End Sub
  225.  
  226. 'this sub adds a new player to the game
  227. Sub AddUNOPlayer(Nickname,Channel,ServerNumber)
  228.     If Not Players.exists(Nickname) then 'if he hasn't joined yet
  229.         NewPlayerCards = GetNewCards(7) 'draw 7 cards from the top of the deck
  230.         If Not NewPlayerCards = "" then
  231.             Players.add Nickname, NewPlayerCards
  232.             SendCommand "/msg " & UnoChannel & " " & Nickname & " joined the game",ServerNumber
  233.             SendCommand "/notice " & Nickname & " --- Your cards are: " & AddColors(NewPlayerCards)
  234.             If PlayerList = "" then
  235.                 PlayerList = Nickname
  236.             Else
  237.                 PlayerList = PlayerList & "," & Nickname 'add the player to the playerlist
  238.             End If
  239.         Else 'if there aren't enough cards for the player to join, he can't join
  240.             SendCommand "/msg " & Channel & " " & Nickname & ": There are not enough cards left in the deck for you to join",ServerNumber
  241.             Player.remove Nickname
  242.         End If
  243.     Else
  244.    
  245.     End If
  246.  
  247. End Sub
  248.  
  249. 'this sub removes a player from the game
  250. Sub RemoveUNOPlayer(Nickname,Channel,ServerNumber)
  251.     CardsInDeck = CardsInDeck & "," & Players.item(Nickname) 'put the players cards to the bottom of the deck
  252.     Players.remove(Nickname)
  253.     AllPlayers = Split(PlayerList,",") 'remove the player from the playerlist
  254.     NewPlayerList = ""
  255.     NicknameInTurn = False
  256.     For i = 0 to UBound(AllPlayers)
  257.         If Not AllPlayers(i) = Nickname then
  258.             If NewPlayerList = "" then
  259.                 NewPlayerList = AllPlayers(i)
  260.             Else
  261.                 NewPlayerList = NewPlayerList & "," & AllPlayers(i)
  262.             End If
  263.         Else
  264.             If GetCurrentPlayer(Turn) = AllPlayers(i) then 'if the player was in turn when leaving the game, pass the turn to the next player
  265.                 NicknameInTurn = True
  266.             End If
  267.         End If
  268.     Next
  269.     SendCommand "/msg " & Channel & " Removed " & Nickname & " from the game",ServerNumber
  270.     PlayerList = NewPlayerList
  271.     If HasStarted = True then
  272.         If UBound(Split(PlayerList,",")) = 0 then 'if there is only one player left in the game at any time, the game ends
  273.  
  274.         SendCommand "/msg " & Channel & " Not enough player to continue game. Game terminated",ServerNumber
  275.         Gameover Nickname,Channel,False,ServerNumber
  276.         End If
  277.        
  278.         If NicknameInTurn = True then
  279.             SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn)
  280.             SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- You cards are: " & AddColors(Players.item(GetCurrentPlayer(Turn))),ServerNumber
  281.         End If
  282.     End If
  283. End Sub
  284.  
  285.  
  286. 'this function handles drawing cards from the deck
  287. Function GetNewCards(NumberOfCards)
  288.     if Not UBound(Split(CardsInDeck,",")) + UBound(Split(CardsOnTable,",")) +1 > NumberOfCards then 'if there aren't enough cards, we do nothing
  289.         If NumberOfCards = 7 or NumberOfCards = 1 then
  290.             GetNewCards = ""
  291.             Exit Function
  292.         Else
  293.             NumberOfCards = UBound(Split(CardsInDeck,",")) + UBound(Split(CardsOnTable,","))
  294.         End If
  295.     End If
  296.    
  297.  
  298.     NewCards = ""
  299.     For i = 0 to NumberOfCards-1
  300.         If InStr(CardsInDeck,",") > 0 then
  301.             Card = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  302.             CardsInDeck = Mid(CardsInDeck,InStr(CardsInDeck,",")+1)
  303.         Else 'if we take the last card from the deck, we take the already played cards and shuffle them and make them the new deck
  304.             Card = CardsInDeck
  305.            
  306.             If InStr(Mid(CardsOnTable,InStr(CardsOnTable,",")+1),",") > 0 then
  307.                 ArrayShuffle Split(Mid(CardsOnTable,InStr(CardsOnTable,",")+1),","), True
  308.                 CardsInDeck = NewString
  309.             Else
  310.                 CardsInDeck = Mid(CardsOnTable,InStr(CardsOnTable,",")+1)
  311.             End If
  312.             CardsOnTable = Left(CardsOnTable,InStr(CardsOnTable,",")-1)
  313.         End If
  314.        
  315.         If NewCards = "" then
  316.             NewCards = Card
  317.         Else
  318.             NewCards = NewCards & "," & Card
  319.         End If
  320.        
  321.     Next
  322.     GetNewCards = NewCards
  323.  
  324. End Function
  325.  
  326.  
  327.  
  328. 'this function adds color to the cards in your hand
  329. Function AddColors(CardSequence)
  330. ColoredCards = ""
  331.     CardArr = Split(CardSequence,",")
  332.     For i = 0 to UBound(CardArr)   
  333.         if Left(CardArr(i),1) = "b" then
  334.             CardArr(i) = "1,12" & " " & Mid(CardArr(i),3) & " "
  335.         Elseif Left(CardArr(i),1) = "g" then
  336.             CardArr(i) = "1,9" & " " & Mid(CardArr(i),3) & " "      
  337.         Elseif Left(CardArr(i),1) = "y" then
  338.             CardArr(i) = "1,8" & " " & Mid(CardArr(i),3) & " "      
  339.         Elseif Left(CardArr(i),1) = "r" then
  340.             CardArr(i) = "1,4" & " " & Mid(CardArr(i),3) & " "      
  341.         Elseif Left(CardArr(i),1) = "p" then
  342.             CardArr(i) = "1,13" & " " & Mid(CardArr(i),3) & " "     
  343.         ElseIf CardArr(i) = "wild" then
  344.             CardArr(i) = "1,12 w1,9i1,8l1,4d "
  345.         ElseIf CardArr(i) = "wd4" then
  346.             CardArr(i) = "1,12 1,9w1,8d41,4 "
  347.         End If
  348.        
  349.         If ColoredCards = "" then
  350.             ColoredCards = CardArr(i)
  351.         Else
  352.             ColoredCards = ColoredCards & " " & CardArr(i)     
  353.         End If
  354.     Next
  355.     AddColors = ColoredCards
  356. End Function
  357.  
  358. 'this sub shuffles an array
  359. Sub ArrayShuffle(arr,MakeString)
  360.     Randomize
  361.     Dim index
  362.     Dim newIndex
  363.     Dim firstIndex
  364.     Dim itemCount
  365.     Dim tmpValue
  366.     firstIndex = LBound(arr)
  367.     itemCount = UBound(arr) - LBound(arr) + 1
  368.     For index = UBound(arr) To LBound(arr) + 1 Step -1
  369.         ' evaluate a random index from LBound to INDEX
  370.         newIndex = firstIndex + Int(Rnd * itemCount)
  371.         ' swap the two items
  372.         tmpValue = arr(index)
  373.         arr(index) = arr(newIndex)
  374.         arr(newIndex) = tmpValue
  375.         ' prepare for next iteration
  376.         itemCount = itemCount - 1
  377.     Next
  378.     If MakeString = True then
  379.         NewString = ""
  380.         For i = 0 to UBound(arr)
  381.             If NewString = "" then
  382.                 NewString = arr(i)
  383.             Else
  384.                 NewString = NewString & "," & arr(i)
  385.             End If
  386.         Next
  387.     End If
  388. End Sub
  389.  
  390. 'this function converts the card code into the real name of the card
  391. Function GetLongCardName(Card)
  392.     if Left(Card,1) = "b" then
  393.         Color = "1,12 BLUE "
  394.     Elseif Left(Card,1) = "g" then
  395.         Color = "1,9 GREEN "
  396.     Elseif Left(Card,1) = "y" then
  397.         Color = "1,8 YELLOW "
  398.     Elseif Left(Card,1) = "r" then
  399.         Color = "1,4 RED "
  400.     Elseif Left(Card,1) = "p" then
  401.         Color = "1,13 PINK "
  402.     End If
  403.    
  404.     If IsNumeric(Mid(Card,3)) then
  405.         GetLongCardName = Color & "NUMBER " & Mid(Card,3) & " "
  406.     ElseIf Mid(Card,3) = "dr2" then
  407.         GetLongCardName = Color & "DRAW TWO "
  408.     ElseIf Mid(Card,3) = "r" then
  409.         GetLongCardName = Color & "REVERSE "
  410.     ElseIf Mid(Card,3) = "s" then
  411.         GetLongCardName = Color & "SKIP "
  412.     End If
  413.    
  414.    
  415.     If Card = "wild" then
  416.         GetLongCardName = "1,12 w1,9i1,8l1,4d "
  417.     ElseIf Card = "wd4" then
  418.         GetLongCardName = "1,12 WILD1,9 DRA1,8W FO1,4UR "
  419.     End If
  420.     GetLongCardName = GetLongCardName & ""
  421.    
  422. End Function
  423.  
  424. 'this function checks if the player has the card he is trying to play
  425. Function CheckHasCard(Nickname,Card)
  426.     CheckHasCard = False
  427.     NicknameCards = Players.item(Nickname)
  428.     If InStr(NicknameCards,",") > 0 then
  429.         CardArr = Split(NicknameCards,",")
  430.         For i = 0 to UBound(CardArr)
  431.             If CardArr(i) = Card then
  432.                 CheckHasCard = True
  433.                 Exit For
  434.             End If
  435.         Next
  436.     Else
  437.         If NicknameCards = Card then CheckHasCard = True
  438.     End If
  439. End Function
  440.  
  441. 'this function checks if the card the player is trying to play, can be played
  442. Function CanBePut(ColorOnTable,TypeOnTable,ColorOfCard,TypeOfCard)
  443.     CanBePut = False
  444.     If ColorOfCard = "w" then
  445.         CanBePut = True
  446.         Exit Function
  447.     Elseif ColorOnTable = ColorOfCard then
  448.         CanBePut = True
  449.         Exit Function
  450.     Elseif TypeOnTable = TypeOfCard then
  451.         CanBePut = True
  452.         Exit Function
  453.     End If
  454. End Function
  455.  
  456. 'this function returns the current player
  457. Function GetCurrentPlayer(AssignedTurn)
  458. TotalPlayers = Split(PlayerList,",")
  459. If AssignedTurn = UBound(TotalPlayers) + 1 then AssignedTurn = 0
  460. If AssignedTurn = UBound(TotalPlayers) + 2 then AssignedTurn = 1
  461.  
  462. GetCurrentPlayer = TotalPlayers(AssignedTurn)
  463. End Function
  464.  
  465. 'this function removes a card from a player, and returns the number of cards the player has left
  466. Function RemoveCard(Nickname,Card)
  467.     NicknameCards = Players.Item(Nickname)
  468.     If InStr(NicknameCards,",") > 0 then
  469.         CardArr = Split(NicknameCards,",")
  470.         Found = False
  471.         NicknameCards = ""
  472.         For i = 0 to UBound(CardArr)
  473.             If Found = False then
  474.                 If Not CardArr(i) = Card then
  475.                     If NicknameCards = "" then
  476.                         NicknameCards = CardArr(i)
  477.                     Else
  478.                         NicknameCards = NicknameCards & "," & CardArr(i)
  479.                     End If
  480.                 Else
  481.                 Found = True
  482.                 End If
  483.             Else
  484.                 If NicknameCards = "" then
  485.                     NicknameCards = CardArr(i)
  486.                 Else
  487.                     NicknameCards = NicknameCards & "," & CardArr(i)
  488.                 End If
  489.             End If
  490.         Next
  491.         Players.item(Nickname) = NicknameCards
  492.         If InStr(NicknameCards,",") > 0 then
  493.             RemoveCard = UBound(Split(NicknameCards,","))+1
  494.         Else
  495.             RemoveCard = 1
  496.         End If
  497.     Else
  498.         RemoveCard = 0
  499.         Players.item(Nickname) = ""
  500.         Exit Function
  501.     End If
  502. End Function
  503.  
  504. 'this sub ends the game
  505. Sub GameOver(Winner,Channel,Win,ServerNumber)
  506.     If Win = True then
  507.         SendCommand "/msg " & Channel & " " & Winner & " has won the game",ServerNumber
  508.     End If
  509.     UnoChannel = ""
  510.     GameStarter = ""
  511.     PlayerList = ""
  512.     HasStarted = False
  513.     Players.RemoveAll
  514. End Sub
  515.  
  516. 'this sub is where the actual magic happens
  517. Sub PlayUNO(Nickname,Channel,ServerNumber,Card)
  518.  
  519.     If Card = "newgame" then
  520.  
  521.         If UBound(Split(PlayerList,",")) < 1 then 'if only one player has joined before the game starts, the game is terminated
  522.             SendCommand "/msg " & Channel & " Not enough players to start a game. Game terminated",ServerNumber
  523.             GameOver Nickname,Channel,False,ServerNumber
  524.             Exit Sub
  525.         End If
  526.         HasStarted = True
  527.         CardOnTop = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  528.         CanStart = False
  529.         CardsInDeck = Mid(CardsInDeck,InStr(CardsInDeck,",")+1)
  530.         Do While CanStart = False
  531.             If CardOnTop = "wd4" then 'the game can not start with a wild draw 4 card
  532.                 CardsInDeck = CardsInDeck & "," & CardOnTop
  533.                 CardOnTop = Left(CardsInDeck,InStr(CardsInDeck,",")-1)
  534.             Else
  535.                 CanStart = True
  536.             End If
  537.         Loop
  538.        
  539.  
  540.         If CardOnTop = "wild" then 'if the first card is a wild card, the starting color is random
  541.             TopColor = Int(rnd * 5) + 1
  542.             If TopColor = 1 then
  543.                 NewColor = "r"
  544.                 NewColor2 = "1,4 RED "
  545.             ElseIf TopColor = 2 then
  546.                 NewColor = "g"
  547.                 NewColor2 = "1,9 GREEN "        
  548.             ElseIf TopColor = 3 then
  549.                 NewColor = "b"
  550.                 NewColor2 = "1,16 BLUE "
  551.             ElseIf TopColor = 4 then
  552.                 NewColor = "y"
  553.                 NewColor2 = "1,8 YELLOW "   
  554.             ElseIf TopColor = 5 then
  555.                 NewColor = "p"
  556.                 NewColor2 = "1,13 PINK "
  557.             End If
  558.        
  559.             SendCommand "/msg " & Channel & " The play order is: " & PlayerList,ServerNumber
  560.             SendCommand "/msg " & Channel & " Game started, the first card is: " & GetLongCardName(CardOnTop) & " and the color is: " & NewColor2,ServerNumber
  561.             SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  562.             CardsOnTable = NewColor & ":" & CardOnTop
  563.                
  564.         Else
  565.             TypeOfCard = Mid(CardOnTop,3)
  566.             SendCommand "/msg " & Channel & " The playing order is: " & PlayerList,ServerNumber
  567.             SendCommand "/msg " & Channel & " Game started, the first card is: " & GetLongCardName(CardOnTop),ServerNumber
  568.             If TypeOfCard = "s" then 'the first card is a skip card
  569.                 SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn) & " is skipped, next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  570.                 Turn = Turn + 1
  571.             ElseIf TypeOfCard = "r" then 'the first card is reverse
  572.                 TotalPlayers = Split(PlayerList,",")
  573.                 PlayerList = ""
  574.                 for i = UBound(TotalPlayers) to 0 Step -1
  575.                     If PlayerList = "" then
  576.                         PlayerList = TotalPlayers(i)
  577.                     Else
  578.                         PlayerList = PlayerList & "," & TotalPlayers(i)
  579.                     End If
  580.                 Next
  581.                 SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  582.                
  583.             ElseIf TypeOfCard = "dr2" then 'the first card is draw 2
  584.                 SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn) & " Draws 2 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  585.                 DrawnCards = GetNewCards(2)
  586.                 Players.item(GetCurrentPlayer(Turn)) = Players.item(GetCurrentPlayer(Turn)) & "," & DrawnCards
  587.                 SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  588.                 Turn = Turn + 1
  589.            
  590.             Else
  591.                 SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  592.             End If
  593.             CardsOnTable = CardOnTop
  594.         End If
  595.     Else
  596.         If Left(Card,1) = "w" and InStr(Card," ") = 0 then
  597.             SendCommand "/msg " & Channel & " " & Nickname & ": Please assign a color when playing this card (!play card p/r/g/b/y)",ServerNumber
  598.             Exit Sub
  599.         ElseIf Left(Card,1) = "w" and InStr(Card," ") > 0 and Len(Card) > InStr(Card," ") then
  600.             Card = Replace(Card,":","")
  601.             NewColor = Mid(Card,InStr(Card," ")+1)
  602.             If Not (NewColor = "p" or NewColor = "r" or NewColor = "g" or NewColor = "b" or NewColor = "y") then
  603.                 SendCommand "/msg " & Channel & " Invalid color: " & NewColor,ServerNumber
  604.                 Exit Sub
  605.             Else
  606.                 Card = Left(Card,InStr(Card," ")-1)
  607.                 if NewColor = "b" then
  608.                     NewColor2 = "1,12 BLUE "
  609.                 Elseif NewColor = "g" then
  610.                     NewColor2 = "1,9 GREEN "
  611.                 Elseif NewColor = "y" then
  612.                     NewColor2 = "1,8 YELLOW "
  613.                 Elseif NewColor = "r" then
  614.                     NewColor2 = "1,4 RED "
  615.                 Elseif NewColor = "p" then
  616.                     NewColor2 = "1,13 PINK "
  617.                 End If
  618.                
  619.             End If
  620.         End If
  621.        
  622.         If CheckHasCard(Nickname,Card) = True then
  623.            
  624.             ColorOnTable = Left(CardsOnTable,1)
  625.             If InStr(CardsOnTable,",") > 0 then
  626.                 TypeOnTable = Mid(CardsOnTable,InStr(CardsOnTable,":")+1,InStr(CardsOnTable,",")-InStr(CardsOnTable,":")-1)
  627.             Else
  628.                 TypeOnTable = Mid(CardsOnTable,3)
  629.             End If
  630.             ColorOfCard = Left(Card,1)
  631.             TypeOfCard = Mid(Card,3)
  632.             If CanBePut(ColorOnTable,TypeOnTable,ColorOfCard,TypeOfCard) = True then
  633.                 If Mid(CardsOnTable,3,4) = "wild" or Mid(CardsOnTable,3,3) = "wd4" then CardsOnTable = Mid(CardsOnTable,3)
  634.                 CardsLeft = RemoveCard(Nickname,Card)
  635.                 HasDrawn = False
  636.  
  637.                
  638.                 CardsOnTable = Card & "," & CardsOnTable
  639.  
  640.  
  641.                 If TypeOfCard = "s" then 'player played a skip card
  642.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  643.  
  644.                     If CardsLeft = 0 then
  645.                         GameOver Nickname,Channel,True,ServerNumber
  646.                         Exit Sub
  647.                     ElseIf CardsLeft = 1 then
  648.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  649.                     End If
  650.                     SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  651.                     Turn = Turn + 2
  652.  
  653.  
  654.                 ElseIf TypeOfCard = "dr2" then 'player played a draw 2 card
  655.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  656.                     If CardsLeft = 0 then
  657.                         GameOver Nickname,Channel,True,ServerNumber
  658.                         Exit Sub
  659.                     ElseIf CardsLeft = 1 then
  660.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  661.                     End If
  662.                     SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " Draws 2 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  663.                     DrawnCards = GetNewCards(2)
  664.                     If Not DrawnCards = "" then
  665.                         Players.item(GetCurrentPlayer(Turn+1)) = Players.item(GetCurrentPlayer(Turn+1)) & "," & DrawnCards
  666.                         SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  667.                     Else
  668.                         SendCommand "/msg " & Channel & " Not enough cards in the deck",ServerNumber
  669.                     End If
  670.  
  671.                     Turn = Turn + 2
  672.  
  673.                    
  674.  
  675.                 ElseIf TypeOfCard = "r" then 'player played a reverse card
  676.                     If UBound(Split(PlayerList,",")) > 1 then
  677.                         TotalPlayers = Split(PlayerList,",")
  678.                         PlayerList = ""
  679.                         for i = UBound(TotalPlayers) to 0 Step -1
  680.                             If PlayerList = "" then
  681.                                 PlayerList = TotalPlayers(i)
  682.                             Else
  683.                                 PlayerList = PlayerList & "," & TotalPlayers(i)
  684.                             End If
  685.                         Next
  686.                         Turn = UBound(TotalPlayers)-Turn + 1
  687.                     Else
  688.                         Turn = Turn + 2
  689.                     End If
  690.  
  691.                        
  692.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  693.                     If CardsLeft = 0 then
  694.                         GameOver Nickname,Channel,True,ServerNumber
  695.                         Exit Sub
  696.                     ElseIf CardsLeft = 1 then
  697.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  698.                     End If
  699.                     SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn),ServerNumber
  700.  
  701.  
  702.                 ElseIf ColorOfCard = "w" then
  703.                     CardsOnTable = NewColor & ":" & CardsOnTable
  704.                     If Card = "wild" then 'player played a wild card
  705.                         SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card) & " New color: " & NewColor2,ServerNumber
  706.                         If CardsLeft = 0 then
  707.                             GameOver Nickname,Channel,True,ServerNumber
  708.                             Exit Sub
  709.                         ElseIf CardsLeft = 1 then
  710.                             SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  711.                         End If
  712.                         SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  713.                         Turn = Turn + 1
  714.                        
  715.                     ElseIf Card = "wd4" then 'player played a wild draw 4 card
  716.                         SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card) & " New color: " & NewColor2,ServerNumber
  717.                         If CardsLeft = 0 then
  718.                             GameOver Nickname,Channel,True,ServerNumber
  719.                             Exit Sub
  720.                         ElseIf CardsLeft = 1 then
  721.                             SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  722.                         End If
  723.                         SendCommand "/msg " & Channel & " " & GetCurrentPlayer(Turn+1) & " Draws 4 cards and is skipped. Next in turn: " & GetCurrentPlayer(Turn+2),ServerNumber
  724.                         DrawnCards = GetNewCards(4)
  725.                         If Not DrawnCards = "" then
  726.                             Players.item(GetCurrentPlayer(Turn+1)) = Players.item(GetCurrentPlayer(Turn+1)) & "," & DrawnCards
  727.                             SendCommand "/notice " & GetCurrentPlayer(Turn+1) & " --- You drew: " & AddColors(DrawnCards),ServerNumber
  728.                         Else
  729.                             SendCommand "/msg " & Channel & " Not enough cards in the deck",ServerNumber
  730.                         End If
  731.                         Turn = Turn + 2
  732.  
  733.                     End If
  734.  
  735.  
  736.                 Else
  737.                     SendCommand "/msg " & Channel & " " & Nickname & " played: " & GetLongCardName(Card),ServerNumber
  738.                     If CardsLeft = 0 then
  739.                         GameOver Nickname,Channel,True,ServerNumber
  740.                         Exit Sub
  741.                     ElseIf CardsLeft = 1 then
  742.                         SendCommand "/msg " & Channel & " " & Nickname & " has UNO",ServerNumber
  743.                     End If
  744.                     SendCommand "/msg " & Channel & " Next in turn: " & GetCurrentPlayer(Turn+1),ServerNumber
  745.                     Turn = Turn + 1
  746.                 End If
  747.                 SendCommand "/notice " & GetCurrentPlayer(Turn) & " --- Your cards are: " & AddColors(Players.item(GetCurrentPlayer(Turn))),ServerNumber
  748.             Else
  749.                 SendCommand "/msg " & Channel & " " & Nickname & ": You can not play that card",ServerNumber
  750.             End If
  751.         Else
  752.             SendCommand "/msg " & Channel & " " & Nickname & ": You do not have that card",ServerNumber
  753.         End If
  754.     End If
  755. End Sub
Add Comment
Please, Sign In to add comment