Spree System

Started by Retard, Feb 03, 2018, 02:21 AM

Previous topic - Next topic

Retard

Everything is explained in the code.
SpreeSlot <- array( 100, null ); // Creates a static 100 size array with all values at null.

class KillingSpree {

  constructor(Player, Kills) {

PlayerName  = Player;
num_kills   = Kills;
}

function find_plr(player)
{
return SpreeSlot[ player.ID ] != null ? true : false;
}

function AnnounceSpree(text)
{
  ::Message( " **** " + text );
}

function list_players()
{
local tmp = "";
foreach ( obj in SpreeSlot )
{
if ( ( obj != null ) && ( obj.num_kills >= 5 ) )
{
tmp = tmp + obj.PlayerName + " " + obj.num_kills + ", ";
}
}

return tmp != "" ? tmp.slice(0, tmp.len() - 2) : "No Players are on a Killspree";
}

function IsSpree(killer, player, reason)
{

if ( KillingSpree.find_plr(player) )  // Spree Ended
{
// Calculate kills for the victim
local kills = SpreeSlot[ player.ID ].num_kills;

// Filter killed/died reasons
reason = reason < 39 ? "KILLED" : reason;

// Prevent spree ending for Drive-By/Vehicle killings.
if ( ( reason != 39 ) && ( reason != 42 ) )
{
// Empty the SpreeSlot.
SpreeSlot[ player.ID ] = null;

if ( kills >= 5 )
{
// Establish end type
switch ( reason )
{
case "KILLED":
AnnounceSpree( killer + " ended " + player + "'s Killing Spree of " + kills + " kills in a row." );
        break;

    case 43: AnnounceSpree( player + "'s Killing Spree was ended by drowning themselves" );
        break;

    default: AnnounceSpree( player + "'s Killing Spree was ended" );
}
}
}
}

if ( ( KillingSpree.find_plr(killer) ) || ( SpreeSlot[ killer.ID ] == null ) )
{
// Calculate kills for the killer
local kills = KillingSpree.find_plr(killer) ? SpreeSlot[ killer.ID ].num_kills + 1 : 1;

// Allocate a killing spree slot for the killer.
SpreeSlot[ killer.ID ] = KillingSpree( killer, kills );

// Establish the killspree mode.
  if ( kills == 5 ) AnnounceSpree( killer + " is on a Killing Spree with " + kills + " kills in a row!" );
  else if ( kills == 10 ) AnnounceSpree( killer + " is Dangerous!  Killing Spree with " + kills + " kills in a row!" );
  else if ( kills == 15 ) AnnounceSpree( killer + " is Murderous!!  Deadly Killing Spree with " + kills + " kills in a row!" );
  else if ( kills == 20 ) AnnounceSpree( killer + " is Psychotic!!!  Insane Killing Spree with " + kills + " kills in a row!" );
  else if ( kills == 25 ) AnnounceSpree( killer + " is an Assassin!!!!  Professional Killing Spree with " + kills + " kills in a row!" );
else if ( ( kills >= 30 ) && ( kills % 5 == 0 ) ) AnnounceSpree( killer + " is UNSTOPPABLE!!!!  Untouchable Killing Spree with " + kills + " kills in a row!" );
}
}


PlayerName = null;
num_kills  = null;
}

function onPlayerKill( killer, player, reason, bodypart )
{
  KillingSpree.IsSpree( killer, player, reason );
}

function onPlayerDeath( player, reason )
{
KillingSpree.IsSpree( null, player, reason );
}

function onPlayerPart( player, reason )
{
// Reset the spree array slot
SpreeSlot[ player.ID ] = null;
}

function onPlayerCommand( player, cmd, text )
{
if ( cmd == "spree" ) Message( " **** " + KillingSpree.list_players() );
}
Just another retard roaming around.

Mohamed Boubekri

| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Alecu Madalin

that script works

but it gaved me a lot of errors if i suicide or do a spree

NicusorN5

There is a improvised version:
Spree <- array(100,0);

function onPlayerJoin(player) { Spree[player.ID] = 0; }
function onPlayerDeath(player,reason) { Spree[player.ID] = 0; }
function onPlayerKill( . . . ) { Spree[player.ID] += 1; }


When acessing the spree use Spree[player.ID]. Pretty simple...

The difference is being less memory used because a class is not used.

Alecu Madalin

Quote from: Athanatos on Oct 04, 2019, 10:33 AMThere is a improvised version:
Spree <- array(100,0);

function onPlayerJoin(player) { Spree[player.ID] = 0; }
function onPlayerDeath(player,reason) { Spree[player.ID] = 0; }
function onPlayerKill( . . . ) { Spree[player.ID] += 1; }


When acessing the spree use Spree[player.ID]. Pretty simple...

The difference is being less memory used because a class is not used.

nice and easy