Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: DizzasTeR on Nov 01, 2015, 04:03 AM

Title: Last Man Standing
Post by: DizzasTeR on Nov 01, 2015, 04:03 AM
Hello folks, since I'm tired of this (http://forum.vc-mp.org/?topic=1771.0) 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!
Title: Re: Last Man Standing
Post by: KAKAN on Nov 01, 2015, 06:17 AM
Looks Nice!
Title: Re: Last Man Standing
Post by: Cool on Nov 01, 2015, 06:26 AM
THANKS @Doom_Killer
Title: Re: Last Man Standing
Post by: . on Nov 01, 2015, 06:30 AM
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.

(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fs4.postimg.org%2Fadnmdjgbx%2FUntitled.jpg&hash=0e63e612f6aa835bd1a3df8493dc7343658fa260)
Title: Re: Last Man Standing
Post by: . on Nov 01, 2015, 06:43 AM
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
Title: Re: Last Man Standing
Post by: DizzasTeR on Nov 01, 2015, 06:44 AM
Perhaps I should have thought on your advice. These people can never learn.
Title: Re: Last Man Standing
Post by: KAKAN on Nov 01, 2015, 06:45 AM
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.
Title: Re: Last Man Standing
Post by: Cool on Nov 01, 2015, 06:46 AM
done sorry
Title: Re: Last Man Standing
Post by: Xmair on Nov 01, 2015, 07:33 AM
Nice one, looks easy to make.
Title: Re: Last Man Standing
Post by: Diamond on Nov 01, 2015, 08:31 AM
Good Work!.
Title: Re: Last Man Standing
Post by: Karthik on Dec 27, 2015, 03:11 AM
_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"
Title: Re: Last Man Standing
Post by: Karthik on Dec 27, 2015, 03:12 AM
_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"
where to add this?
Title: Re: Last Man Standing
Post by: . on Dec 27, 2015, 03:15 AM
« 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?
Title: Re: Last Man Standing
Post by: Karthik on Dec 27, 2015, 04:56 AM
i am saying where to add for ex scriptload in which?
Title: Re: Last Man Standing
Post by: DizzasTeR on Dec 27, 2015, 05:11 AM
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.
Title: Re: Last Man Standing
Post by: Karthik on Dec 27, 2015, 05:15 AM
K dude i will try this system
if i will find error i will contact u
Title: Re: Last Man Standing
Post by: SAzEe21 on Feb 20, 2016, 08:48 AM
Sorry for bumping the old topic, but i got an error.

717 line is end of main.nut.
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi.imgur.com%2FEhD6EZB.png&hash=86723777d79972dc8f95a6832302af14f8ed4eb4)
Title: Re: Last Man Standing
Post by: DizzasTeR on Feb 20, 2016, 09:54 AM
You screwed up somewhere while copying. If you have that '_LMS' Table in onScriptLoad then remove it from there and keep it above onScriptLoad.
Title: Re: Last Man Standing
Post by: KAKAN on Feb 20, 2016, 05:36 PM
Quote from: Doom_Kill3R on Feb 20, 2016, 09:54 AMYou screwed up somewhere while copying. If you have that '_LMS' Table in onScriptLoad then remove it from there and keep it above onScriptLoad.
What about teams and other things? I know that this isn't important, but think, what if all the players are having the same team?
Title: Re: Last Man Standing
Post by: Karthik on Feb 23, 2016, 09:25 AM
It works fine for me good qork
Title: Re: Last Man Standing
Post by: dEaN on Dec 01, 2016, 07:09 AM
_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"

-Error-
Title: Re: Last Man Standing
Post by: KAKAN on Dec 01, 2016, 08:53 AM
Would you even bother to say what's the error code?
Maybe you are weak in copying code...
Title: Re: Last Man Standing
Post by: dEaN on Dec 01, 2016, 09:47 AM
Quote from: KAKAN on Dec 01, 2016, 08:53 AMWould you even bother to say what's the error code?
Maybe you are weak in copying code...


yes really i am weak... in copy paste becuase you are pro copy paster :p
Title: Re: Last Man Standing
Post by: MatheuS on Dec 01, 2016, 11:10 AM
Quote from: dEaN on Dec 01, 2016, 09:47 AM
Quote from: KAKAN on Dec 01, 2016, 08:53 AMWould you even bother to say what's the error code?
Maybe you are weak in copying code...

yes really i am weak... in copy paste becuase you are pro copy paster :p

(https://media.giphy.com/media/6FymBmqKeBrl6/giphy.gif)
Title: Re: Last Man Standing
Post by: DizzasTeR on Dec 01, 2016, 02:54 PM
Quote from: dEaN on Dec 01, 2016, 07:09 AM_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"

-Error-

I'm pretty sure your script looks like this:
_LMS <- {
 Alive = 0,
 Players = [],
 iData = array( GetMaxPlayers() ),
 State = "OFF"

function onScriptLoad()
{
... shit here ...
}

.. other shit here ...

.. randomly pasted lms functions here

.. and so on ...

Did you notice that the _LMS is a huge table with meta-functions!

PASTE THIS WHOLE CODE SEPARATELY OUTSIDE ANY FUNCTION
_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!" );
 }
}

// Here the rest of your script, onScriptLoad etc.

And then paste the rest in the events which are mentioned in first post, if you can't do it, stop scripting.
Title: Re: Last Man Standing
Post by: Cool on Dec 01, 2016, 07:34 PM
@Doom_Kill3R   i was just trying its work or not i found a small mistake if me and you are in lms and i type /kill so its should announce Doom Won its announcing Hercules win
Title: Re: Last Man Standing
Post by: KAKAN on Dec 02, 2016, 08:39 AM
Quote from: Hercules on Dec 01, 2016, 07:34 PM@Doom_Kill3R   i was just trying its work or not i found a small mistake if me and you are in lms and i type /kill so its should announce Doom Won its announcing Hercules win
That's because your parameters name in onPlayerDeath and/or onPlayerKill function are wrong.
Title: Re: Last Man Standing
Post by: Mahmoud Tornado on Aug 25, 2017, 09:32 AM
Very Nice It Is Work :D
@Doom_Kill3R
Title: Re: Last Man Standing
Post by: umar4911 on Dec 26, 2017, 03:07 PM
bump*

If player's are on same team. Forgot to add that
Title: Re: Last Man Standing
Post by: NicusorN5 on Dec 28, 2017, 05:09 PM
Nice!
Title: Re: Last Man Standing
Post by: Retard on Jan 02, 2018, 11:21 AM
Nice @Doom_kill3r