Last Man Standing

Started by DizzasTeR, Nov 01, 2015, 04:03 AM

Previous topic - Next topic

DizzasTeR

Hello folks, since I'm tired of this plus the LMS script which is being used by people is not efficient and coded in a complicated way. So I just took a few moments out and decided to code a better LMS snippet which the newbies can use. I've tested it quite well and it seems alright to me.

Now for the stuff you have to manage and learn:

- Add this global table in your main script which includes all the basic functions which are compulsory for the working of this snippet.
_LMS <- {
Alive = 0,
Players = [],
iData = array( GetMaxPlayers() ),
State = "OFF"

function AnnounceLMS()
{
State = "ON";
Message( "[#FFFFFF]* LMS has been activated! /joinlms to join!" );
}

function JoinLMS( player )
{
Players.push( player.ID );
Alive++;
player.IsFrozen = true;
iData[ player.ID ] = player.Pos;
player.Pos = Vector( -195.861, 507.561, 16.4494 );
MessagePlayer( "[#FFFFFF]* You have joined LMS!", player );
Message( "[#FFFFFF]* " + player.Name + " has joined LMS!" );
}

function StartLMS()
{
local iPlayer;

foreach( ID in Players ) {
iPlayer = FindPlayer( ID );
if( iPlayer ) iPlayer.IsFrozen = false;
}

if( Alive >= 2 )
{
State = "STARTED";
Message( "[#FFFFFF]* LMS has started!" );
}
else
{
State = "OFF";
Players.clear();
Alive = 0;
iPlayer.Pos = iData[ iPlayer.ID ];
Message( "[#FFFFFF]* LMS was aborted due to lack of participants!" );
}
}

function PartLMS( player, eliminated = false )
{
Alive--;
Players.remove( player.ID );

if( eliminated ) Message( "[#FFFFFF]* " + player.Name + " has been eliminated from LMS!" );
else Message( "[#FFFFFF]* " + player.Name + " has left LMS!" );

if( Alive <= 1 )
{
foreach( ID in Players ) {
local iPlayer = FindPlayer( ID );
if( iPlayer ) _LMS.Winner( iPlayer );
}
}
}

function Winner( player )
{
State = "OFF";
Alive = 0;
Players.clear();
player.Pos = iData[ player.ID ];
Message( "[#FFFFFF]* " + player.Name + " has won the LMS!" );
}
}

Add this in the first place of your onPlayerPart:
function onPlayerPart( player, reason )
{
if( _LMS.Players.find( player.ID ) != null )
{
_LMS.PartLMS( player );
}
}

Add this in the first place of your onPlayerDeath:
function onPlayerDeath( player, reason )
{
if( _LMS.Players.find( player.ID ) != null )
{
_LMS.PartLMS( player, true );
}
}

Add this in onPlayerKill:
function onPlayerKill( killer, player, reason, bodypart )
{
if( _LMS.Players.find( killer.ID ) != null && _LMS.Players.find( player.ID ) != null )
{
_LMS.PartLMS( player, true );
}
}

Keep these commands in your onPlayerCommand:
function onPlayerCommand( player, cmd, arg )
{
if( _LMS.Players.find( player.ID ) != null ) return MessagePlayer( "[#FFFFFF]* Commands are disabled in LMS!", player );

if( cmd == "lms" )
{
if( !player.IsSpawned ) return;
else if ( _LMS.State == "ON" || _LMS.State == "STARTED" ) return MessagePlayer( "[#FFFFFF]* LMS is already running!", player );
else
{
_LMS.State = "ON";
_LMS.JoinLMS( player );
NewTimer( "LMSEntriesEnd", 30000, 1 );
Message( "[#FFFFFF]* LMS has been activated by " + player.Name + "! /joinlms to join!" );
}
}

else if( cmd == "joinlms" )
{
if( !player.IsSpawned ) return;
else if( _LMS.State == "STARTED" ) return MessagePlayer( "[#FFFFFF]* LMS is already running!", player );
else if( _LMS.State == "OFF" ) return MessagePlayer( "[#FFFFFF]* LMS is not running!", player );
else if( _LMS.Players.find( player.ID ) != null ) return MessagePlayer( "[#FFFFFF]* You are already in LMS!", player );
else
{
_LMS.JoinLMS( player );
}
}

else if( cmd == "s" ) { print( player.Pos ); }
}

You can modify them to your needs, and finally this small function anywhere you would like to:
function LMSEntriesEnd() { _LMS.StartLMS(); }
Have fun, test it and tell me if you find any issues.

~ Regards,
~ Doom_Kill3R!

KAKAN

oh no

Cool


.

You people do know that there's a Like button bellow each post. And you know why that button is there? To prevent all those junk posts with "Thanks" in them.

.

.

#4
Quote from: Noob on Nov 01, 2015, 06:42 AMahhh Error expected = or ; 
line = _LMS <- {

@Doom_Killer Don't say I never warned you ;D
.

DizzasTeR

Perhaps I should have thought on your advice. These people can never learn.

KAKAN

Quote from: Noob on Nov 01, 2015, 06:42 AMahhh Error expected = or ; 
line = _LMS <- {
Quote from: Doom_Kill3R- Add this global table in your main script which includes all the basic functions which are compulsory for the working of this snippet.
oh no

Cool


Xmair

Nice one, looks easy to make.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Diamond


Karthik

_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"

Karthik

_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"
where to add this?

.

« Reply #9, 56 days ago »

Quote from: NE DiamondBlue on Nov 01, 2015, 08:31 AMGood Work!.

« Reply #10, 2 minutes ago »

Quote from: Karthik on Dec 27, 2015, 03:11 AM_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"

Do you see anything strange?
.

Karthik

i am saying where to add for ex scriptload in which?

DizzasTeR

Quote from: Karthik on Dec 27, 2015, 04:56 AMi am saying where to add for ex scriptload in which?

Add it at the top of your script, above onScriptLoad, you can also add it in onScriptLoad but that'll look messed up.