Vote Kick System

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Vote Kick System
« on March 6th, 2015, 09:58 AM »
Vote Kick 0.4

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

Function.nut
Code: [Select]
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
Code: [Select]
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
Code: [Select]
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;
       }
}
}

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KingOfVC

  • Full Member
  • Posts: 104
[13:51] <&RastySpoon> [10] =RKr=HearTz_Hz: MOL and gre and for noobs like imkiki

Founder of Kat & King Cops and Robbers, Developer of Rob The Vehicle
Past: ViceLand Developer, EAD Scripter & Administrator

PsyChO_KiLLeR

  • Full Member
  • Learning from you All
  • Posts: 133

Thijn

  • VC:MP Beta Tester
  • Posts: 1,689
Re: Vote Kick System
« Reply #3, on March 6th, 2015, 06:35 PM »
I don't know what Dany's script looks like, so I'm just going to blame you :)

Code: [Select]
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.

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Vote Kick System
« Reply #4, on March 6th, 2015, 06:56 PM »Last edited on March 6th, 2015, 07:19 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
Quote
I 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:
Code: [Select]
function Kick(playerID) {
    local player = FindPlayer(playerID);
    if (player == null) {
        return;
    }

    EMessage();
}

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Thijn

  • VC:MP Beta Tester
  • Posts: 1,689
Re: Vote Kick System
« Reply #5, on March 7th, 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.

rObInX

  • Jr. Member
  • Posts: 67

MacTavish

  • Hero Member
  • Nicks( Kusanagi, Beztone, RATHORE )
  • Posts: 809
Re: Vote Kick System
« Reply #7, on March 7th, 2015, 01:05 PM »
Alright Thanks Thijn and rObinX. No error appeard after removing that part :)

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

Tiggyh55

  • Newbie
  • Posts: 12
Re: Vote Kick System
« Reply #8,  »
ty bro is working in my server

Hendrix

  • Newbie
  • Posts: 25