Its a pretty basic system. but you can improve it later on.
Feel Free to modify and improve it.
Code Select
function onServerStart()
{
local DuelAr = false;
}
function onScriptLoad()
{
DuelStats <- array( GetMaxPlayers(), null );
DuelAr <- array( GetMaxPlayers(), null );
DuelAr = false;
}
class DuelClass
{
Duel = false;
Dueling = -1;
DRequest = -1;
DKills = 0;
DK = 0;
}
function onPlayerJoin( player )
{
DuelStats[ player.ID ] = DuelClass();
}
function GetTok(string, separator, n, ...)
{
local m = vargv.len() > 0 ? vargv[0] : n,
tokenized = split(string, separator),
text = "";
if (n > tokenized.len() || n < 1) return null;
for (; n <= m; n++)
{
text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
}
return text;
}
function Unf2( playerID )
{
local player = FindPlayer(playerID);
player.Pos = Vector(-264.459, -815.077, 1211.09);
player.Angle = 0.0553603;
player.Frozen = false;
MessagePlayer("Duel Started",player);
}
function Unf( playerID )
{
local player = FindPlayer(playerID);
player.Pos = Vector(-264.537, -787.858, 1211.15);
player.Angle = -3.14039;
player.Frozen = false;
MessagePlayer("Duel Started",player);
}
function onPlayerCommand( player, cmd, text ){
if ( cmd == "duel" )
{
if( !text ) MessagePlayer( "/Duel <Name/ID>", player );
else if ( DuelStats[ player.ID ].Duel ) MessagePlayer("[ERROR]You are already in a duel.", player );
else if ( DuelAr == true ) MessagePlayer("Duel Arena is full.",player);
else
{
local plr = FindPlayer( GetTok( text, " ", 1 ) );
if ( !plr ) MessagePlayer( "Invalid Player.", player );
else if ( player.ID == plr.ID ) MessagePlayer( "You can't duel yourself.", player );
else if ( DuelStats[ plr.ID ].Duel ) MessagePlayer( "That player is already dueling.", player );
else if ( DuelStats[ plr.ID ].DRequest != -1 ) MessagePlayer( "That player has already a duel request.", player );
else
{
DuelStats[ plr.ID ].DRequest = player.ID;
MessagePlayer( "You sent a duel request to " + plr.Name + ".", player );
MessagePlayer( player.Name + " sent you a duel request,you can /acduel or /deduel ", plr );
}
}
}
else if ( cmd == "acceptduel" || cmd == "acduel" )
{
if ( DuelStats[ player.ID ].DRequest == -1 ) MessagePlayer( "[ERROR]You dont have a pending duel.", player );
else
{
local plr = FindPlayer( DuelStats[ player.ID ].DRequest.tointeger() );
DuelStats[ plr.ID ].DRequest = -1;
DuelStats[ plr.ID ].Duel = true;
DuelStats[ plr.ID ].Dueling = player.ID;
DuelStats[ player.ID ].DRequest = -1;
DuelStats[ player.ID ].Duel = true;
DuelStats[ player.ID ].Dueling = plr.ID;
plr.Eject();
plr.Pos = Vector(-264.537, -787.858, 1211.15);
plr.Angle = -3.14039;
plr.Frozen = true;
Announce( "Duel will start in 10 secs.", plr, 6 );
NewTimer( "Unf", 5000, 1, plr.ID );
player.Eject();
player.Pos = Vector(-264.459, -815.077, 1211.09);
player.Angle = 0.0553603;
player.Frozen = true;
Announce( "Duel will start in 10 secs.", player, 6 );
NewTimer( "Unf2", 5000, 1, player.ID );
DuelAr = true;
Message( player.Name +" is now in duel against " + plr.Name );
}
}
else if ( cmd == "denyduel" || cmd == "deduel" )
{
if ( DuelStats[ player.ID ].DRequest == -1 ) Error_MSG( "You dont have a pending duel request.", player );
else
{
local plr = FindPlayer( DuelStats[ player.ID ].DRequest.tointeger() );
DuelStats[ player.ID ].DRequest = -1;
DuelStats[ player.ID ].Duel = false;
DuelStats[ player.ID ].Dueling = -1;
DuelStats[ plr.ID ].DRequest = -1;
DuelStats[ plr.ID ].Duel = false;
Message( player.Name +" denied " + plr.Name + "'s duel request" );
}
}
}
function onPlayerTeamKill( killer, player, reason, bodypart )
{
if ( DuelStats[ player.ID ].Duel && DuelStats[ killer.ID ].Duel && DuelStats[ player.ID ].Dueling == killer.ID && DuelStats[ killer.ID ].Dueling == player.ID && DuelStats[ killer.ID ].DKills >= 4 )
{
Message(killer.Name + " has won the duel against " + player.Name );
DuelStats[ player.ID ].DRequest = -1;
DuelStats[ player.ID ].DKills = 0;
DuelStats[ killer.ID ].DKills = 0;
DuelStats[ killer.ID ].Duel = -1;
DuelStats[ player.ID ].Duel = false;
DuelStats[ killer.ID ].Duel = false;
DuelStats[ player.ID ].Dueling = -1;
DuelStats[ killer.ID ].Dueling = -1;
DuelAr = false;
}
else if ( DuelStats[ player.ID ].Duel && DuelStats[ killer.ID ].Duel && DuelStats[ player.ID ].Dueling == killer.ID && DuelStats[ killer.ID ].Dueling == player.ID )
{
DuelStats[ killer.ID ].DKills += 1;
Announce( "~w~Duel Resulte: ~b~" + DuelStats[ killer.ID ].DKills + "~w~ - ~b~ " + DuelStats[ player.ID ].DKills, killer, 6 );
Announce( "~w~Duel Resulte: ~b~" + DuelStats[ player.ID ].DKills + "~w~ - ~b~ " + DuelStats[ killer.ID ].DKills, player, 6 );
Message( "[DUEL]> " + killer.Name + "killed " + player.Name + " with a shot in " + GetBP( bodypart ) + " with " + GetWeaponName( reason ) + ". Duel result: " + DuelStats[ killer.ID ].DKills + " - " + DuelStats[ player.ID ].DKills );
}
}
function onPlayerKill( killer, player, reason, bodypart )
{
if ( DuelStats[ player.ID ].Duel && DuelStats[ killer.ID ].Duel && DuelStats[ player.ID ].Dueling == killer.ID && DuelStats[ killer.ID ].Dueling == player.ID && DuelStats[ killer.ID ].DKills >= 4 )
{
Message(killer.Name + " has won the duel against " + player.Name );
DuelStats[ player.ID ].DRequest = -1;
DuelStats[ player.ID ].DKills = 0;
DuelStats[ killer.ID ].DKills = 0;
DuelStats[ killer.ID ].Duel = -1;
DuelStats[ player.ID ].Duel = false;
DuelStats[ killer.ID ].Duel = false;
DuelStats[ player.ID ].Dueling = -1;
DuelStats[ killer.ID ].Dueling = -1;
DuelAr = false;
}
else if ( DuelStats[ player.ID ].Duel && DuelStats[ killer.ID ].Duel && sDuelStats[ player.ID ].Dueling == killer.ID && DuelStats[ killer.ID ].Dueling == player.ID )
{
DuelStats[ killer.ID ].DKills += 1;
Announce( "~w~Duel Resulte: ~b~" + DuelStats[ killer.ID ].DKills + "~w~ - ~b~ " + DuelStats[ player.ID ].DKills, killer, 6 );
Announce( "~w~Duel Resulte: ~b~" + DuelStats[ player.ID ].DKills + "~w~ - ~b~ " + DuelStats[ killer.ID ].DKills, player, 6 );
Message( "[DUEL-INFO]> " + killer.Name + " killed " + player.Name + " with a shot in " + GetBP( bodypart ) + " with " + GetWeaponName( reason ) + ". Duel result: " + DuelStats[ killer.ID ].DKills + " - " + DuelStats[ player.ID ].DKills );
}
}
function onPlayerSpawn( player )
{
NewTimer( "DuelSpawn", 1000, 1, player.ID );
}
function DuelSpawn( playerID )
{
local player = FindPlayer( playerID );
if ( player && DuelStats[ player.ID ].Duel )
{
local plr = FindPlayer( DuelStats[ player.ID ].Dueling.tointeger() );
player.Pos = Vector(-264.537, -787.858, 1211.15);
player.Angle = -3.14039;
plr.Pos = Vector(-264.459, -815.077, 1211.09);
plr.Angle = 0.0553603;
player.Health = 100;
plr.Health = 100;
player.Armour = 0;
plr.Armour = 0;
}
}
function GetBP( part )
{
local group;
if ( part == 0 ) group = "Body";
else if ( part == 1 ) group = "Torso";
else if ( part == 2 ) group = "Left Arm";
else if ( part == 3 ) group = "Right Arm";
else if ( part == 4 ) group = "Left Leg";
else if ( part == 5 ) group = "Right Leg";
else if ( part == 6 ) group = "Head";
else if ( part == 7 ) group = "Vehicle";
else group = "Unknown";
return group;
}
Code Select
here is the map file link: https://drive.google.com/file/d/1W7ft0l7Ni8HF0vcjvRkr3oFK4S4nRqqH/view?usp=drive_link
Feel Free to modify and improve it.