Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Duels <- array( 3000, null ); //This Array will store the duels data
- Invitations <- array( GetMaxPlayers(), null );//This Array will store the invitatios data
- class DuelClass //This data will be saved in the duels array.
- {
- Player1 = null;
- Player2 = null;
- Player1Kills = 0;
- Player2Kills = 0;
- MaxKills = 0;
- }
- DuelSystem <- {
- //Function responsible for sending requests for duels
- function SendInvitation(player, player2, KillsToWin)
- {
- 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);
- MessagePlayer("[#81F79F]You have sent the invitation to a duel to the player [#FF5733]"+ player2.Name +"[#81F79F]. Kills to Win: [#FF5733]"+ KillsToWin +"[#81F79F].", player);
- Invitations[player.ID] =
- {
- Sent = player2
- Kills = KillsToWin
- InvitedBy = player
- Accepted = false
- };
- Invitations[player2.ID] =
- {
- Sent = player
- Kills = KillsToWin
- InvitedBy = player
- Accepted = false
- };
- }
- //Function responsible for denying requests for duels
- function DenyInvitation(player, reason)
- {
- local plr = Invitations[player.ID].Sent;
- MessagePlayer(player+ " [#81F79F]canceled the duel invitation. Reason: [#FF5733]"+reason+".", plr);
- if (reason != "Quit") MessagePlayer("[#81F79F]You have successfully canceled the duel", player); //
- Invitations[plr.ID] = null;
- Invitations[player.ID] = null;
- }
- //This function is executed when accepting duels
- function StartDuel(player1, player2, kills)
- {
- local World = (rand() % 3000).tointeger();
- Duels[ World ] = DuelClass();
- Duels[World].Player1 = player1;
- Duels[World].Player2 = player2;
- Duels[World].MaxKills = kills;
- player1.World = World;
- player1.Pos = Vector(-1759.98, -193.022, 14.8683);
- player1.Team = 1;
- player2.World = World;
- player2.Team = 2;
- player2.Pos = Vector(-1763.34, -127.249, 14.8683);
- Invitations[player2.ID].Accepted = true;
- Invitations[player1.ID].Accepted = true;
- Message("[#FF5733]" + player1.Name + "[#81F79F] has started a duel against [#FF5733]"+ player2.Name +"[#81F79F]. Kills to win: [#FF5733]"+ kills +"[#81F79F].");
- }
- function EndDuel(World)
- {
- local winner, loser, result;
- if( Duels[World].Player1Kills < Duels[World].Player2Kills )
- {
- winner = Duels[World].Player2.Name;
- loser = Duels[World].Player1.Name;
- result = Duels[World].Player2Kills +" - "+ Duels[World].Player1Kills;
- }
- else
- {
- winner = Duels[World].Player1.Name;
- loser = Duels[World].Player2.Name;
- result = Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills;
- }
- local player1 = Duels[World].Player1;
- local player2 = Duels[World].Player2;
- player1.World = 0;
- player1.Select();
- player2.World = 0;
- player2.Select();
- Invitations[player1.ID] = null;
- Invitations[player2.ID] = null;
- Duels[World] = null;
- Message("[#FF5733]" + winner + " [#81F79F]won a duel to [#FF5733]"+ loser +"[#81F79F]. Result: [#FF5733]"+ result +".");
- }
- function AddKill(team, World)
- {
- if (team == 1)
- {
- Duels[World].Player1Kills++;
- DuelSystem.SayKills(World);
- if ( Duels[World].MaxKills <= Duels[World].Player1Kills ) DuelSystem.EndDuel(World);
- }
- else
- {
- Duels[World].Player2Kills++;
- DuelSystem.SayKills(World);
- if ( Duels[World].MaxKills <= Duels[World].Player2Kills ) DuelSystem.EndDuel(World);
- }
- }
- function SayKills(World)
- {
- MessagePlayer( Duels[World].Player1.Name+" "+ Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills+" "+ Duels[World].Player2.Name, Duels[World].Player2 );
- MessagePlayer( Duels[World].Player1.Name+" "+ Duels[World].Player1Kills +" - "+ Duels[World].Player2Kills+" "+ Duels[World].Player2.Name, Duels[World].Player1 );
- }
- function Respawn(player)
- {
- if ( Duels[player.World].Player1.Name == player.Name )
- {
- player.Pos = Vector(-1759.98, -193.022, 14.8683);
- player.Team = 1;
- }
- else
- {
- player.Pos = Vector(-1763.34, -127.249, 14.8683);
- player.Team = 2;
- }
- }
- // =========================== Commands ========================== //
- function onPlayerCommand(player, cmd, text)
- {
- if (cmd == "newduel")
- {
- if(!text) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
- else if ( !GetPlayer(GetTok(text, " ", 1)) ) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
- else if ( GetPlayer(GetTok(text, " ", 1)).Name == player.Name ) MessagePlayer("[#81F79F]You can't invite yourself.", player);
- else if ( !IsNum(GetTok(text, " ", 2)) ) MessagePlayer("[#81F79F]/newduel Nick KillsToWin", player);
- else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You cannot create an invitation while in a duel.", player);
- else if ( Invitations[ player.ID ] ) MessagePlayer("[#81F79F]You have already created a grieving invitation.", player);
- 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);
- else if ( Invitations[ GetPlayer(GetTok(text, " ", 1)).ID ] ) MessagePlayer("[#81F79F]He has already been invited to a duel", player);
- else
- {
- local kills = GetTok(text, " ", 2);
- local plr = GetPlayer(GetTok(text, " ", 1));
- DuelSystem.SendInvitation(player, plr, kills);
- }
- }
- else if (cmd == "duel")
- {
- if( !text ) MessagePlayer("[#81F79F]/duel accept/deny", player);
- else
- {
- local subcommand = GetTok(text, " ", 1);
- switch (subcommand.tolower())
- {
- case "accept":
- if ( !Invitations[ player.ID ] ) MessagePlayer("[#81F79F]Nobody has invited you to a duel.", player);
- else if ( Invitations[ player.ID ] && Invitations[ player.ID ].InvitedBy.Name == player.Name ) MessagePlayer("[#81F79F]You cannot accept your own duel", player);
- else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You can't accept while you're in a duel.", player);
- else DuelSystem.StartDuel(player, Invitations[ player.ID ].Sent, Invitations[ player.ID ].Kills.tointeger() );
- break;
- case "deny":
- case "cancel":
- if ( !Invitations[ player.ID ] ) MessagePlayer("[#81F79F]Nobody has invited you to a duel.", player);
- else if ( Invitations[ player.ID ] && Invitations[ player.ID ].Accepted == true) MessagePlayer("[#81F79F]You can't accept while you're in a duel.", player);
- else if ( Invitations[ player.ID ] && Invitations[ player.ID ].InvitedBy.Name == player.Name ) DuelSystem.DenyInvitation(player, "Canceled");
- else DuelSystem.DenyInvitation(player, "Denied.");
- break;
- default:
- MessagePlayer("[#81F79F]/duel accept/deny", player);
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement