Advertisement
Guest User

Duel System - VCMP - By (ARG)Maximiliano

a guest
Oct 12th, 2019
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.99 KB | None | 0 0
  1. Duels <- array( 3000, null ); //This Array will store the duels data
  2. Invitations <- array( GetMaxPlayers(), null );//This Array will store the invitatios data
  3.  
  4. class DuelClass //This data will be saved in the duels array.
  5. {
  6. Player1 = null;
  7. Player2 = null;
  8. Player1Kills = 0;
  9. Player2Kills = 0;
  10. MaxKills = 0;
  11. }
  12.  
  13. DuelSystem <- {
  14.  
  15. //Function responsible for sending requests for duels
  16. function SendInvitation(player, player2, KillsToWin)
  17. {
  18. MessagePlayer("[#81F79F]You have received a duel invitation from the player [#FF5733]"+ player.Name +"[#81F79F]. You must kill him [#FF5733]"+KillsToWin+ " [#81F79F]times to win", player2);
  19. MessagePlayer("[#81F79F]You have sent the invitation to a duel to the player [#FF5733]"+ player2.Name +"[#81F79F]. Kills to Win: [#FF5733]"+ KillsToWin +"[#81F79F].", player);
  20.  
  21. Invitations[player.ID] =
  22. {
  23. Sent = player2
  24. Kills = KillsToWin
  25. InvitedBy = player
  26. Accepted = false
  27. };
  28.  
  29. Invitations[player2.ID] =
  30. {
  31. Sent = player
  32. Kills = KillsToWin
  33. InvitedBy = player
  34. Accepted = false
  35. };
  36. }
  37.  
  38. //Function responsible for denying requests for duels
  39. function DenyInvitation(player, reason)
  40. {
  41. local plr = Invitations[player.ID].Sent;
  42.  
  43. MessagePlayer(player+ " [#81F79F]canceled the duel invitation. Reason: [#FF5733]"+reason+".", plr);
  44. if (reason != "Quit") MessagePlayer("[#81F79F]You have successfully canceled the duel", player); //
  45.  
  46. Invitations[plr.ID] = null;
  47. Invitations[player.ID] = null;
  48. }
  49.  
  50. //This function is executed when accepting duels
  51. function StartDuel(player1, player2, kills)
  52. {
  53. local World = (rand() % 3000).tointeger();
  54.  
  55. Duels[ World ] = DuelClass();
  56. Duels[World].Player1 = player1;
  57. Duels[World].Player2 = player2;
  58. Duels[World].MaxKills = kills;
  59.  
  60. player1.World = World;
  61. player1.Pos = Vector(-1759.98, -193.022, 14.8683);
  62. player1.Team = 1;
  63.  
  64. player2.World = World;
  65. player2.Team = 2;
  66. player2.Pos = Vector(-1763.34, -127.249, 14.8683);
  67.  
  68. Invitations[player2.ID].Accepted = true;
  69. Invitations[player1.ID].Accepted = true;
  70.  
  71. Message("[#FF5733]" + player1.Name + "[#81F79F] has started a duel against [#FF5733]"+ player2.Name +"[#81F79F]. Kills to win: [#FF5733]"+ kills +"[#81F79F].");
  72. }
  73.  
  74. function EndDuel(World)
  75. {
  76. local winner, loser, result;
  77.  
  78. if( Duels[World].Player1Kills < Duels[World].Player2Kills )
  79. {
  80. winner = Duels[World].Player2.Name;
  81. loser = Duels[World].Player1.Name;
  82. result = Duels[World].Player2Kills +" - "+ Duels[World].Player1Kills;
  83. }
  84. else
  85. {
  86. winner = Duels[World].Player1.Name;
  87. loser = Duels[World].Player2.Name;
  88. result = Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills;
  89. }
  90.  
  91. local player1 = Duels[World].Player1;
  92. local player2 = Duels[World].Player2;
  93.  
  94. player1.World = 0;
  95. player1.Select();
  96.  
  97. player2.World = 0;
  98. player2.Select();
  99.  
  100. Invitations[player1.ID] = null;
  101. Invitations[player2.ID] = null;
  102. Duels[World] = null;
  103.  
  104. Message("[#FF5733]" + winner + " [#81F79F]won a duel to [#FF5733]"+ loser +"[#81F79F]. Result: [#FF5733]"+ result +".");
  105. }
  106.  
  107. function AddKill(team, World)
  108. {
  109. if (team == 1)
  110. {
  111. Duels[World].Player1Kills++;
  112. DuelSystem.SayKills(World);
  113. if ( Duels[World].MaxKills <= Duels[World].Player1Kills ) DuelSystem.EndDuel(World);
  114. }
  115. else
  116. {
  117. Duels[World].Player2Kills++;
  118. DuelSystem.SayKills(World);
  119. if ( Duels[World].MaxKills <= Duels[World].Player2Kills ) DuelSystem.EndDuel(World);
  120. }
  121.  
  122. }
  123.  
  124.  
  125. function SayKills(World)
  126. {
  127. MessagePlayer( Duels[World].Player1.Name+" "+ Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills+" "+ Duels[World].Player2.Name, Duels[World].Player2 );
  128. MessagePlayer( Duels[World].Player1.Name+" "+ Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills+" "+ Duels[World].Player2.Name, Duels[World].Player1 );
  129. }
  130.  
  131. function Respawn(player)
  132. {
  133.  
  134. if ( Duels[player.World].Player1.Name == player.Name )
  135. {
  136. player.Pos = Vector(-1759.98, -193.022, 14.8683);
  137. player.Team = 1;
  138. }
  139. else
  140. {
  141. player.Pos = Vector(-1763.34, -127.249, 14.8683);
  142. player.Team = 2;
  143. }
  144. }
  145.  
  146.  
  147. // =========================== Commands ========================== //
  148.  
  149. function onPlayerCommand(player, cmd, text)
  150. {
  151. if (cmd == "newduel")
  152. {
  153. if(!text) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
  154. else if ( !GetPlayer(GetTok(text, " ", 1)) ) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
  155. else if ( GetPlayer(GetTok(text, " ", 1)).Name == player.Name ) MessagePlayer("[#81F79F]You can't invite yourself.", player);
  156. else if ( !IsNum(GetTok(text, " ", 2)) ) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
  157. else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You cannot create an invitation while in a duel.", player);
  158. else if ( Invitations[ player.ID ] ) MessagePlayer("[#81F79F]You have already created a grieving invitation.", player);
  159. else if ( Invitations[ GetPlayer(GetTok(text, " ", 1)).ID ] && Invitations[ GetPlayer(GetTok(text, " ", 1)).ID ].Accepted == true ) MessagePlayer("[#81F79F]He is participating in a duel.", player);
  160. else if ( Invitations[ GetPlayer(GetTok(text, " ", 1)).ID ] ) MessagePlayer("[#81F79F]He has already been invited to a duel", player);
  161. else
  162. {
  163.  
  164. local kills = GetTok(text, " ", 2);
  165. local plr = GetPlayer(GetTok(text, " ", 1));
  166. DuelSystem.SendInvitation(player, plr, kills);
  167. }
  168. }
  169.  
  170. else if (cmd == "duel")
  171. {
  172. if( !text ) MessagePlayer("[#81F79F]/duel accept/deny", player);
  173. else
  174. {
  175. local subcommand = GetTok(text, " ", 1);
  176. switch (subcommand.tolower())
  177. {
  178. case "accept":
  179. if ( !Invitations[ player.ID ] ) MessagePlayer("[#81F79F]Nobody has invited you to a duel.", player);
  180. else if ( Invitations[ player.ID ] && Invitations[ player.ID ].InvitedBy.Name == player.Name ) MessagePlayer("[#81F79F]You cannot accept your own duel", player);
  181. else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You can't accept while you're in a duel.", player);
  182. else DuelSystem.StartDuel(player, Invitations[ player.ID ].Sent, Invitations[ player.ID ].Kills.tointeger() );
  183. break;
  184.  
  185. case "deny":
  186. case "cancel":
  187. if ( !Invitations[ player.ID ] ) MessagePlayer("[#81F79F]Nobody has invited you to a duel.", player);
  188. else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You can't accept while you're in a duel.", player);
  189. else if ( Invitations[ player.ID ] && Invitations[ player.ID ].InvitedBy.Name == player.Name ) DuelSystem.DenyInvitation(player, "Canceled");
  190. else DuelSystem.DenyInvitation(player, "Denied.");
  191. break;
  192. default:
  193. MessagePlayer("[#81F79F]/duel accept/deny", player);
  194. }
  195. }
  196.  
  197. }
  198.  
  199. }
  200.  
  201. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement