Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: MacTavish on Mar 06, 2015, 09:58 AM

Title: Vote Kick System
Post by: MacTavish on Mar 06, 2015, 09:58 AM
Vote Kick 0.4

Credits: Dany( for 0.3 votekick system ), Beztone ( for porting it to 0.4 )

Function.nut
function Check( id )
{
 local plr = FindPlayer(id);
 if ( plr )
 {
     if (( stats[ plr.ID ].VKick ) && ( stats[ plr.ID ].Count > 3 ))
   {
   if (plr == null) // i am checking there the player is still in game or not
{
        return;
    }
else
{
KickPlayer( plr);
}
}
    else
    {
      Message("[#FF0000][VK-Failed]:[#A020F0]Votekick on " + plr.Name + " failed [ " + stats[ plr.ID ].Count + "/3]." );
  stats[ plr.ID ].VKick = false;
  stats[ plr.ID ].Count = 0;
    }
 }
 VK = false;
}

function GetPlayer( text ) //Everyone is familiar with this function it is not necessary if you already have same
{
local plr = null;
if ( !IsNum( text ) ) plr = FindPlayer( text );
else plr = FindPlayer( text.tointeger() );
return plr;
}

Main.nut
class PlayerStats
{
VKick = false;
 Count = 0;
 Voted = "";
}

function onScriptLoad()
{
stats <- array( GetMaxPlayers(), null ); // Leave this line if you already have
VK <- false;
}

function onPlayerJoin( player )
{
stats[ player.ID ] = PlayerStats(); // Leave this if you already have
}

function onPlayerPart( player, reason )
{
stats[ player.ID ] = null; //put this at the end of event
}

Commands
else if( cmd == "votekick" )
{
    if( !text ) MessagePlayer("[#FF0000][Syntax]:[#ADFF2F] /votekick <Nick/ID>.", player);
else
{
local plr = GetPlayer( text );
if( !plr ) MessagePlayer("[#FF0000][Error]:[#F5F5F5]Invalid Player.", player);
else if(( plr ) && ( stats[ plr.ID ].VKick )) MessagePlayer("[#F5F5F5][Info]:[#ADFF2F]An active votekick is present on this player.", player );
  else if( !VK )
     {
        Message("[#ADFF2F][VK-Started]:[#F5F5F5]A votekick started on [#FFFF00]" + plr.Name + "[#F5F5F5] Time 15 Secs." );
        stats[ plr.ID ].VKick = true;
        NewTimer( "Check", 15000, 1, plr.ID );
VK = true;
     } else Message("[#F5F5F5][Info]:[#ADFF2F]There is already a votekick going on." )
}
}

else if( cmd == "vote" )
{
    if( !text ) MessagePlayer("[#FF0000][Syntax]:[#ADFF2F] /vote <Nick/ID>.", player );
else
{
local plr = GetPlayer( text );
if( !plr ) MessagePlayer("[#FF0000][Error]:[#F5F5F5]Invalid Player.", player );
    else if(( plr ) && ( !stats[ plr.ID ].VKick )) MessagePlayer("[#F5F5F5][Info]:[#ADFF2F]No active votekick is present on this player.", player );
    else if (( plr ) && ( stats[ player.ID ].Voted == plr.Name )) MessagePlayer("[#F5F5F5][Info]:[#ADFF2F]Already voted.", player );
    else
       {
         Message("[#ADFF2F][VoteKick]:[#FFFF00]" + player.Name + " voted against " + plr.Name + "." );
Message("[#ADFF2F][Count]:[#F5F5F5]Votekick Count on " + plr.Name + " - [ " + stats[ plr.ID ].Count + "/3]." );
         stats[ plr.ID ].Count++;
stats[ player.ID ].Voted = plr.Name;
       }
}
}
Title: Re: Vote Kick System
Post by: KingOfVC on Mar 06, 2015, 11:08 AM
Quote from: PsyChO_KiLLeR on Mar 06, 2015, 10:18 AMerror this cant create a local slot
 this line VK <- false;

any screenshot?
Title: Re: Vote Kick System
Post by: PsyChO_KiLLeR on Mar 06, 2015, 03:34 PM
nyc work bro
Title: Re: Vote Kick System
Post by: Thijn on Mar 06, 2015, 06:35 PM
I don't know what Dany's script looks like, so I'm just going to blame you :)

if ( plr )
{
    if (( stats[ plr.ID ].VKick ) && ( stats[ plr.ID ].Count > 3 ))
    {
        if (plr == null) // i am checking there the player is still in game or not
        {
            return;
        }
    }
}
That little check you do will never work, and if it did it will still cause a crash.
First you're checking if plr exists, this is all that should be needed to prevent a crash.
Then you call plr.ID inside the array, that will crash if the plr didn't exists. And then you add your so called plr check.
That "I am checking there the player is still in game" is unneeded, and can be removed.
Title: Re: Vote Kick System
Post by: MacTavish on Mar 06, 2015, 06:56 PM
But Thijn i've fully tested it before post console shows no error

Else tell me a better way to check

And that wasnt in dany script i've included that because if the target player leaves before check then server returns an error

EDIT: once again tested no error no crash and i've done just like as Stormeus said
QuoteI just want to point out that this would crash your server anyway if the player left in the five seconds it takes to kick them.

You can check if a player is still online by using a timer with player.ID instead of player, then using this in your Kick function:
function Kick(playerID) {
    local player = FindPlayer(playerID);
    if (player == null) {
        return;
    }

    EMessage();
}
Title: Re: Vote Kick System
Post by: Thijn on Mar 07, 2015, 11:25 AM
I didnt say it will crash or create errors. I said the code you added makes no sense because there's already a check if plr exists above it.
Title: Re: Vote Kick System
Post by: rObInX on Mar 07, 2015, 12:26 PM
I've already ported it.
http://forum.vc-mp.org/?topic=332.0
Just view the functions in the topic.

As Thijn said, you dont need that part.
Title: Re: Vote Kick System
Post by: MacTavish on Mar 07, 2015, 01:05 PM
Alright Thanks Thijn and rObinX. No error appeard after removing that part :)
Title: Re: Vote Kick System
Post by: Tiggyh55 on Aug 14, 2018, 05:33 AM
ty bro is working in my server
Title: Re: Vote Kick System
Post by: Hendrix on Nov 28, 2018, 11:23 PM
jjjj debo probar eso